public IActionResult Upsert(int?id) { UserDetails(); StationVM stationVM = new StationVM() { Station = new Station(), StationTypeList = _unitOfWork.StationType.GetAll().Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() }) }; if (id == null) { // for create return(View(stationVM)); } stationVM.Station = _unitOfWork.Station.Get(id.GetValueOrDefault()); if (stationVM.Station == null) { return(NotFound()); } return(View(stationVM)); }
public IActionResult Upsert(StationVM stationVM) { UserDetails(); if (ModelState.IsValid) { if (stationVM.Station.Id == 0) { _unitOfWork.Station.Add(stationVM.Station); } else { _unitOfWork.Station.Update(stationVM.Station); } _unitOfWork.Save(); return(RedirectToAction(nameof(Index))); } return(View(stationVM)); }