예제 #1
0
 public static HotelAdmin GetHotelAdminInfo(this HotelCreateDTO dto)
 {
     return(new HotelAdmin()
     {
         Email = dto.AdminEmail,
         UserName = dto.AdminEmail
     });
 }
예제 #2
0
 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
     });
 }
예제 #3
0
        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());
        }
예제 #4
0
 public async Task <HotelDTO> RegisterHotel([FromBody] HotelCreateDTO hotelCreateDTO)
 {
     return(await hotelService.CreateHotel(hotelCreateDTO));
 }