public ActionResult Edit(TrainParam _trainparam) { if (ModelState.IsValid) { _TrainService.Update(_trainparam); return(RedirectToAction("Index")); } return(View(_trainparam)); }
public async Task <ActionResult> Update(int id, [FromBody] TrainRequestDto dto) { var validator = new TrainValidator(); var result = await validator.ValidateAsync(dto); if (!result.IsValid) { return(BadRequest(result.Errors)); } return(Ok(await _service.Update(id, dto))); }
public IActionResult Edit(TrainEditViewModel model) { Train train = new Train() { Capacity = model.Capacity, Id = model.Id, Number = model.Number, Type = model.IsFast ? "Fast" : "Normal" }; trainService.Update(train); return(RedirectToAction("Index")); }
public ActionResult Edit(TrainViewModel train) { if (IsAdmin) { try { var trainDto = new TrainDetailDTO { 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 }; trainService.Update(trainDto); return(Content("<h2>Поезд успешно обновлен</h2> <a href='/'> На главную </a>")); } catch (ValidationException ex) { ModelState.AddModelError(ex.Property, ex.Message); } return(View(train)); } return(RedirectToAction("Index")); }