public ActionResult Edit(int?id) { if (IsAdmin) { try { TrainDetailDTO train = trainService.GetTrain(id); var Train = new TrainViewModel { Train_Name = train.Train_Name, Id = train.Id, Train_Desc = train.Train_Desc, From_City = train.From_City, To_City = train.To_City, ArrivalDate = train.ArrivalDate, DepartureDate = train.DepartureDate }; return(View(Train)); } catch (ValidationException ex) { return(Content(ex.Message)); } } return(RedirectToAction("Index")); }
public ActionResult EditTrain(int?id) { TrainDTO trainDto = _trainService.GetTrain(id); if (trainDto == null) { throw new ValidationException("Не установлено id поезда", ""); } var mapper = new MapperConfiguration(cfg => cfg.CreateMap <TrainDTO, TrainViewModel>()).CreateMapper(); var trainView = mapper.Map <TrainDTO, TrainViewModel>(trainDto); return(View(trainView)); }
public IActionResult DeleteTrain(int id) { var train = _train.GetTrain(id); if (train.TrainId == id) { _train.DeleteTrain(id); return(Ok()); } else { return(NotFound($"Train with id {id} was not found")); } }