//create or update public ActionResult CreateOrUpdatePort(Guid rowId, Guid countryId) { var model = new PortModel(); if (rowId.IsEmpty()) model.CountryId = countryId; else { var port = portService.GetById(rowId); if (port != null) { model = port.ToModel(); model.IsEdit = true; } } return PartialView("_CreateOrUpdatePort", model); }
public ActionResult CreateOrUpdatePort(PortModel model) { var country = countryService.GetById(model.CountryId); if (country == null) //No country found with the specified id return Json(new { IsValid = false, errorMessage = "Country does not exists" }); if (ModelState.IsValid) { if (model.RowId.IsEmpty()) portService.Insert(model.ToEntity()); else { var port = portService.GetById(model.RowId); if (port == null) //No state found with the specified id return Json(new { IsValid = false, errorMessage = "Port does not exists" }); port = model.ToEntity(port); portService.Update(port); } return Json(new { IsValid = true }); } //If we got this far, something failed, redisplay form return Json(new { IsValid = false, htmlData = RenderPartialViewToString("_CreateOrUpdatePort", model) }); }