Пример #1
0
        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);
        }
Пример #2
0
 /// <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);
 }
Пример #3
0
 public Store Add(EasyHardwareEntities context, Store store)
 {
     // add store to context
     context.Store.Add(store);
     // save changes
     context.SaveChanges();
     return(store);
 }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        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);
        }
Пример #9
0
 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);
 }
Пример #10
0
        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);
        }
Пример #11
0
        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());
        }
Пример #12
0
        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);
        }
Пример #13
0
        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();
            }
        }
Пример #14
0
        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);
        }
Пример #15
0
        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();
            }
        }
Пример #16
0
 public Store Get(EasyHardwareEntities context, string storeCode)
 {
     // get the attached store
     return(context.Store.SingleOrDefault(x => x.Code == storeCode));
 }
Пример #17
0
 public Product Get(EasyHardwareEntities context, string productPartNumber)
 {
     // get the attached store
     return(context.Product.SingleOrDefault(x => x.PartNumber == productPartNumber));
 }
Пример #18
0
 public Product Get(EasyHardwareEntities context, int productId)
 {
     // get the attached product
     return(context.Product.SingleOrDefault(x => x.Id == productId));
 }
Пример #19
0
 /// <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());
 }
Пример #20
0
 /// <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));
 }
Пример #21
0
 public Store Get(EasyHardwareEntities context, int storeId)
 {
     // get the attached store
     return(context.Store.SingleOrDefault(x => x.Id == storeId));
 }
Пример #22
0
 public Category Get(EasyHardwareEntities context, int categoryId)
 {
     // get the attached category
     return(context.Category.SingleOrDefault(x => x.Id == categoryId));
 }
Пример #23
0
 public IList <Product> Get(EasyHardwareEntities context)
 {
     return(context.Product.Where(x => x.Active).ToList());
 }
Пример #24
0
 /// <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());
 }
Пример #25
0
 public Category Get(EasyHardwareEntities context, string categoryCode)
 {
     // get the attached category
     return(context.Category.SingleOrDefault(x => x.Code == categoryCode));
 }
Пример #26
0
 /// <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));
 }
Пример #27
0
 public IList <Store> Get(EasyHardwareEntities context)
 {
     return(context.Store.Where(x => x.Active)
            .ToList());
 }