public static MailInfo CreateMail(this WebBooking bookingInfo, string htmlTemplate, HouseList houseList, RoomTypeList roomTypeList) { var result = new MailInfo { Subject = "New Customer Reservation", IsBodyHtml = true, To = new[] { ConfigManager.ReservationEmail } }; var house = houseList?.Houses.SingleOrDefault(h => h.Id.Equals(bookingInfo.HouseId)); var roomType = roomTypeList?.RoomTypes.SingleOrDefault(r => r.Id.Equals(bookingInfo.RoomTypeId)); var body = htmlTemplate.Replace("{{fullName}}", bookingInfo.Fullname); body = body.Replace("{{gender}}", bookingInfo.IsMale ? "Male" : "Female"); body = body.Replace("{{email}}", bookingInfo.Email); body = body.Replace("{{phone}}", bookingInfo.Phone); body = body.Replace("{{houseName}}", house == null ? "[Not Specified]" : house.Name); body = body.Replace("{{roomType}}", roomType == null ? "[Not Specified]" :roomType.Name + " - " + roomType.Price + "$"); body = body.Replace("{{dateRange}}", bookingInfo.From.ToString("d") + " - " + bookingInfo.To.ToString("d")); body = body.Replace("{{numPersons}}", bookingInfo.NumberOfPersons.ToString()); body = body.Replace("{{numRooms}}", bookingInfo.NumberOfRooms.ToString()); result.Body = body; return(result); }
public HttpResponseMessage Reserve(WebBooking bookingInfo) { var houseList = GetData <HouseList>("houses.json"); var roomTypeList = GetData <RoomTypeList>(bookingInfo.HouseId + "-roomtypes.json"); var mailInfo = bookingInfo.CreateMail(LoadTemplate("reservation.html"), houseList, roomTypeList); EmailService.SendMail(mailInfo); return(Request.CreateResponse(HttpStatusCode.OK)); }