public ActionResult TestBookingSteps(Customer cus, CustomerBankDetail bank, List <Booking> bookings = null, List <BookingExtraSelection> bookingExtraSelections = null, List <BookingParticipant> bookingParticipants = null) { Session["prc_customer"] = new Customer(); using (var db = new PortugalVillasContext()) { var eventService = new EventController(); var bookingRepo = new FinalBookingDetailGatheringController(); //CUSTOMER //does customer have ID? if not create new Customer if (cus.CustomerID.Equals(0)) { bookingRepo.CreateCustomer(cus, db); } else { //update customer with new details /*cus.BookingExtraSelections = null; * cus.Bookings = null; * cus.CreationDate = cus.CreationDate; * * db.Customers.Attach(cus); * db.Entry(cus).State = EntityState.Modified; * * try * { * db.SaveChanges(); * } * catch (OptimisticConcurrencyException) * { * * } */ } //BANK DETAIL if (bank.CustomerBankDetailID.Equals(0)) { bookingRepo.CreateCustomerBankDetail(bank, cus, db); } else { //update customer with new details db.CustomerBankDetails.Attach(bank); db.Entry(bank).State = EntityState.Modified; db.SaveChanges(); } ////////////////// //BOOKING //create a parent booking thingy and link it BookingParentContainer parentContainer = new BookingParentContainer(); parentContainer.CustomerID = cus.CustomerID; parentContainer = bookingRepo.CreateBookingParentContainer(parentContainer, db); foreach (var booking in bookings) { //link to parent booking booking.BookingParentContainerID = parentContainer.BookingParentContainerID; //fill em out and push them to the DB /* bookingRepo.CreateBooking(booking, cus, db);*/ var participantsThisRound = bookingParticipants.Where(x => x.StepNo.Equals(bookingParticipants.Min(y => y.StepNo))).ToList(); //create the participants foreach (var bookingParticipant in participantsThisRound) { if (bookingParticipant.BookingParticipantFirstName != "" && bookingParticipant.BookingParticipantFirstName != null && bookingParticipant.BookingParticipantLastName != "" && bookingParticipant.BookingParticipantLastName != null) { bookingRepo.CreateBookingParticipant(participantsThisRound, booking, db); } } foreach (var bookingParticipant in participantsThisRound) { bookingParticipants.Remove(bookingParticipant); } //now check which booking form to send depending on location string EventTypeID; if (cus.Country.ToUpper() == "GB") { EventTypeID = "17"; } else { EventTypeID = "20"; } //email all docs var form = new FormCollection(); form.Add("BookingID", booking.BookingID.ToString()); form.Add("EventTypeID", EventTypeID); eventService.AddBookingEvent(form); //email the user of the system } foreach (var bes in bookingExtraSelections) { //link to parent booking } //wipe cars = booking and bes Session["Cart_PropertyBookings"] = null; Session["Cart_ExtraBookings"] = null; return(RedirectToAction("EndOfBookingProcess", "EndOfProcess")); } }
public ActionResult GetBookingDetails(Customer cus, CustomerBankDetail bank, List <Booking> bookings = null, List <BookingExtraSelection> bookingExtraSelections = null, List <BookingParticipant> bookingParticipants = null) { //set customer preferred currency symbol and currency using (var db = new PortugalVillasContext()) { var account = new AccountController(); var eventService = new EventController(); var bookingRepo = new FinalBookingDetailGatheringController(); //CUSTOMER //does customer have ID? if not create new Customer if (cus.CustomerID.Equals(0)) { var returnedCus = bookingRepo.CreateCustomer(cus, db); cus = returnedCus; Session["prc_customer"] = returnedCus; } else { //update customer with new details cus.BookingExtraSelections = null; cus.Bookings = null; //Do the UPDATE if (ModelState.IsValid) { db.Entry(cus).State = EntityState.Modified; var objContextCus = ((IObjectContextAdapter)db).ObjectContext; var refreshableObjectsCus = (from entry in objContextCus.ObjectStateManager.GetObjectStateEntries( EntityState.Added | EntityState.Deleted | EntityState.Modified | EntityState.Unchanged) where entry.EntityKey != null select entry.Entity); objContextCus.Refresh(RefreshMode.ClientWins, refreshableObjectsCus); //if it works, do the update for the userContext, else, don't as it failed if (objContextCus.SaveChanges() > 0) { /*_usersContext.Entry(user).State = EntityState.Modified; * _usersContext.SaveChanges();*/ } } } //BANK DETAIL if (bank.CustomerBankDetailID.Equals(0)) { var returnedBank = bookingRepo.CreateCustomerBankDetail(bank, cus, db); Session["prc_customerBankingDetail"] = returnedBank; } else { bank.CustomerID = cus.CustomerID; db.Entry(bank).State = EntityState.Modified; var objContext = ((IObjectContextAdapter)db).ObjectContext; var refreshableObjects = (from entry in objContext.ObjectStateManager.GetObjectStateEntries( EntityState.Added | EntityState.Deleted | EntityState.Modified | EntityState.Unchanged) where entry.EntityKey != null select entry.Entity); objContext.Refresh(RefreshMode.ClientWins, refreshableObjects); if (ModelState.IsValid) { if (objContext.SaveChanges() > 0) { ; } { //great it worked } } } //parent BookingParentContainer parentContainer = new BookingParentContainer(); parentContainer.CustomerID = cus.CustomerID; parentContainer = bookingRepo.CreateBookingParentContainer(parentContainer, db); //need to add booking reference then propagate to all others below ////////////////// //BOOKING //create a parent booking thingy and link i if (bookings != null) { foreach (var booking in bookings) { booking.Test = false; //it's real, from a customer //convert if neededed //link to parent booking booking.BookingParentContainerID = parentContainer.BookingParentContainerID; //fill em out and push them to the DB var property = db.Properties.Find(booking.PropertyID); booking.Property = property; booking.BookingParticipants = null; bookingRepo.CreateBooking(booking, property, cus, db); var participantsThisRound = bookingParticipants.Where(x => x.StepNo.Equals(bookingParticipants.Min(y => y.StepNo))) .ToList(); //create the participants var partstoAdd = new List <BookingParticipant>(); foreach (var bookingParticipant in participantsThisRound) { if (bookingParticipant.BookingParticipantFirstName != "" && bookingParticipant.BookingParticipantFirstName != null && bookingParticipant.BookingParticipantLastName != "" && bookingParticipant.BookingParticipantLastName != null) { partstoAdd.Add(bookingParticipant); } } foreach (var bookingParticipant in participantsThisRound) { bookingParticipants.Remove(bookingParticipant); } if (partstoAdd.Count > 0) { bookingRepo.CreateBookingParticipant(partstoAdd, booking, db); //create all ones we need } //now check which booking form to send depending on location string EventTypeID; TimeSpan dateRemainder = ((DateTime)booking.StartDate).Subtract(DateTime.Now); int dateRemainderDays = dateRemainder.Days; //late booking form if (cus.Country.ToLower() == "united kingdom" && ConfigurationManager.AppSettings["defaultCurrency"] == "GBP") { if (dateRemainderDays <= 30) { //late uk EventTypeID = "51"; } else { //standard UK EventTypeID = "37"; } } else { //convert all the bookings to euros if (dateRemainderDays <= 30) { //late EU EventTypeID = "52"; } else { //standard EU EventTypeID = "20"; } } //email all docs var form = new FormCollection(); form.Add("BookingID", booking.BookingID.ToString()); form.Add("EventTypeID", EventTypeID); eventService.AddBookingEvent(form); //email the user of the system } } if (bookingExtraSelections != null) { foreach (var bes in bookingExtraSelections) { //?????//convert all BES to EUROS var extraType = db.BookingExtras.Find((long)bes.BookingExtraID); bes.BookingExtraID = extraType.BookingExtraID; //link to parent booking bes.BookingParentContainerID = parentContainer.BookingParentContainerID; //need //reference //price fully done //all extras on form fully taken care of for each one var createdBes = bookingRepo.CreateBookingExtraSelection(bes, extraType, cus, db); string EventTypeID = ""; //car if (extraType.BookingExtraTypeID == 1) { if (cus.Country.ToLower() == "united kingdom") { EventTypeID = "43"; } else { EventTypeID = "62"; } } //wine else if (extraType.BookingExtraTypeID == 2) { if (cus.Country.ToLower() == "united kingdom") { EventTypeID = "45"; } else { EventTypeID = "60"; } } //airport else if (extraType.BookingExtraTypeID == 3) { if (cus.Country.ToLower() == "united kingdom") { EventTypeID = "31"; } else { EventTypeID = "61"; } } //tour else if (extraType.BookingExtraTypeID == 4) { if (cus.Country.ToLower() == "united kingdom") { EventTypeID = "33"; } else { EventTypeID = "63"; } } var form = new FormCollection(); form.Add("BookingExtraSelectionID", bes.BookingExtraSelectionID.ToString()); form.Add("EventTypeID", EventTypeID); eventService.AddBookingExtraSelectionEvent(form); } } //wipe cars = booking and bes Session["Cart_PropertyBookings"] = null; Session["Cart_ExtraBookings"] = null; //email the main user with the new services and bookings var prc = db.PRCInformations.First(); MaintainanceMailer mail = new MaintainanceMailer(); mail.theAsposeMessage.Subject = "You have new bookings:"; mail.theAsposeMessage.HtmlBody = "<h1>Automated email: You have a new booking</h1><br><p>Customer: ID - " + cus.CustomerID + "-" + cus.FirstName + " " + cus.LastName + "</p>"; if (bookings != null) { foreach (var booking in bookings) { mail.theAsposeMessage.HtmlBody += "<p>Booking: ID - " + booking.BookingID + "-" + booking.Property.LegacyReference + " for " + booking.NumberOfNights + " " + "nights starting " + booking.StartDate.ToString().Substring(0, 10) + "</p>"; } } if (bookingExtraSelections != null) { foreach (var bes in bookingExtraSelections) { mail.theAsposeMessage.HtmlBody += "<p>Booking: ID - " + bes.BookingExtraSelectionID + " - " + bes.BookingExtra.BookingExtraName + " for " + bes.NumberOfDays + " " + "days starting " + bes.ExtraRentalDate.ToString().Substring(0, 10) + " for " + bes.NumberOfGuests + " people" + "</p>"; } } var addressees = new MailAddressCollection(); addressees.Add(prc.PRCNotificationEmailAddress); if (prc.PRCNotificationEmailAddress2 != null) { if (prc.PRCNotificationEmailAddress2 != "") { addressees.Add(prc.PRCNotificationEmailAddress2); } } if (prc.PRCNotificationEmailAddress3 != null) { if (prc.PRCNotificationEmailAddress3 != "") { addressees.Add(prc.PRCNotificationEmailAddress3); } } mail.SendEmail(); return(RedirectToAction("EndOfBookingProcess", "EndOfProcess")); } }
public ActionResult TestBookingSteps(Customer cus, CustomerBankDetail bank, List<Booking> bookings = null, List<BookingExtraSelection> bookingExtraSelections = null, List<BookingParticipant> bookingParticipants = null) { Session["prc_customer"] = new Customer(); using (var db = new PortugalVillasContext()) { var eventService = new EventController(); var bookingRepo = new FinalBookingDetailGatheringController(); //CUSTOMER //does customer have ID? if not create new Customer if (cus.CustomerID.Equals(0)) { bookingRepo.CreateCustomer(cus, db); } else { //update customer with new details /*cus.BookingExtraSelections = null; cus.Bookings = null; cus.CreationDate = cus.CreationDate; db.Customers.Attach(cus); db.Entry(cus).State = EntityState.Modified; try { db.SaveChanges(); } catch (OptimisticConcurrencyException) { } */ } //BANK DETAIL if (bank.CustomerBankDetailID.Equals(0)) { bookingRepo.CreateCustomerBankDetail(bank, cus, db); } else { //update customer with new details db.CustomerBankDetails.Attach(bank); db.Entry(bank).State = EntityState.Modified; db.SaveChanges(); } ////////////////// //BOOKING //create a parent booking thingy and link it BookingParentContainer parentContainer = new BookingParentContainer(); parentContainer.CustomerID = cus.CustomerID; parentContainer = bookingRepo.CreateBookingParentContainer(parentContainer, db); foreach (var booking in bookings) { //link to parent booking booking.BookingParentContainerID = parentContainer.BookingParentContainerID; //fill em out and push them to the DB /* bookingRepo.CreateBooking(booking, cus, db);*/ var participantsThisRound = bookingParticipants.Where(x => x.StepNo.Equals(bookingParticipants.Min(y => y.StepNo))).ToList(); //create the participants foreach (var bookingParticipant in participantsThisRound) { if (bookingParticipant.BookingParticipantFirstName != "" && bookingParticipant.BookingParticipantFirstName != null && bookingParticipant.BookingParticipantLastName != "" && bookingParticipant.BookingParticipantLastName != null) { bookingRepo.CreateBookingParticipant(participantsThisRound, booking, db); } } foreach (var bookingParticipant in participantsThisRound) { bookingParticipants.Remove(bookingParticipant); } //now check which booking form to send depending on location string EventTypeID; if (cus.Country.ToUpper() == "GB") { EventTypeID = "17"; } else { EventTypeID = "20"; } //email all docs var form = new FormCollection(); form.Add("BookingID", booking.BookingID.ToString()); form.Add("EventTypeID", EventTypeID); eventService.AddBookingEvent(form); //email the user of the system } foreach (var bes in bookingExtraSelections) { //link to parent booking } //wipe cars = booking and bes Session["Cart_PropertyBookings"] = null; Session["Cart_ExtraBookings"] = null; return RedirectToAction("EndOfBookingProcess", "EndOfProcess"); } }
public ActionResult GetBookingDetails(Customer cus, CustomerBankDetail bank, List<Booking> bookings = null, List<BookingExtraSelection> bookingExtraSelections = null, List<BookingParticipant> bookingParticipants = null) { //set customer preferred currency symbol and currency using (var db = new PortugalVillasContext()) { var account = new AccountController(); var eventService = new EventController(); var bookingRepo = new FinalBookingDetailGatheringController(); //CUSTOMER //does customer have ID? if not create new Customer if (cus.CustomerID.Equals(0)) { var returnedCus = bookingRepo.CreateCustomer(cus, db); cus = returnedCus; Session["prc_customer"] = returnedCus; } else { //update customer with new details cus.BookingExtraSelections = null; cus.Bookings = null; //Do the UPDATE if (ModelState.IsValid) { db.Entry(cus).State = EntityState.Modified; var objContextCus = ((IObjectContextAdapter)db).ObjectContext; var refreshableObjectsCus = (from entry in objContextCus.ObjectStateManager.GetObjectStateEntries( EntityState.Added | EntityState.Deleted | EntityState.Modified | EntityState.Unchanged) where entry.EntityKey != null select entry.Entity); objContextCus.Refresh(RefreshMode.ClientWins, refreshableObjectsCus); //if it works, do the update for the userContext, else, don't as it failed if (objContextCus.SaveChanges() > 0) { /*_usersContext.Entry(user).State = EntityState.Modified; _usersContext.SaveChanges();*/ } } } //BANK DETAIL if (bank.CustomerBankDetailID.Equals(0)) { var returnedBank = bookingRepo.CreateCustomerBankDetail(bank, cus, db); Session["prc_customerBankingDetail"] = returnedBank; } else { bank.CustomerID = cus.CustomerID; db.Entry(bank).State = EntityState.Modified; var objContext = ((IObjectContextAdapter)db).ObjectContext; var refreshableObjects = (from entry in objContext.ObjectStateManager.GetObjectStateEntries( EntityState.Added | EntityState.Deleted | EntityState.Modified | EntityState.Unchanged) where entry.EntityKey != null select entry.Entity); objContext.Refresh(RefreshMode.ClientWins, refreshableObjects); if (ModelState.IsValid) { if (objContext.SaveChanges() > 0) ; { //great it worked } } } //parent BookingParentContainer parentContainer = new BookingParentContainer(); parentContainer.CustomerID = cus.CustomerID; parentContainer = bookingRepo.CreateBookingParentContainer(parentContainer, db); //need to add booking reference then propagate to all others below ////////////////// //BOOKING //create a parent booking thingy and link i if (bookings != null) { foreach (var booking in bookings) { booking.Test = false; //it's real, from a customer //convert if neededed //link to parent booking booking.BookingParentContainerID = parentContainer.BookingParentContainerID; //fill em out and push them to the DB var property = db.Properties.Find(booking.PropertyID); booking.Property = property; booking.BookingParticipants = null; bookingRepo.CreateBooking(booking, property, cus, db); var participantsThisRound = bookingParticipants.Where(x => x.StepNo.Equals(bookingParticipants.Min(y => y.StepNo))) .ToList(); //create the participants var partstoAdd = new List<BookingParticipant>(); foreach (var bookingParticipant in participantsThisRound) { if (bookingParticipant.BookingParticipantFirstName != "" && bookingParticipant.BookingParticipantFirstName != null && bookingParticipant.BookingParticipantLastName != "" && bookingParticipant.BookingParticipantLastName != null) { partstoAdd.Add(bookingParticipant); } } foreach (var bookingParticipant in participantsThisRound) { bookingParticipants.Remove(bookingParticipant); } if (partstoAdd.Count > 0) { bookingRepo.CreateBookingParticipant(partstoAdd, booking, db); //create all ones we need } //now check which booking form to send depending on location string EventTypeID; TimeSpan dateRemainder = ((DateTime)booking.StartDate).Subtract(DateTime.Now); int dateRemainderDays = dateRemainder.Days; //late booking form if (cus.Country.ToLower() == "united kingdom" && ConfigurationManager.AppSettings["defaultCurrency"] == "GBP") { if (dateRemainderDays <= 30) { //late uk EventTypeID = "51"; } else { //standard UK EventTypeID = "37"; } } else { //convert all the bookings to euros if (dateRemainderDays <= 30) { //late EU EventTypeID = "52"; } else { //standard EU EventTypeID = "20"; } } //email all docs var form = new FormCollection(); form.Add("BookingID", booking.BookingID.ToString()); form.Add("EventTypeID", EventTypeID); eventService.AddBookingEvent(form); //email the user of the system } } if (bookingExtraSelections != null) { foreach (var bes in bookingExtraSelections) { //?????//convert all BES to EUROS var extraType = db.BookingExtras.Find((long)bes.BookingExtraID); bes.BookingExtraID = extraType.BookingExtraID; //link to parent booking bes.BookingParentContainerID = parentContainer.BookingParentContainerID; //need //reference //price fully done //all extras on form fully taken care of for each one var createdBes = bookingRepo.CreateBookingExtraSelection(bes, extraType, cus, db); string EventTypeID = ""; //car if (extraType.BookingExtraTypeID == 1) { if (cus.Country.ToLower() == "united kingdom") { EventTypeID = "43"; } else { EventTypeID = "62"; } } //wine else if (extraType.BookingExtraTypeID == 2) { if (cus.Country.ToLower() == "united kingdom") { EventTypeID = "45"; } else { EventTypeID = "60"; } } //airport else if (extraType.BookingExtraTypeID == 3) { if (cus.Country.ToLower() == "united kingdom") { EventTypeID = "31"; } else { EventTypeID = "61"; } } //tour else if (extraType.BookingExtraTypeID == 4) { if (cus.Country.ToLower() == "united kingdom") { EventTypeID = "33"; } else { EventTypeID = "63"; } } var form = new FormCollection(); form.Add("BookingExtraSelectionID", bes.BookingExtraSelectionID.ToString()); form.Add("EventTypeID", EventTypeID); eventService.AddBookingExtraSelectionEvent(form); } } //wipe cars = booking and bes Session["Cart_PropertyBookings"] = null; Session["Cart_ExtraBookings"] = null; //email the main user with the new services and bookings var prc = db.PRCInformations.First(); MaintainanceMailer mail = new MaintainanceMailer(); mail.theAsposeMessage.Subject = "You have new bookings:"; mail.theAsposeMessage.HtmlBody = "<h1>Automated email: You have a new booking</h1><br><p>Customer: ID - " + cus.CustomerID + "-" + cus.FirstName + " " + cus.LastName + "</p>"; if (bookings != null) { foreach (var booking in bookings) { mail.theAsposeMessage.HtmlBody += "<p>Booking: ID - " + booking.BookingID + "-" + booking.Property.LegacyReference + " for " + booking.NumberOfNights + " " + "nights starting " + booking.StartDate.ToString().Substring(0, 10) + "</p>"; } } if (bookingExtraSelections != null) { foreach (var bes in bookingExtraSelections) { mail.theAsposeMessage.HtmlBody += "<p>Booking: ID - " + bes.BookingExtraSelectionID + " - " + bes.BookingExtra.BookingExtraName + " for " + bes.NumberOfDays + " " + "days starting " + bes.ExtraRentalDate.ToString().Substring(0, 10) + " for " + bes.NumberOfGuests + " people" + "</p>"; } } var addressees = new MailAddressCollection(); addressees.Add(prc.PRCNotificationEmailAddress); if (prc.PRCNotificationEmailAddress2 != null) if (prc.PRCNotificationEmailAddress2 != "") { addressees.Add(prc.PRCNotificationEmailAddress2); } if (prc.PRCNotificationEmailAddress3 != null) if (prc.PRCNotificationEmailAddress3 != "") { addressees.Add(prc.PRCNotificationEmailAddress3); } mail.SendEmail(); return RedirectToAction("EndOfBookingProcess", "EndOfProcess"); } }