public ActionResult Edit(TaxiDetailsVM taxiDetailsVM) { try { if (ModelState.IsValid) { var taxi = this.Data.Taxies.Find(taxiDetailsVM.TaxiId); if (taxi.Status != TaxiStatus.Unassigned || taxi.Status != TaxiStatus.Decommissioned) { TempData["Error"] = "Taxi should be Unassigned or Decommissioned to be changed!"; return(PartialView("Edit", taxiDetailsVM)); } taxi.Plate = taxiDetailsVM.Plate; taxi.Seats = taxiDetailsVM.Seats; taxi.Luggage = taxiDetailsVM.Luggage; if (taxiDetailsVM.AssignDistrictId != 0) { District district = this.Data.Districts.All().First(d => d.DistrictId == taxiDetailsVM.AssignDistrictId); if (district == null) { TempData["Error"] = "District not found!"; return(PartialView("Edit", taxiDetailsVM)); } taxi.District = district; } taxi.Status = TaxiStatus.Unassigned; this.Data.Taxies.Update(taxi); this.Data.SaveChanges(); return(JavaScript("alert('Success')")); } var districts = this.populator.GetDistricts(); ViewBag.Districts = districts; return(PartialView("Edit", taxiDetailsVM)); } catch (Exception e) { return(Content("Error occured:" + e.ToString())); } }
public ActionResult Create(TaxiDetailsVM newTaxi) { try { if (ModelState.IsValid) { District district = this.Data.Districts.All().First(d => d.DistrictId == newTaxi.AssignDistrictId); Taxi taxi = TaxiDetailsVM.FromTaxiDetailsVM(newTaxi, district); this.Data.Taxies.Add(taxi); this.Data.SaveChanges(); return(RedirectToAction("Index")); } return(View("Create", newTaxi)); } catch { return(View()); } }