public IActionResult CreateFromOrder(int?id)
        {
            var order = _dataContext.Orders
                        .Include(o => o.House)
                        .Include(o => o.Warehouse)
                        .Include(o => o.Collector)
                        .ThenInclude(c => c.User)
                        .Include(o => o.TypePayment)
                        .Include(o => o.DayPayment)
                        .Include(o => o.Seller)
                        .ThenInclude(s => s.User)
                        .Include(s => s.Helper)
                        .Include(o => o.Customer)
                        .Include(o => o.State)
                        .Include(o => o.OrderDetails)
                        .ThenInclude(od => od.Product)
                        .FirstOrDefault(o => o.Id == id);

            var model = new SaleFromOrderViewModel
            {
                Houses        = _combosHelper.GetComboHouses(),
                HouseId       = order.House.Id,
                TypePayments  = _combosHelper.GetComboTypePayments(),
                TypePaymentId = order.TypePayment.Id,
                DayPayments   = _combosHelper.GetComboDayPayments(),
                DayPaymentId  = order.DayPayment.Id,
                Sellers       = _combosHelper.GetComboSellers(),
                SellerId      = order.Seller.Id,
                Helpers       = _combosHelper.GetComboHelpers(),
                HelperId      = order.Helper.Id,
                Warehouses    = _combosHelper.GetComboWarehouses(),
                WarehouseId   = order.Warehouse.Id,
                CustomerId    = order.Customer.Id,
                CollectorId   = order.Collector.Id,
                StateId       = 1,
                StartDate     = order.StartDate.Date,
                EndDate       = order.EndDate.Date,
                Deposit       = order.Deposit,
                Payment       = order.Payment,
                Remarks       = order.Remarks,
                Pending       = order.Pending,
                Details2      = _dataContext.Orders.Include(o => o.Customer).Where(o => o.Id == id).ToList(),
                Details       = _dataContext.OrderDetails.Include(od => od.Product).Where(sd => sd.Order.Id == id).ToList(),
            };

            return(View(model));
        }
示例#2
0
        public IActionResult Create()
        {
            var orderTmp       = _dataContext.OrderTmps.Include(ot => ot.Customer).ThenInclude(c => c.Collector).Where(ot => ot.Username == User.Identity.Name).FirstOrDefault();
            var orderDetailTmp = _dataContext.OrderDetailTmps.Include(odt => odt.Product).ThenInclude(p => p.ProductImages).FirstOrDefault();

            var model = new OrderViewModel
            {
                Houses       = _combosHelper.GetComboHouses(),
                TypePayments = _combosHelper.GetComboTypePayments(),
                DayPayments  = _combosHelper.GetComboDayPayments(),
                Sellers      = _combosHelper.GetComboSellers(),
                Helpers      = _combosHelper.GetComboHelpers(),
                Warehouses   = _combosHelper.GetComboWarehouses(),
                CustomerId   = orderTmp.Customer.Id,
                CollectorId  = orderTmp.Customer.Collector.Id,
                StateId      = 2,
                StartDate    = DateTime.Today,
                EndDate      = DateTime.Today.AddYears(1),
                Details      = _dataContext.OrderDetailTmps.Where(odt => odt.Username == User.Identity.Name).ToList(),
                Details2     = _dataContext.OrderTmps.Include(ot => ot.Customer).Where(ot => ot.Username == User.Identity.Name).ToList(),
            };

            return(View(model));
        }