public ActionResult AddBookingEvent(FormCollection eventAndBooking) { try { var bookingId = Convert.ToInt32(eventAndBooking["BookingID"]); var eventTypeId = Convert.ToInt32(eventAndBooking["EventTypeID"]); //get the booking var booking = db.Bookings.Where(x => x.BookingID.Equals(bookingId)).FirstOrDefault(); var property = booking.Property; //get the customer var customer = db.Customers.FirstOrDefault(x => x.CustomerID.Equals(booking.CustomerID)); var documentType = new PRCDocument.PRCDocumentType(); //create new event and assign the correct typeID HERE, then can make event creation generic var eventToAdd = CreateBookingEventViaFactory(eventTypeId, booking); /*var whatAmIReturning = FullyInstantiateAndRunEvent(customer, booking);*/ //////////GET TYPE OF DOCUMENT////// //STORE IN EVENT - DocumentEnum and Email Enum if (eventToAdd.EventType.DocumentEnumID != null) { documentType = (PRCDocument.PRCDocumentType)eventToAdd.EventType.DocumentEnumID; } ////BEGIN GENERIC CODE ///////////////////////////////////////// ////////CREATE EVENT DEPENDING ON SUB TYPE EventCommandCreateDocument createDocCommand; EventCommandSendEmail sendEmail; EventCommandDocumentOutDirectoryBundleAndEmail docBundle; switch (eventToAdd.EventType.EventSubTypeID) { case 1: //does nothing, just add event case 2: //email out sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailTemplateId, customer, booking); eventToAdd.EventCommands.Add(sendEmail); break; case 3: createDocCommand = new EventCommandCreateDocument(eventToAdd, customer, documentType, booking); sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailTemplateId, customer, booking); eventToAdd.EventCommands.Add(createDocCommand); eventToAdd.EventCommands.Add(sendEmail); //document out + email that document break; case 4: //email reminder sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailTemplateId, customer, booking); eventToAdd.EventCommands.Add(sendEmail); break; case 5: //create only sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailTemplateId, customer, booking); eventToAdd.EventCommands.Add(sendEmail); break; case 6: //composite bundle and email //get directory for docs var bundleDir = HttpRuntime.AppDomainAppPath + "FinalBookingDocuments\\" + property.LegacyReference.ToLower() + "\\"; docBundle = new EventCommandDocumentOutDirectoryBundleAndEmail(bundleDir, eventToAdd, customer, documentType, booking); sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailEnumID, customer, booking); eventToAdd.EventCommands.Add(docBundle); eventToAdd.EventCommands.Add(sendEmail); break; } var commandsAndResultsToLog = new List<EventCommand>(); //execute the commands //create document using executes //create emails and bodies //do all sending var result = new EventCommandResult(); foreach (var command in eventToAdd.EventCommands) { command.EventCommandResults.Add(command.ExecuteCommand()); commandsAndResultsToLog.Add(command); } /////END CREATE EVENT //////////////////////////// //DO LOGGING //if successful log the event and the commands that ran //save event EventLogger log = new EventLogger(db); //strip out event wiring before loggin eventToAdd.EventCommands = null; var doLogging = log.LogEvent(eventToAdd); var EventCommandLogger = new CommandLogger(db); var eventLogger = new EventLogger(db, EventCommandLogger); //save eventcoomand and result foreach (var commandAndResult in commandsAndResultsToLog) { EventCommandLogger.Log(eventToAdd.EventID, commandAndResult); } //save document generated //if there's any docs, write them to the DB foreach (var doc in eventToAdd.Documents) { doc.EventID = eventToAdd.EventID; doc.DocumentDescription = documentType.ToString(); doc.EmailTo = customer.EmailAddress; doc.CustomerID = customer.CustomerID; db.Documents.Add(doc); db.SaveChanges(); } //for view ViewBag.Bookingid = bookingId; var eventsForDDL = db.EventTypes.Where(x => x.EventSchemeTypeID == 1 || x.EventSchemeTypeID == 2).ToList(); ViewBag.EventTypeDDL = eventsForDDL; } catch (Exception ex) { MaintainanceMailer mail = new MaintainanceMailer(); mail.theAsposeMessage.Subject = "Adding Booking Event Failed"; mail.theAsposeMessage.Body = ex.Message.ToString(); mail.theAsposeMessage.Body += "----------------------------------"; mail.theAsposeMessage.Body += ex.InnerException.ToStringDescriptive(); throw ex; } return View(); }
public ActionResult AddBookingEvent(FormCollection eventAndBooking) { try { var bookingId = Convert.ToInt32(eventAndBooking["BookingID"]); var eventTypeId = Convert.ToInt32(eventAndBooking["EventTypeID"]); //get the booking var booking = db.Bookings.Where(x => x.BookingID.Equals(bookingId)).FirstOrDefault(); var property = booking.Property; //get the customer var customer = db.Customers.FirstOrDefault(x => x.CustomerID.Equals(booking.CustomerID)); var documentType = new PRCDocument.PRCDocumentType(); //create new event and assign the correct typeID HERE, then can make event creation generic var eventToAdd = CreateBookingEventViaFactory(eventTypeId, booking); /*var whatAmIReturning = FullyInstantiateAndRunEvent(customer, booking);*/ //////////GET TYPE OF DOCUMENT////// //STORE IN EVENT - DocumentEnum and Email Enum if (eventToAdd.EventType.DocumentEnumID != null) { documentType = (PRCDocument.PRCDocumentType)eventToAdd.EventType.DocumentEnumID; } ////BEGIN GENERIC CODE ///////////////////////////////////////// ////////CREATE EVENT DEPENDING ON SUB TYPE EventCommandCreateDocument createDocCommand; EventCommandSendEmail sendEmail; EventCommandDocumentOutDirectoryBundleAndEmail docBundle; switch (eventToAdd.EventType.EventSubTypeID) { case 1: //does nothing, just add event case 2: //email out sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailTemplateId, customer, booking); eventToAdd.EventCommands.Add(sendEmail); break; case 3: createDocCommand = new EventCommandCreateDocument(eventToAdd, customer, documentType, booking); sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailTemplateId, customer, booking); eventToAdd.EventCommands.Add(createDocCommand); eventToAdd.EventCommands.Add(sendEmail); //document out + email that document break; case 4: //email reminder sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailTemplateId, customer, booking); eventToAdd.EventCommands.Add(sendEmail); break; case 5: //create only sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailTemplateId, customer, booking); eventToAdd.EventCommands.Add(sendEmail); break; case 6: //composite bundle and email //get directory for docs var bundleDir = HttpRuntime.AppDomainAppPath + "FinalBookingDocuments\\" + property.LegacyReference.ToLower() + "\\"; docBundle = new EventCommandDocumentOutDirectoryBundleAndEmail(bundleDir, eventToAdd, customer, documentType, booking); sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailEnumID, customer, booking); eventToAdd.EventCommands.Add(docBundle); eventToAdd.EventCommands.Add(sendEmail); break; } var commandsAndResultsToLog = new List <EventCommand>(); //execute the commands //create document using executes //create emails and bodies //do all sending var result = new EventCommandResult(); foreach (var command in eventToAdd.EventCommands) { command.EventCommandResults.Add(command.ExecuteCommand()); commandsAndResultsToLog.Add(command); } /////END CREATE EVENT //////////////////////////// //DO LOGGING //if successful log the event and the commands that ran //save event EventLogger log = new EventLogger(db); //strip out event wiring before loggin eventToAdd.EventCommands = null; var doLogging = log.LogEvent(eventToAdd); var EventCommandLogger = new CommandLogger(db); var eventLogger = new EventLogger(db, EventCommandLogger); //save eventcoomand and result foreach (var commandAndResult in commandsAndResultsToLog) { EventCommandLogger.Log(eventToAdd.EventID, commandAndResult); } //save document generated //if there's any docs, write them to the DB foreach (var doc in eventToAdd.Documents) { doc.EventID = eventToAdd.EventID; doc.DocumentDescription = documentType.ToString(); doc.EmailTo = customer.EmailAddress; doc.CustomerID = customer.CustomerID; db.Documents.Add(doc); db.SaveChanges(); } //for view ViewBag.Bookingid = bookingId; var eventsForDDL = db.EventTypes.Where(x => x.EventSchemeTypeID == 1 || x.EventSchemeTypeID == 2).ToList(); ViewBag.EventTypeDDL = eventsForDDL; } catch (Exception ex) { MaintainanceMailer mail = new MaintainanceMailer(); mail.theAsposeMessage.Subject = "Adding Booking Event Failed"; mail.theAsposeMessage.Body = ex.Message.ToString(); mail.theAsposeMessage.Body += "----------------------------------"; mail.theAsposeMessage.Body += ex.InnerException.ToStringDescriptive(); throw ex; } return(View()); }