public async Task <IActionResult> CreateAsync([FromBody] CreateTripViewModel createTripViewModel) { var createTripDto = _mapper.Map <CreateTripDto>(createTripViewModel); var createdTripDto = await _tripService.CreateAsync(createTripDto); var createdTripViewModel = _mapper.Map <TripViewModel>(createdTripDto); return(Ok(createdTripViewModel)); }
public async Task <ActionResult <TripViewModel> > CreateTripAsync(TripItem tripItem) { Trip trip = new Trip(tripItem.Date, tripItem.IdDriver); _mapper.Map(tripItem, trip); try { trip = await _tripService.CreateAsync(trip); } catch (Exception exception) { return(BadRequest(exception)); } TripViewModel tripVM = await _tripQuery.GetTripByIdAsync(trip.Id); return(Ok(tripVM)); }
public async Task <ActionResult <BaseResult> > CreateAsync([FromBody, Required] TripDto tripDto) { if (!ModelState.IsValid) { return(BadRequest()); } var login = HttpContext.User.Identity.Name; var userAuth = await _authService.GetActiveUserByLoginAsNoTrackingAsync(login); if (userAuth.ForceRelogin) { throw new UnauthorizedException(string.Empty); } tripDto.UserId = userAuth.UserId; return(await _tripService.CreateAsync(tripDto)); }