Example #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);
        }
Example #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);
 }
Example #3
0
 public Store Add(EasyHardwareEntities context, Store store)
 {
     // add store to context
     context.Store.Add(store);
     // save changes
     context.SaveChanges();
     return(store);
 }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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);
 }
Example #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);
        }
Example #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());
        }
Example #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);
        }
Example #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();
            }
        }
Example #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);
        }
Example #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();
            }
        }
Example #16
0
 public Store Get(EasyHardwareEntities context, string storeCode)
 {
     // get the attached store
     return(context.Store.SingleOrDefault(x => x.Code == storeCode));
 }
Example #17
0
 public Product Get(EasyHardwareEntities context, string productPartNumber)
 {
     // get the attached store
     return(context.Product.SingleOrDefault(x => x.PartNumber == productPartNumber));
 }
Example #18
0
 public Product Get(EasyHardwareEntities context, int productId)
 {
     // get the attached product
     return(context.Product.SingleOrDefault(x => x.Id == productId));
 }
Example #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());
 }
Example #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));
 }
Example #21
0
 public Store Get(EasyHardwareEntities context, int storeId)
 {
     // get the attached store
     return(context.Store.SingleOrDefault(x => x.Id == storeId));
 }
Example #22
0
 public Category Get(EasyHardwareEntities context, int categoryId)
 {
     // get the attached category
     return(context.Category.SingleOrDefault(x => x.Id == categoryId));
 }
Example #23
0
 public IList <Product> Get(EasyHardwareEntities context)
 {
     return(context.Product.Where(x => x.Active).ToList());
 }
Example #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());
 }
Example #25
0
 public Category Get(EasyHardwareEntities context, string categoryCode)
 {
     // get the attached category
     return(context.Category.SingleOrDefault(x => x.Code == categoryCode));
 }
Example #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));
 }
Example #27
0
 public IList <Store> Get(EasyHardwareEntities context)
 {
     return(context.Store.Where(x => x.Active)
            .ToList());
 }