public async Task <bool> AddAsync(AddAccommodationFormModel accommodationForm)
        {
            try
            {
                if (!(await _context.Accommodations.AnyAsync(x => x.Caption == accommodationForm.Caption)))
                {
                    var accommodation = new Accommodation()
                    {
                        Caption     = accommodationForm.Caption,
                        Address     = accommodationForm.Address,
                        CityId      = accommodationForm.CityId,
                        Code        = accommodationForm.Code,
                        District    = accommodationForm.District,
                        FileId      = accommodationForm.FileId,
                        IsActivated = accommodationForm.IsActivated,
                        Number      = accommodationForm.Number
                    };

                    await _context.Accommodations.AddAsync(accommodation);

                    await _context.SaveChangesAsync();

                    return(true);
                }
                else
                {
                    throw new ReservationGlobalException(AccommodationServiceErrors.AddDuplicateAccommodationError);
                }
            }
            catch (Exception ex)
            {
                throw new ReservationGlobalException(AccommodationServiceErrors.AddAccommodationError, ex);
            }
        }
Пример #2
0
 //[Authorize(Roles = "Accommodation-AddAccommodation")]
 public async Task <IActionResult> AddAccommodation([FromBody] AddAccommodationFormModel accommodationForm)
 {
     return(Ok(GetRequestResult(await _accommodationService.AddAsync(accommodationForm))));
 }