public Product Edit(EasyHardwareEntities context, int productId, Product product) { // get the attached product Product dbProduct = context.Product.Single(x => x.Id == productId); // edit values dbProduct.Price = product.Price; dbProduct.Description = product.Description; dbProduct.Name = product.Name; dbProduct.PartNumber = product.PartNumber; ICollection <Category> categories = new List <Category>(); // get new categories ids List <int> newCategories = product.Categories.Select(x => x.Id).ToList(); // get attached categories categories = context.Category.Where(x => newCategories.Any(c => c == x.Id)).ToList(); // clear already product categories dbProduct.Categories.Clear(); // assign the new categories dbProduct.Categories = categories; // save changes after edit context.SaveChanges(); // return edited product return(product); }
/// <summary> /// Generate a purchase /// </summary> /// <param name="context"></param> /// <param name="purchase"></param> /// <returns></returns> public Purchase Add(EasyHardwareEntities context, Purchase purchase) { // add purchase to context context.Purchase.Add(purchase); // save changes context.SaveChanges(); return(purchase); }
public Store Add(EasyHardwareEntities context, Store store) { // add store to context context.Store.Add(store); // save changes context.SaveChanges(); return(store); }
public Store Delete(EasyHardwareEntities context, int storeId) { // get the attached store Store store = context.Store.Single(x => x.Id == storeId); // soft delete store.Active = false; // save changes after soft delete context.SaveChanges(); // returns deleted store return(store); }
public Product Delete(EasyHardwareEntities context, int productId) { // get the attached product Product product = context.Product.Single(x => x.Id == productId); // soft delete product.Active = false; // save changes after soft delete context.SaveChanges(); // returns deleted product return(product); }
public Category Delete(EasyHardwareEntities context, int categoryId) { // get the attached category Category category = context.Category.Single(x => x.Id == categoryId); // soft delete category.Active = false; // save changes after soft delete context.SaveChanges(); // returns deleted category return(category); }
public Stock Edit(EasyHardwareEntities context, int stockId, Stock stock) { // get the attached stock Stock dbStock = context.Stock.Single(x => x.Id == stockId); // edit values dbStock.Quantity = stock.Quantity; // save changes after edit context.SaveChanges(); // return edited stock return(stock); }
public User SignIn(EasyHardwareEntities context, string username, string password) { // get an user by username and password and returns the user without sending the password var user = context.User.FirstOrDefault(x => x.UserName.Equals(username, StringComparison.InvariantCultureIgnoreCase) && x.Password.Equals(password, StringComparison.InvariantCultureIgnoreCase)); if (user != null) { user.Password = null; } return(user); }
public Category Add(EasyHardwareEntities context, Category category) { // relating to the assigned parent category if (category.ParentCategoryId > 0) { category.ParentCategory = context.Category.Single(x => x.Id == category.ParentCategoryId); } // add category to context context.Category.Add(category); // save changes context.SaveChanges(); return(category); }
public Store Edit(EasyHardwareEntities context, int storeId, Store store) { // get the attached store Store dbStore = context.Store.Single(x => x.Id == storeId); // edit values dbStore.Active = store.Active; dbStore.Description = store.Description; dbStore.Name = store.Name; dbStore.Location = store.Location; // save changes after edit context.SaveChanges(); // return edited store return(store); }
public IList <Stock> Get(EasyHardwareEntities context, List <int> storeIds, string productName) { var stocks = context.Stock.AsQueryable(); if (storeIds != null && storeIds.Any()) { stocks = stocks.Where(x => storeIds.Any(y => y == x.StoreId)); } if (!string.IsNullOrWhiteSpace(productName)) { stocks = stocks.Where(x => x.Product.Name.Contains(productName)); } return(stocks.ToList()); }
public Category Edit(EasyHardwareEntities context, int categoryId, Category category) { // get the attached category Category dbCategory = context.Category.Single(x => x.Id == categoryId); // edit values dbCategory.Active = category.Active; dbCategory.Description = category.Description; dbCategory.Name = category.Name; dbCategory.Order = category.Order; dbCategory.ParentCategoryId = category.ParentCategoryId; // save changes after edit context.SaveChanges(); // return edited category return(category); }
public void GenerateStock(EasyHardwareEntities context, Product product) { // get all stores to generate stock for this product List <Store> stores = context.Store.ToList(); if (stores != null && stores.Any()) { foreach (Store store in stores) { context.Stock.Add(new Stock() { ProductId = product.Id, StoreId = store.Id, Quantity = 0 }); } context.SaveChanges(); } }
public Product Add(EasyHardwareEntities context, Domain.Product product) { ICollection <Category> categories = new List <Category>(); if (product.Categories.Any()) { foreach (Category category in product.Categories) { categories.Add(context.Category.Single(x => x.Id == category.Id)); } product.Categories = categories; } // add product to context context.Product.Add(product); // save changes context.SaveChanges(); return(product); }
public void GenerateStock(EasyHardwareEntities context, Store store) { // get all products to generate stock all products List <Product> products = context.Product.ToList(); if (products != null && products.Any()) { foreach (Product product in products) { context.Stock.Add(new Stock() { ProductId = product.Id, StoreId = store.Id, Quantity = 0 }); } context.SaveChanges(); } }
public Store Get(EasyHardwareEntities context, string storeCode) { // get the attached store return(context.Store.SingleOrDefault(x => x.Code == storeCode)); }
public Product Get(EasyHardwareEntities context, string productPartNumber) { // get the attached store return(context.Product.SingleOrDefault(x => x.PartNumber == productPartNumber)); }
public Product Get(EasyHardwareEntities context, int productId) { // get the attached product return(context.Product.SingleOrDefault(x => x.Id == productId)); }
/// <summary> /// Get active categories with respective subcategories /// </summary> /// <param name="context"></param> /// <returns>List of categories</returns> public IList <Category> Get(EasyHardwareEntities context, bool onlyUnparent) { return(context.Category.Where(x => x.Active && (!onlyUnparent || (onlyUnparent && x.ParentCategoryId == null))) .OrderBy(x => x.Order) .ToList()); }
/// <summary> /// Gets a purchase by Code /// </summary> /// <param name="context"></param> /// <param name="purchaseCode"></param> /// <returns></returns> public Purchase Get(EasyHardwareEntities context, Guid purchaseCode) { // get the attached purchase return(context.Purchase.SingleOrDefault(x => x.Code == purchaseCode)); }
public Store Get(EasyHardwareEntities context, int storeId) { // get the attached store return(context.Store.SingleOrDefault(x => x.Id == storeId)); }
public Category Get(EasyHardwareEntities context, int categoryId) { // get the attached category return(context.Category.SingleOrDefault(x => x.Id == categoryId)); }
public IList <Product> Get(EasyHardwareEntities context) { return(context.Product.Where(x => x.Active).ToList()); }
/// <summary> /// Returns all purchases from an user /// </summary> /// <param name="context"></param> /// <param name="userId"></param> /// <returns></returns> public IList <Purchase> GetAll(EasyHardwareEntities context, int userId) { return(context.Purchase.Where(x => x.Client == userId).ToList()); }
public Category Get(EasyHardwareEntities context, string categoryCode) { // get the attached category return(context.Category.SingleOrDefault(x => x.Code == categoryCode)); }
/// <summary> /// Gets a purchase by Id /// </summary> /// <param name="context"></param> /// <param name="purchaseId"></param> /// <returns></returns> public Purchase Get(EasyHardwareEntities context, int purchaseId) { // get the attached purchase return(context.Purchase.SingleOrDefault(x => x.Id == purchaseId)); }
public IList <Store> Get(EasyHardwareEntities context) { return(context.Store.Where(x => x.Active) .ToList()); }