コード例 #1
0
        public void Edit(CategoryToEditViewModel categoryToEdit)
        {
            Category category = _dbContext.Categories.FirstOrDefault(c => c.CategoryId == categoryToEdit.CategoryId);

            category.Name = categoryToEdit.Name;
            _dbContext.Entry(category).State = EntityState.Modified;
            _dbContext.SaveChanges();
        }
コード例 #2
0
        public Guid Create(Guid deliveryAddressId, ApplicationUser user)
        {
            List <Product> products = new List <Product>();

            foreach (ItemInCartViewModel item in GetCart())
            {
                if (item.Quantity <= item.Product.ItemsAvailable)
                {
                    for (int i = 0; i < item.Quantity; i++)
                    {
                        products.Add(item.Product);
                    }
                }
                else
                {
                    throw new Exception("Not enough products in stock");
                }
            }
            Order newOrder = new Order();

            newOrder.OrderId           = Guid.NewGuid();
            newOrder.DateOfPurchase    = DateTime.Now;
            newOrder.OrderState        = OrderState.New;
            newOrder.DeliveryAddressId = deliveryAddressId;
            newOrder.UserId            = user.Id;
            _dbContext.Orders.Add(newOrder);
            foreach (Product product in products)
            {
                Product tempProd = _dbContext.Products.FirstOrDefault(p => p.ProductId == product.ProductId);
                if (tempProd.ItemsAvailable > 0)
                {
                    ProductCopy newCopy = new ProductCopy();
                    newCopy.ProductCopyId = Guid.NewGuid();
                    newCopy.ProductId     = product.ProductId;
                    newCopy.Price         = product.Price;
                    newCopy.OrderId       = newOrder.OrderId;
                    _dbContext.ProductsCopies.Add(newCopy);
                    tempProd.ItemsAvailable--;
                    _dbContext.Entry(tempProd).Property(p => p.ItemsAvailable).IsModified = true;
                    _dbContext.SaveChanges();
                }
            }
            _dbContext.SaveChanges();
            EmptyCart();
            return(newOrder.OrderId);
        }
コード例 #3
0
        public void Edit(SubcategoryToEditViewModel subcategoryToEdit)
        {
            Subcategory subcategory =
                _dbContext.Subcategories.FirstOrDefault(s => s.SubcategoryId == subcategoryToEdit.SubcategoryId);

            subcategory.Name = subcategoryToEdit.Name;
            _dbContext.Entry(subcategory).State = EntityState.Modified;
            _dbContext.SaveChanges();
        }
コード例 #4
0
        public void Edit(ProductToEditViewModel productToEdit)
        {
            Product product = _dbContext.Products.FirstOrDefault(c => c.ProductId == productToEdit.ProductId);

            product.Name                    = productToEdit.Name;
            product.Price                   = productToEdit.Price;
            product.ItemsAvailable          = productToEdit.ItemsAvailable;
            _dbContext.Entry(product).State = EntityState.Modified;
            _dbContext.SaveChanges();
        }