Ejemplo n.º 1
0
        //Get Edit
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var booklist = (IEnumerable <Books>)(from b in _db.Books
                                                 join s in _db.BooksSelectedForShipment
                                                 on b.ID equals s.BookID
                                                 where s.ShipmentID == id
                                                 select b).Include("BookTypes").Include("Publishers").Include("Authors");

            ShipmentDetailsViewModel objShipmentVM = new ShipmentDetailsViewModel()
            {
                Shipment    = _db.Shipments.Include(s => s.SalesPerson).Where(s => s.ID == id).FirstOrDefault(),
                SalesPerson = _db.ApplicationUsers.ToList(),
                Books       = booklist.ToList()
            };

            return(View(objShipmentVM));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, ShipmentDetailsViewModel objShipmentVM)
        {
            if (ModelState.IsValid)
            {
                objShipmentVM.Shipment.ShipmentDate = objShipmentVM.Shipment.ShipmentDate.AddHours(objShipmentVM.Shipment.ShipmentTime.Hour).AddMinutes(objShipmentVM.Shipment.ShipmentTime.Minute);
                var shipmentFromDb = _db.Shipments.Where(s => s.ID == objShipmentVM.Shipment.ID).FirstOrDefault();

                shipmentFromDb.CustomerName  = objShipmentVM.Shipment.CustomerName;
                shipmentFromDb.CustomerEmail = objShipmentVM.Shipment.CustomerEmail;
                shipmentFromDb.CustomerPhone = objShipmentVM.Shipment.CustomerPhone;
                shipmentFromDb.ShipmentDate  = objShipmentVM.Shipment.ShipmentDate;
                shipmentFromDb.isConfirmed   = objShipmentVM.Shipment.isConfirmed;

                //Cập nhật ID
                if (User.IsInRole(SD.SuperAdminEndUser))
                {
                    shipmentFromDb.SalesPersonID = objShipmentVM.Shipment.SalesPersonID;
                }
                _db.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(objShipmentVM));
        }