public async Task AddReservationAsync(ReservationParamsDTO reservationParamsDTO) { var email = _httpContextAccessor.HttpContext.User.FindFirst(ClaimsIdentity.DefaultNameClaimType).Value; var user = (await _userRepository.GetAllAsync(x => x.Email.ToUpper().Equals(email.ToUpper()))) .FirstOrDefault(); if (user == null) { throw new EntityNotExistException("User does not exist."); } var apartment = await(await _apartmentRepository.GetAllAsync(x => x.Id == reservationParamsDTO.IdApartment)) .FirstOrDefaultAsync(); var reservation = _mapper.Map <ApartmentReservation>(reservationParamsDTO); reservation.Apartment = apartment ?? throw new EntityNotExistException("Apartment not found."); reservation.CreatedBy = user.Id; reservation.Client = user; await _reservationRepository.InsertAsync(reservation); }
public async Task <IActionResult> OrderFlat(ReservationParamsDTO reservationParams) { try { await _reservationService.AddReservationAsync(reservationParams); return(Ok()); } catch (EntityNotExistException e) { return(BadRequest(e.Message)); } catch (DbUpdateConcurrencyException e) { return(BadRequest(e.Message)); } catch (Exception e) { return(BadRequest(e)); } }