Example #1
0
        public async Task <IActionResult> Edit(OrderProductAdminEditViewModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            await this.productsService.EditOrderProductAsync(inputModel);

            return(this.RedirectToAction("All", "Products", new { id = inputModel.OrderId }));
        }
        public async Task EditOrderProductAsync(OrderProductAdminEditViewModel inputModel)
        {
            var orderProduct = await this.dbContext.OrderProducts
                               .Where(c => c.ProductId == inputModel.ProductId)
                               .FirstOrDefaultAsync();

            if (orderProduct == null)
            {
                throw new ArgumentNullException(string.Format(ServicesConstants.InvalidOrderProductId, inputModel.ProductId));
            }

            orderProduct.OrderId = inputModel.OrderId;

            orderProduct.ProductId = inputModel.ProductId;

            orderProduct.Price = inputModel.Price;

            orderProduct.Quantity = inputModel.Quantity;

            this.dbContext.Update(orderProduct);

            await this.dbContext.SaveChangesAsync();
        }