public void Put(Guid id, [FromBody] TourBookingVM tbooking) { var booking = _uow.TourBookings.Get(id); booking.FullName = tbooking.FullName; booking.Email = tbooking.Email; booking.Mobile = tbooking.Mobile; booking.Note = tbooking.Note; booking.Address = tbooking.Address; booking.UserId = tbooking.UserId; booking.Status = tbooking.Status; booking.Deleted = tbooking.Deleted; _uow.TourBookings.Update(booking); var result = _uow.SaveChanges(); }
public void Post([FromBody] TourBookingVM tourBooking) { tourBooking.BookingPrices.Clear(); tourBooking.Id = Guid.NewGuid(); string emailDatas = tourBooking.FullName + "|" + tourBooking.Email + "|THANK YOU TO BOOKs TOUR AT FLASHTOUR"; decimal totalPrice = 0; for (var i = 0; i < 3; i++) { var tourBookingPrice = new BookingPriceVM(); tourBookingPrice.Id = Guid.NewGuid(); tourBookingPrice.TourBookingId = tourBooking.Id; tourBookingPrice.TouristType = i; var prices = _uow.Prices.GetSingleOrDefault(x => x.TouristType == i && x.TourId == tourBooking.TourId); var toCheck = DateTime.UtcNow; var min = prices.StartDatePro; var max = prices.EndDatePro; if (DateTime.Compare(toCheck, min) >= 0 && DateTime.Compare(toCheck, max) <= 0) { tourBookingPrice.Price = prices.PromotionPrice; } else { tourBookingPrice.Price = prices.OriginalPrice; } tourBooking.BookingPrices.Add(tourBookingPrice); } foreach (var tourBookingTourCustomer in tourBooking.TourCustomers) { tourBookingTourCustomer.Id = Guid.NewGuid(); var pricesCustomer = tourBooking.BookingPrices.SingleOrDefault(x => x.TouristType == tourBookingTourCustomer.TouristType && x.TourBookingId == tourBooking.Id); if (pricesCustomer != null) { totalPrice += pricesCustomer.Price; } tourBookingTourCustomer.TourBookingId = tourBooking.Id; } _uow.TourBookings.Add(_mapper.Map <TourBooking>(tourBooking)); var tour = _uow.Tours.GetSingleOrDefault(x => x.Id == tourBooking.TourId); emailDatas += "|" + tour.Id + "|" + totalPrice + "|" + tour.DepartureDate.AddDays(-3); tour.Slot -= tourBooking.TourCustomers.Count; SendEmail(emailDatas, tourBooking, 2); _uow.SaveChanges(); }
public bool SendEmail(string emailData, TourBookingVM tourBooking, int typeMail) { try { string[] emailDatas = emailData.Split("|"); var name = emailDatas[0]; var address = emailDatas[1]; var subject = emailDatas[2]; var tourId = emailDatas[3]; var totalPrices = emailDatas[4]; var departureDay = emailDatas[5]; var message = new MimeMessage(); message.From.Add(new MailboxAddress("FLASH TOUR", "*****@*****.**")); message.To.Add(new MailboxAddress(name, address)); message.Subject = subject; var text = ""; if (typeMail == 2) { text = "Welcome " + name + "\nThank you for choosing to book a tour at our Flash Tour Website!" + "\nYou have booked the tour and successfully paid with the following information:" + "\nTour code: " + tourId + "\nCustomer information:" + "\n- Full name:"+ name + "\n- Email: "+ address + "\n- PhoneNumber:" + tourBooking.Mobile + "\n- Total Price:" + totalPrices + "\nList tour customer:"; foreach (var tourBookingTourCustomer in tourBooking.TourCustomers) { text += "\nFull name: " + tourBookingTourCustomer.FullName; } text += "\nPlease pay the above amount via your account number 007.137.008.9095 3 days before the tour departure. Too many days on the tour will automatically be canceled." + "\n\nIf you have any questions, please contact our consultants or 24/7 customer service center at any FlashTour offices nationwide and foreign branches" + "\nTour booking is valid to " + departureDay + "\nThank you for your interest in the Flash Tour Website service." + "\nThis is an automated email system, please do not reply to this email."; } else { text = "Welcome " + name + "\nThank you for choosing to book a tour at our Flash Tour Website!" + "\nYou have booked the tour and successfully paid with the following information:" + "\nTour code: " + tourId + "\nTour booking code: " + tourBooking.Id + "\nCustomer information:" + "\n- Full name:"+ name + "\n- Email: "+ address + "\n- PhoneNumber:" + tourBooking.Mobile + "\n- Total Price:" + totalPrices + "\nList tour customer:"; foreach (var tourBookingTourCustomer in tourBooking.TourCustomers) { text += "\nFull name: " + tourBookingTourCustomer.FullName; } text += "\n\nIf you have any questions, please contact our consultants or 24/7 customer service center at any FlashTour offices nationwide and foreign branches" + "\nTour booking is valid to " + departureDay + "\nThank you for your interest in the Flash Tour Website service." + "\nThis is an automated email system, please do not reply to this email."; } message.Body = new TextPart("plain") { Text = text }; using (var client = new MailKit.Net.Smtp.SmtpClient()) { client.Connect("smtp.gmail.com", 587, false); //SMTP server authentication if needed client.Authenticate("*****@*****.**", "flashtour123"); client.Send(message); client.Disconnect(true); } } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } return(true); }
public void Post([FromBody] TourBookingVM tourBooking) { _uow.TourBookings.Add(_mapper.Map <TourBooking>(tourBooking)); _uow.SaveChanges(); }