public List <Product> GetProductsCheaperThan(float price) { using (var db = new ShopDataContext()) { return(db.Products.Where(product => product.Price < price).ToList()); } }
public int GetNumberOfClients() { using (var db = new ShopDataContext()) { return(db.Clients.Select(client => client).ToList().Count); } }
public List <Product> GetProductsMoreExpensiveThan(float price) { using (var db = new ShopDataContext()) { return(db.Products.Where(product => product.Price > price).ToList()); } }
public List <Product> GetProductsByPrice(float price) { using (var db = new ShopDataContext()) { return(db.Products.Where(product => product.Price.Equals(price)).ToList()); } }
public Product GetLastProduct() { using (var db = new ShopDataContext()) { return(db.Products.Select(product => product).ToList().LastOrDefault()); } }
public Product GetProductById(int id) { using (var db = new ShopDataContext()) { return(db.Products.FirstOrDefault(product => product.Id.Equals(id))); } }
public List <Product> GetProductsByCategory(ProductCategory category) { using (var db = new ShopDataContext()) { return(db.Products.Where(product => product.Category.Equals(category)).ToList()); } }
public List <ProductCategory> GetAllCategories() { using (var db = new ShopDataContext()) { return(db.ProductCategories.Select(category => category).ToList()); } }
public ProductCategory GetCategoryByName(string category) { using (var db = new ShopDataContext()) { return(db.ProductCategories.FirstOrDefault(c => c.Category.Equals(category))); } }
public PurchaseEvent GetMostRecentPurchase() { using (var db = new ShopDataContext()) { return(db.PurchaseEvents.Select(p => p).ToList().LastOrDefault()); } }
public Client GetClientById(int id) { using (var db = new ShopDataContext()) { return(db.Clients.FirstOrDefault(client => client.Id.Equals(id))); } }
public Product GetProductByName(string name) { using (var db = new ShopDataContext()) { return(db.Products.FirstOrDefault(product => product.ProductName.Equals(name))); } }
public Client GetLastClient() { using (var db = new ShopDataContext()) { return(db.Clients.Select(client => client).ToList().LastOrDefault()); } }
public PurchaseEvent GetPurchaseEventById(int id) { using (var db = new ShopDataContext()) { return(db.PurchaseEvents.FirstOrDefault(ev => ev.Id.Equals(id))); } }
public List <PurchaseEvent> GetPurchaseEventsByProductId(int id) { using (var db = new ShopDataContext()) { return(db.PurchaseEvents.Where(ev => ev.ProductId.Equals(id)).ToList()); } }
public List <PurchaseEvent> GetAllPurchaseEvents() { using (var db = new ShopDataContext()) { return(db.PurchaseEvents.Select(ev => ev).ToList()); } }
public List <Client> GetAllClients() { using (var db = new ShopDataContext()) { return(db.Clients.Select(client => client).ToList()); } }
public List <Product> GetAllProducts() { using (var db = new ShopDataContext()) { return(db.Products.Select(product => product).ToList()); } }
public void AddProduct(Product product) { using (var db = new ShopDataContext()) { db.Products.InsertOnSubmit(product); db.SubmitChanges(); } }
public void AddClient(Client client) { using (var db = new ShopDataContext()) { db.Clients.InsertOnSubmit(client); db.SubmitChanges(); } }
public void AddPurchaseEvent(PurchaseEvent e) { using (var db = new ShopDataContext()) { db.PurchaseEvents.InsertOnSubmit(e); db.SubmitChanges(); } }
public Client GetClientByCredentials(string firstName, string lastName) { using (var db = new ShopDataContext()) { return(db.Clients .FirstOrDefault(client => (client.FirstName.Equals(firstName) && (client.LastName.Equals(lastName))))); } }
public PurchaseEvent GetMostRecentByClientIdAndProductId(int clientId, int productId) { using (var db = new ShopDataContext()) { return(db.PurchaseEvents.Where(p => (p.ClientId.Equals(clientId) && (p.ProductId.Equals(productId)))) .ToList().LastOrDefault()); } }
public void DeleteProduct(int id) { using (var db = new ShopDataContext()) { Product productToDelete = db.Products.FirstOrDefault(product => product.Id.Equals(id)); if (productToDelete != null) { db.Products.DeleteOnSubmit(productToDelete); db.SubmitChanges(); } } }
public void DeleteClient(int id) { using (var db = new ShopDataContext()) { Client clientToDelete = db.Clients.FirstOrDefault(client => client.Id.Equals(id)); if (clientToDelete != null) { db.Clients.DeleteOnSubmit(clientToDelete); db.SubmitChanges(); } } }
public void DeletePurchaseEvent(int id) { using (var db = new ShopDataContext()) { PurchaseEvent eventToDelete = db.PurchaseEvents.FirstOrDefault(e => e.Id.Equals(id)); if (eventToDelete != null) { db.PurchaseEvents.DeleteOnSubmit(eventToDelete); db.SubmitChanges(); } } }
public void UpdateClient(Client client) { using (var db = new ShopDataContext()) { Client clientToUpdate = db.Clients.FirstOrDefault(c => c.Id.Equals(client.Id)); if (clientToUpdate != null) { clientToUpdate.FirstName = client.FirstName; clientToUpdate.LastName = client.LastName; db.SubmitChanges(); } } }
public void UpdateProduct(Product p) { using (var db = new ShopDataContext()) { Product productToUpdate = db.Products.FirstOrDefault(product => product.Id.Equals(p.Id)); if (productToUpdate != null) { productToUpdate.ProductName = p.ProductName; productToUpdate.Category = p.Category; productToUpdate.Price = p.Price; db.SubmitChanges(); } } }