public static HotelAdmin GetHotelAdminInfo(this HotelCreateDTO dto) { return(new HotelAdmin() { Email = dto.AdminEmail, UserName = dto.AdminEmail }); }
public static Hotel ToHotel(this HotelCreateDTO dto) { return(new Hotel() { Name = dto.Name, Address = dto.Address, City = dto.City, Country = dto.Country, Stars = dto.Stars }); }
public async Task <HotelDTO> CreateHotel(HotelCreateDTO hotelCreateDTO) { ValidationResults result = ModelValidator.IsValid(hotelCreateDTO); if (!result.Successed) { throw ValidationExceptionBuilder.BuildValidationException(result); } var hotelAdmin = hotelCreateDTO.GetHotelAdminInfo(); string password = GeneratePassword(); await CheckIfThePasswordIsValid(password); await CheckIfTheUserDoesNotExist(hotelAdmin); hotelAdmin.EmailConfirmed = true; var isCreated = await _userManager.CreateAsync(hotelAdmin, password); if (!isCreated.Succeeded) { throw new DBException("Cann't create new hotel admin"); } var isAddedToRole = await _userManager.AddToRoleAsync(hotelAdmin, "hotel-admin"); if (!isAddedToRole.Succeeded) { throw new DBException("Cann't add new user to hotel admin's role"); } var newHotelAdmin = await _userManager.FindByEmailAsync(hotelAdmin.Email); var hotel = hotelCreateDTO.ToHotel(); hotel.HotelAdminId = newHotelAdmin.Id; context.Hotels.Create(hotel); await context.SaveAsync(); string message = "Ваш пароль у системi: " + password; await EmailService.SendEmailAsync(newHotelAdmin.Email, "HotelLocker", message); return(hotel.ToHotelDTO()); }
public async Task <HotelDTO> RegisterHotel([FromBody] HotelCreateDTO hotelCreateDTO) { return(await hotelService.CreateHotel(hotelCreateDTO)); }