Exemplo n.º 1
0
        public void AddProductToOrderList(AddProductToOrderServiceModel model)
        {
            var order = this.data.Orders.Where(o => o.Id == model.OrderId).FirstOrDefault();

            if (order == null)
            {
                throw new ArgumentException("There is no order whith given id.");
            }

            var product = this.data.Products.Where(p => p.Id == model.ProductId).FirstOrDefault();

            if (product == null)
            {
                throw new ArgumentException("There is no product with given id.");
            }

            var productQuantity = new ProductQuantity
            {
                ProductId = model.ProductId,
                Product   = product,
                Quantity  = model.Quantity,
            };

            order.ProductsQuantities.Add(productQuantity);
            this.data.SaveChanges();
        }
Exemplo n.º 2
0
        public IActionResult AddingProduct(AddProductToOrderInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var addProductToOrderServiceModel = new AddProductToOrderServiceModel
            {
                OrderId     = model.OrderId,
                ProductName = model.ProductName,
                ProductId   = model.ProductId,
                Quantity    = model.Quantity
            };

            this.orders.AddProductToOrderList(addProductToOrderServiceModel);
            return(this.RedirectToAction("Details", "Orders", new { id = model.OrderId }));
        }