public async Task <ActionResult> Create([FromBody] TrainRequestDto dto) { var validator = new TrainValidator(); var result = await validator.ValidateAsync(dto); if (!result.IsValid) { return(BadRequest(result.Errors)); } return(Ok(await _service.Create(dto))); }
public IActionResult Create(TrainCreateViewModel model) { Train train = new Train() { Capacity = model.Capacity, Number = model.Number, Type = model.IsFast ? "Fast" : "Normal" }; trainService.Create(train); return(RedirectToAction("Index")); }
public ActionResult Insert(TrainViewModel train) { if (IsAdmin) { try { var trainDto = new TrainDetailDTO { Train_Name = train.Train_Name, Train_Desc = train.Train_Desc, From_City = train.From_City, To_City = train.To_City, ArrivalDate = train.ArrivalDate, DepartureDate = train.DepartureDate }; trainService.Create(trainDto); return(Content("<h2>Поезд успешно добавлен</h2> <a href='/'> На главную </a>")); } catch (ValidationException ex) { ModelState.AddModelError(ex.Property, ex.Message); } return(View(train)); } return(RedirectToAction("Login", "Account")); }