public async Task <IActionResult> CreateStop([FromBody] StopForCreationDTO stopInput)
        {
            if (stopInput == null)
            {
                return(BadRequest());
            }

            if (stopInput.Name.Equals(stopInput.Description, StringComparison.CurrentCultureIgnoreCase))
            {
                ModelState.AddModelError(nameof(StopForCreationDTO), "Stop name and description must be different!");
            }

            if (!ModelState.IsValid)
            {
                return(new UnprocessableEntityObjectResult(ModelState));
            }

            StopDTO stop = await _stopBus.CreateStop(stopInput);

            if (stop == null)
            {
                return(StatusCode(500, "Insert failure"));
            }

            return(CreatedAtRoute("GetStop", new { id = stop.Id }, stop));
        }
        public async Task <StopDTO> CreateStop(StopForCreationDTO stopModel)
        {
            Stop stop = StopMapper.ConvertCreationModelToEntity(stopModel);

            if (await _stopRepo.CreateStop(stop))
            {
                return(StopMapper.ConvertEntityToModel(stop));
            }

            return(null);
        }
示例#3
0
 public static Stop ConvertCreationModelToEntity(StopForCreationDTO stopInput)
 {
     return(AutoMapperContainer.GenericConvert <Stop>(stopInput));
 }