Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
 public Store Add(EasyHardwareEntities context, Store store)
 {
     // add store to context
     context.Store.Add(store);
     // save changes
     context.SaveChanges();
     return(store);
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 8
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);
 }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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();
            }
        }
Ejemplo n.º 12
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();
            }
        }
Ejemplo n.º 13
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);
        }