Ejemplo n.º 1
0
        public ActionResult Create(SaleOrder order)
        {
            if (ModelState.IsValid)
            {
                foreach (var item in order.Items)
                {
                    item.Product.Stocks = _context.Stocks.Where(s => s.ProductId == item.ProductId).ToList();
                }

                order.FinalizeOrder();

                _context.SaleOrders.Add(order);

                foreach (var item in order.Items)
                {
                    _context.Entry(item.Product).State = EntityState.Modified;
                }

                _context.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.CityId = new SelectList(_context.Cities.Where(c => c.IsActive).OrderBy(c => c.Name), "Id", "Name", order.Freight.CityId);

            return(View(order));
        }