public async Task SendReservationEmail(HotelReservation hotelReservation, RoomType roomType, IEnumerable <HotelPrice> dailyPrices, decimal vatAmount, int paidDays, string?country, string phoneNumber) { var hotel = await _meredithDbContext.Hotels .Include(item => item.Translations) .ThenInclude(item => item.Language) .Include(item => item.Page) .ThenInclude(item => item.Translations) .ThenInclude(item => item.Language) .Include(item => item.Spaces) .ThenInclude(item => item.Translations) .ThenInclude(item => item.Language) .Include(item => item.Amenities) .ThenInclude(item => item.Translations) .ThenInclude(item => item.Language) .Include(item => item.Rules) .ThenInclude(item => item.Translations) .ThenInclude(item => item.Language) .FirstOrDefaultAsync(item => item.Id == roomType.HotelId); if (hotel?.CompanyId is null) { // I don't think this is possible and I don't see any hotel without a companyId in db either // I don't know why we marked this is nullable throw new Exception("Hotel is not connected to any company."); } var templateData = new { resort = new { featuredImage = hotel.Page.FeaturedImage, h2 = hotel.Page.Translations.FirstOrDefault(t => t.Language.Culture == "en-US")?.Title }, numberOfGuests = hotelReservation.NumberOfGuests, checkIn = hotelReservation.Start.ToString("ddd, d MMM"), checkOut = hotelReservation.End.ToString("ddd, d MMM"), nightsCount = paidDays, prices = dailyPrices.Select(item => new { date = item.Date.ToString("ddd, d MMM"), amount = Math.Round(item.Amount, 2) }), vat = Math.Round(vatAmount, 2), amount = Math.Round(hotelReservation.Amount, 2), name = hotelReservation.Name, phoneCountry = country, phone = phoneNumber, email = hotelReservation.Email, message = hotelReservation.Message, roomDescriptionHTML = GetRoomDescription(hotel) }; var to = Tuple.Create(hotelReservation.User.Email, hotelReservation.User.UserName); await _sendGridService.SendEmail(hotel.CompanyId.Value, to, templateData); }
public async Task SendReservationEmail(Reservation reservation, RoomType roomType, IEnumerable <Price> dailyPrices, decimal vatAmount, int paidDays, string country, string phoneNumber) { var hotel = await _meredithDbContext.Hotels .Include(item => item.Translations) .ThenInclude(item => item.Language) .Include(item => item.Page) .Include(item => item.Spaces) .ThenInclude(item => item.Translations) .ThenInclude(item => item.Language) .Include(item => item.Amenities) .ThenInclude(item => item.Translations) .ThenInclude(item => item.Language) .Include(item => item.Rules) .ThenInclude(item => item.Translations) .ThenInclude(item => item.Language) .FirstOrDefaultAsync(item => item.Id == roomType.HotelId); var sendGridAccount = await GetSendGridAccount(hotel.CompanyId.Value); var templateData = new { bcc = sendGridAccount.Bcc, resort = new { featuredImage = hotel.Page.FeaturedImage, h2 = hotel.Page.Title }, numberOfGuests = reservation.NumberOfGuests, checkIn = reservation.Start.ToString("ddd, d MMM"), checkOut = reservation.End.ToString("ddd, d MMM"), nightsCount = paidDays, prices = dailyPrices.Select(item => new { date = item.Date.ToString("ddd, d MMM"), amount = Math.Round(item.Amount, 2) }), vat = Math.Round(vatAmount, 2), amount = Math.Round(reservation.Amount, 2), name = reservation.Name, phoneCountry = country, phone = phoneNumber, email = reservation.Email, message = reservation.Message, roomDescriptionHTML = GetRoomDescription(hotel) }; await _sendGridService.SendEmail(sendGridAccount.FromEmail, sendGridAccount.FromEmailName, reservation.User.Email, reservation.User.UserName, sendGridAccount.TemplateId, templateData); }