public List <Product> GetProductsCheaperThan(float price)
 {
     using (var db = new ShopDataContext())
     {
         return(db.Products.Where(product => product.Price < price).ToList());
     }
 }
Пример #2
0
 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)));
     }
 }
Пример #10
0
 public PurchaseEvent GetMostRecentPurchase()
 {
     using (var db = new ShopDataContext())
     {
         return(db.PurchaseEvents.Select(p => p).ToList().LastOrDefault());
     }
 }
Пример #11
0
 public Client GetClientById(int id)
 {
     using (var db = new ShopDataContext())
     {
         return(db.Clients.FirstOrDefault(client => client.Id.Equals(id)));
     }
 }
Пример #12
0
 public Product GetProductByName(string name)
 {
     using (var db = new ShopDataContext())
     {
         return(db.Products.FirstOrDefault(product => product.ProductName.Equals(name)));
     }
 }
Пример #13
0
 public Client GetLastClient()
 {
     using (var db = new ShopDataContext())
     {
         return(db.Clients.Select(client => client).ToList().LastOrDefault());
     }
 }
Пример #14
0
 public PurchaseEvent GetPurchaseEventById(int id)
 {
     using (var db = new ShopDataContext())
     {
         return(db.PurchaseEvents.FirstOrDefault(ev => ev.Id.Equals(id)));
     }
 }
Пример #15
0
 public List <PurchaseEvent> GetPurchaseEventsByProductId(int id)
 {
     using (var db = new ShopDataContext())
     {
         return(db.PurchaseEvents.Where(ev => ev.ProductId.Equals(id)).ToList());
     }
 }
Пример #16
0
 public List <PurchaseEvent> GetAllPurchaseEvents()
 {
     using (var db = new ShopDataContext())
     {
         return(db.PurchaseEvents.Select(ev => ev).ToList());
     }
 }
Пример #17
0
 public List <Client> GetAllClients()
 {
     using (var db = new ShopDataContext())
     {
         return(db.Clients.Select(client => client).ToList());
     }
 }
Пример #18
0
 public List <Product> GetAllProducts()
 {
     using (var db = new ShopDataContext())
     {
         return(db.Products.Select(product => product).ToList());
     }
 }
Пример #19
0
 public void AddProduct(Product product)
 {
     using (var db = new ShopDataContext())
     {
         db.Products.InsertOnSubmit(product);
         db.SubmitChanges();
     }
 }
Пример #20
0
 public void AddClient(Client client)
 {
     using (var db = new ShopDataContext())
     {
         db.Clients.InsertOnSubmit(client);
         db.SubmitChanges();
     }
 }
Пример #21
0
 public void AddPurchaseEvent(PurchaseEvent e)
 {
     using (var db = new ShopDataContext())
     {
         db.PurchaseEvents.InsertOnSubmit(e);
         db.SubmitChanges();
     }
 }
Пример #22
0
 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)))));
     }
 }
Пример #23
0
 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());
     }
 }
Пример #24
0
        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();
                }
            }
        }
Пример #25
0
        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();
                }
            }
        }
Пример #26
0
        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();
                }
            }
        }
Пример #27
0
        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();
                }
            }
        }
Пример #28
0
        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();
                }
            }
        }