示例#1
0
        public override EventCommandResult ExecuteCommand()
        {
            var result = new EventCommandResult();



            var dc = new DocumentGenerationController();
            //create a document with all parsed variables
            var document = dc.CreateDocument(this.customer, this.documentType, this.booking, this.bes);

            this.Event.Documents.Add(new Document
            {
                DocumentBLOB = document
            });


            if (booking != null)
            {
                this.Event.Documents.FirstOrDefault().DocumentName = "C" + customer.CustomerID + "B" + booking.BookingID +
                                                                     DateTime.Now.ToLongDateString() +
                                                                     documentType.ToString();
            }
            if (bes != null)
            {
                this.Event.Documents.FirstOrDefault().DocumentName = "C" + customer.CustomerID + "BE" + bes.BookingExtraSelectionID +
                                                                     DateTime.Now.ToLongDateString() +
                                                                     documentType.ToString();
            }

            //get that doc just created and add it to the event

            // this.Event.Documents.Add(document);


            if (!document.Equals(null) && !document.Equals(""))
            {
                result.ResultCode          = 200;
                result.CommandExecutedInfo = "DocumentOutCommand";
                result.ResultMessage       = "OK";
            }
            else
            {
                result.ResultCode          = 800;
                result.CommandExecutedInfo = "DocumentOutCommand";
                result.ResultMessage       = "Fail";
            }



            return(result);
        }
示例#2
0
        public override EventCommandResult ExecuteCommand()
        {
            var result = new EventCommandResult();

            var template = new StandardEmailTemplate(customer.EmailAddress, this.EmailTemplateId, customer, booking, bes);


            if (this.Event.Documents.Equals(null))
            {
                this.Event.Documents = new Collection <Document>();
                this.Event.Documents.Add(new Document());
            }

            if (this.Event.Documents.Count > 0)
            {
                foreach (var doc in this.Event.Documents)
                {
                    Stream docStream = new MemoryStream(doc.DocumentBLOB);
                    template.theAsposeMessage.AddAttachment(new Attachment(docStream, doc.DocumentName + ".pdf"));
                }
            }

            if (template.SendEmail())
            {
                result.ResultCode          = 200;
                result.CommandExecutedInfo = "EmailOutCommand";
                result.ResultMessage       = "OK";
            }
            else
            {
                result.ResultCode          = 800;
                result.CommandExecutedInfo = "EmailOutCommand";
                result.ResultMessage       = "Fail";
            }

            return(result);
        }
示例#3
0
        public void TestEventCommandAndLogging()
        {
            var db = new PortugalVillasContext();

            var anEvent = new Event();

            anEvent.WhenCreated = DateTime.Now;



            anEvent.Booking = db.Bookings.Find(4);

            long customerID = anEvent.Booking.CustomerID;

            //get other vars
            Customer aCustomer = db.Customers.Where(x => x.CustomerID == customerID).FirstOrDefault();


            EventCommandCreateDocument docEventCommand = new EventCommandCreateDocument(anEvent, aCustomer, PRCDocument.PRCDocumentType.UK_AirportTransfer, anEvent.Booking);

            anEvent.EventCommands.Add(docEventCommand);

            var result = new EventCommandResult();

            foreach (var command in anEvent.EventCommands)
            {
                result = command.ExecuteCommand();
            }

            //all done, do the logging

            var eventLogger = new EventLogger(db, new CommandLogger(db));

            eventLogger.LogEventAndCommandandCommandResult(anEvent, docEventCommand,
                                                           result);
        }
