ASP NET MVC (loading data from database)

Posted by rah.deex on Stack Overflow See other posts from Stack Overflow or by rah.deex
Published on 2010-04-23T06:29:36Z Indexed on 2010/04/23 6:33 UTC
Read the original article Hit count: 348

Filed under:

hi experts, its me again... i have some code like this..

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MvcGridSample.Models
{
 public class CustomerService
 {
  private List<SVC> Customers
  {
   get
   {
    List<SVC> customers;
    if (HttpContext.Current.Session["Customers"] != null)
    {
     customers = (List<SVC>) HttpContext.Current.Session["Customers"];
    }
    else
    {
     //Create customer data store and save in session
     customers = new List<SVC>();

     InitCustomerData(customers);

     HttpContext.Current.Session["Customers"] = customers;
    }

    return customers;
   }
  }




  public SVC GetByID(int customerID)
  {
   return this.Customers.AsQueryable().First(customer => customer.seq_ == customerID);
  }


  public IQueryable<SVC> GetQueryable()
  {
   return this.Customers.AsQueryable();
  }


  public void Add(SVC customer)
 {
   this.Customers.Add(customer);
  }


  public void Update(SVC customer)
  {

  }


  public void Delete(int customerID)
  {
   this.Customers.RemoveAll(customer => customer.seq_ == customerID);
  }


    private void InitCustomerData(List<SVC> customers)
    {
        customers.Add(new SVC
        {
            ID = 1,
            FirstName = "John",
            LastName = "Doe",
            Phone = "1111111111",
            Email = "[email protected]",
            OrdersPlaced = 5,
            DateOfLastOrder = DateTime.Parse("5/3/2007")
        });

        customers.Add(new SVC
        {
            ID = 2,
            FirstName = "Jane",
            LastName = "Doe",
            Phone = "2222222222",
            Email = "[email protected]",
            OrdersPlaced = 3,
            DateOfLastOrder = DateTime.Parse("4/5/2008")
        });


        customers.Add(new SVC
        {
            ID = 3,
            FirstName = "John",
            LastName = "Smith",
            Phone = "3333333333",
            Email = "[email protected]",
            OrdersPlaced = 25,
            DateOfLastOrder = DateTime.Parse("4/5/2000")
        });


        customers.Add(new SVC
        {
            ID = 4,
            FirstName = "Eddie",
            LastName = "Murphy",
            Phone = "4444444444",
            Email = "[email protected]",
            OrdersPlaced = 1,
            DateOfLastOrder = DateTime.Parse("4/5/2003")
        });


        customers.Add(new SVC
        {
            ID = 5,
            FirstName = "Ziggie",
            LastName = "Ziggler",
            Phone = null,
            Email = "[email protected]",
            OrdersPlaced = 0,
            DateOfLastOrder = null
        });


        customers.Add(new SVC
        {
            ID = 6,
            FirstName = "Michael",
            LastName = "J",
            Phone = "666666666",
            Email = "[email protected]",
            OrdersPlaced = 5,
            DateOfLastOrder = DateTime.Parse("12/3/2007")
        });

    }

 }
}

those codes is an example that i've got from the internet..
in that case, the data is created and saved in session before its shown..
the things that i want to ask is how if i want to load the data from table?
i'am a newbie here.. please help :)

thank b4 for advance..

© Stack Overflow or respective owner

Related posts about ASP.NET