Exemplo n.º 1
0
        public async Task <ActionResult> Update(int id, [FromBody] RouteRequestDto dto)
        {
            var validator = new RouteValidator();
            var result    = await validator.ValidateAsync(dto);

            if (!result.IsValid)
            {
                return(BadRequest(result.Errors));
            }
            return(Ok(await _service.Update(id, dto)));
        }
Exemplo n.º 2
0
        public async Task <Route> Create(RouteRequestDto dto)
        {
            Route entity = _mapper.Map <RouteRequestDto, Route>(dto);

            entity.Train = await _unitOfWork._trainRepository.GetOneById(dto.TrainId);

            Route route = await _unitOfWork._routeRepository.Create(entity);

            await _unitOfWork.SaveChanges();

            return(route);
        }