示例#4
0
        public void TestFullDocumentGenerateStack()
        {
            var db = new PortugalVillasContext();

            //Test WITH PARENT

            //TEST WITH BOOKING
            Booking booking = db.Bookings.Where(x => x.BookingID.Equals(4)).FirstOrDefault();

            booking.PropertyID = 221;
            /*           Booking booking = null;*/



            //TEST WITH CUSTOMER
            Customer aCustomer = db.Customers.Where(x => x.CustomerID == 1).FirstOrDefault();
            //TEST WITH BES
            var bes = db.BookingExtraSelections.Where(x => x.BookingExtraSelectionID == 3).First();

            bes.BookingExtraID = 1;

            //set up vars


            var type = PRCDocument.PRCDocumentType.UK_WineTasting;



            //create event  - need to give it type thus name
            var anEvent = new Event();

            anEvent.Documents = new List <Document>();
            //TEST ADD ID - PLEASE REMOVE
            anEvent.EventID = 2;
            //END TEST CODE

            anEvent.WhenCreated = DateTime.Now;
            var commandsAndResultsToLog = new List <EventCommand>();


            //create correct command
            //doc
            //email out with doc

            EventCommandCreateDocument createDocCommand;
            EventCommandSendEmail      sendEmail;

            //HOW DO WE DECIDE WHAT TYPE OF EVENT WE WANT??? depends on type??

            if (booking != null)
            {
                createDocCommand = new EventCommandCreateDocument(anEvent, aCustomer, type, booking);
                /* sendEmail = new EventCommandSendEmail(anEvent, aCustomer, booking);*/
            }
            else
            {
                createDocCommand = new EventCommandCreateDocument(anEvent, aCustomer, type, null, bes);
                /*/sendEmail = new EventCommandSendEmail(anEvent, aCustomer, null, bes);*/
            }



            //create all commands
            anEvent.EventCommands.Add(createDocCommand);
            /*       anEvent.EventCommands.Add(sendEmail);*/


            //create document using executes
            var result = new EventCommandResult();

            foreach (var command in anEvent.EventCommands)
            {
                command.EventCommandResults.Add(command.ExecuteCommand());
                commandsAndResultsToLog.Add(command);
            }

            //render

            //save to DB with all correct commands etc

            var EventCommandLogger = new CommandLogger(db);
            var eventLogger        = new EventLogger(db, EventCommandLogger);

            //save event
            eventLogger.LogEvent(anEvent);
            //save eventcoomand and result


            foreach (var commandAndResult in commandsAndResultsToLog)
            {
                EventCommandLogger.Log(anEvent.EventID, commandAndResult);
            }

            //save document generated

            //NEED TO ADD CORRECT PARAMS (which are what??)

            //if there's any docs, write them to the DB
            foreach (var doc in anEvent.Documents)
            {
                doc.EventID             = anEvent.EventID;
                doc.DocumentDescription = type.ToString();
                doc.EmailTo             = aCustomer.EmailAddress;
                doc.CustomerID          = aCustomer.CustomerID;

                db.Documents.Add(doc);
                db.SaveChanges();
            }
        }
示例#5
0
        public override EventCommandResult ExecuteCommand()
        {
            var result = new EventCommandResult();

            var dc = new DocumentGenerationController();

            IEnumerable <byte[]> theDocs = dc.GetAllFilesInADirectory(BundleDir);

            //attempt to pull all docs
            try
            {
                foreach (var doc in theDocs)
                {
                    var tempPdf = dc.ConvertWordBytesToPDFBytes(doc);



                    this.Event.Documents.Add(new Document
                    {
                        DocumentBLOB = tempPdf
                    });
                }
            }
            catch (Exception ex)
            {
                //generate email for error/write an error - provide a default document
                throw ex;
            }


            int i = 1;

            foreach (var doc in theDocs)
            {
                if (booking != null)
                {
                    this.Event.Documents.ElementAt(i - 1).DocumentName = "C" + customer.CustomerID + "B" + booking.BookingID +
                                                                         DateTime.Now.ToLongDateString() +
                                                                         documentType.ToString() + i.ToString();
                }
                if (bes != null)
                {
                    this.Event.Documents.ElementAt(i - 1).DocumentName = "C" + customer.CustomerID + "BE" + bes.BookingExtraSelectionID +
                                                                         DateTime.Now.ToLongDateString() +
                                                                         documentType.ToString() + i.ToString();
                }
                i++;
            }



            if (!this.Event.Documents.Equals(null) && this.Event.Documents.Any())
            {
                result.ResultCode          = 200;
                result.CommandExecutedInfo = "DocumentBundleCommand";
                result.ResultMessage       = "OK";
            }
            else
            {
                result.ResultCode          = 800;
                result.CommandExecutedInfo = "DocumentBundleCommand";
                result.ResultMessage       = "Fail";
            }



            return(result);
        }
        /// <summary>
        /// Logs
        /// </summary>
        /// <returns></returns>
        public int LogEventAndCommandandCommandResult(Event anEvent, EventCommand eventCommand, EventCommandResult result)
        {
            anEvent.EventCommands = null;
            //can't log a command without an event
            if (LogEvent(anEvent).Equals(0))
            {
                _commandLogger.Log(anEvent.EventID, eventCommand);
                return(0);
            }

            return(-1);
        }
示例#7
0
        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());
        }