C'est encore moi... j'ai du code comme ceci..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcGridSample.Models
{
public class CustomerService
{
private List Customers
{
get
{
List customers;
if (HttpContext.Current.Session["Customers"] != null)
{
customers = (List) HttpContext.Current.Session["Customers"];
}
else
{
//Créer un magasin de données client et enregistrer en session
customers = new List();
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 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 customers)
{
customers.Add(new SVC
{
ID = 1,
FirstName = "John",
LastName = "Doe",
Phone = "1111111111",
Email = "johndoe@gmail.com",
OrdersPlaced = 5,
DateOfLastOrder = DateTime.Parse("5/3/2007")
});
customers.Add(new SVC
{
ID = 2,
FirstName = "Jane",
LastName = "Doe",
Phone = "2222222222",
Email = "janedoe@gmail.com",
OrdersPlaced = 3,
DateOfLastOrder = DateTime.Parse("4/5/2008")
});
customers.Add(new SVC
{
ID = 3,
FirstName = "John",
LastName = "Smith",
Phone = "3333333333",
Email = "johnsmith@yahoo.com",
OrdersPlaced = 25,
DateOfLastOrder = DateTime.Parse("4/5/2000")
});
customers.Add(new SVC
{
ID = 4,
FirstName = "Eddie",
LastName = "Murphy",
Phone = "4444444444",
Email = "eddiem@yahoo.com",
OrdersPlaced = 1,
DateOfLastOrder = DateTime.Parse("4/5/2003")
});
customers.Add(new SVC
{
ID = 5,
FirstName = "Ziggie",
LastName = "Ziggler",
Phone = null,
Email = "ziggie@hotmail.com",
OrdersPlaced = 0,
DateOfLastOrder = null
});
customers.Add(new SVC
{
ID = 6,
FirstName = "Michael",
LastName = "J",
Phone = "666666666",
Email = "ziggie@hotmail.com",
OrdersPlaced = 5,
DateOfLastOrder = DateTime.Parse("12/3/2007")
});
}
}
}
ces codes sont un exemple que j'ai trouvé sur internet..
dans ce cas, les données sont créées et enregistrées en session avant d'être affichées..
ce que je veux demander c'est comment charger les données depuis une table?
je suis nouveau ici.. s'il vous plaît aidez :)
merci d'avance..