public ActionResult Update(ShipmentFormViewModel viewModel) { if (!ModelState.IsValid) { //viewModel.TypeOfLoads = context.TypeOfLoads.ToList(); viewModel.TypeOfLoads = unitOfWork.TypeOfLoads.GetTypesOfLoad(); return(View("ShipmentForm", viewModel)); } //var shipmentDb = context.Shipments.Single(s => s.Id == viewModel.Id); var shipmentDb = unitOfWork.Shipments.GetShipment(viewModel.Id); if (shipmentDb == null) { return(HttpNotFound()); } if (shipmentDb.DriverId != User.Identity.GetUserId()) { return(new HttpUnauthorizedResult()); } shipmentDb.Modify(viewModel.GetDateTime(), viewModel.Location, viewModel.TypeOfLoad); //context.SaveChanges(); unitOfWork.Complete(); return(RedirectToAction("MyShipments", "Shipments")); }
public ActionResult Create(ShipmentFormViewModel viewModel) { if (!ModelState.IsValid) { //viewModel.TypeOfLoads = context.TypeOfLoads.ToList(); viewModel.TypeOfLoads = unitOfWork.TypeOfLoads.GetTypesOfLoad(); return(View("ShipmentForm", viewModel)); } var shipment = new Shipment() { DriverId = User.Identity.GetUserId(), DateTime = viewModel.GetDateTime(), TypeOfLoadId = viewModel.TypeOfLoad, Location = viewModel.Location }; //context.Shipments.Add(shipment); //context.SaveChanges(); unitOfWork.Shipments.Add(shipment); unitOfWork.Complete(); return(RedirectToAction("MyShipments", "Shipments")); }