Пример #1
0
        /// <summary>
        /// Updates the appointment.
        /// </summary>
        /// <param name="umbracoContext">The umbraco context.</param>
        /// <param name="viewModel">The view model.</param>
        /// <param name="lastUpdatedUser">The last updated user.</param>
        /// <returns></returns>
        /// <inheritdoc />
        public string UpdateAppointment(
            UmbracoContext umbracoContext,
            UpdateAppointmentViewModel viewModel,
            string lastUpdatedUser)
        {
            loggingService.Info(GetType(), "Start");

            AppointmentSettingsModel appointmentSettingsModel = appointmentsProvider.GetAppointmentsModel(umbracoContext);

            AppointmentModel originalModel = databaseProvider.GetAppointment(Convert.ToInt32(viewModel.Id), GetCustomerId(umbracoContext));

            AppointmentModel appointmentModel = appointmentTranslator.Translate(originalModel, viewModel);

            appointmentModel.LastedUpdatedUser = lastUpdatedUser;

            loggingService.Info(GetType(), "Database Integration");

            databaseProvider.UpdateAppointment(appointmentModel);

            //// now update the attendees
            if (viewModel.Attendees != null)
            {
                UpdateAppointmentAttendees(appointmentModel.Id, viewModel.Attendees);
            }

            if (appointmentSettingsModel.GoogleCalendarIntegration)
            {
                loggingService.Info(GetType(), "Google Calendar Integration");
            }

            if (appointmentSettingsModel.IcalIntegration &&
                string.IsNullOrEmpty(appointmentSettingsModel.IcalUpdateEmailTemplate) == false)
            {
                Dictionary <string, string> dictionary = new Dictionary <string, string>
                {
                    { "AppointmentId", viewModel.Id.ToString() },
                    { "AppointmentStartTime", viewModel.StartTime.ToLongTimeString() },
                    { "AppointmentDuration", viewModel.Duration.ToString(CultureInfo.InvariantCulture) },
                    { "AppointmentLocation", viewModel.Location },
                    { "AppointmentDescription", viewModel.Description }
                };

                ICalAppointmentModel iCalModel = databaseProvider.GetIcalAppointment(viewModel.Id);

                ICalAppointmentModel iCalAppointmentModel = iCalendarService.GetICalAppoinment(
                    appointmentModel,
                    iCalModel.Guid,
                    iCalModel.Sequence + 1);

                Attachment attachment = Attachment.CreateAttachmentFromString(
                    iCalAppointmentModel.SerializedString,
                    iCalAppointmentModel.ContentType);

                mailProvider.SendEmail(
                    umbracoContext,
                    appointmentSettingsModel.IcalUpdateEmailTemplate,
                    appointmentSettingsModel.IcalEmailAddress,
                    attachment,
                    dictionary);

                if (appointmentSettingsModel.IcalSendToAttendees)
                {
                    if (appointmentModel.Attendees != null)
                    {
                        foreach (AppointmentAttendeeModel attendeeModel in appointmentModel.Attendees)
                        {
                            mailProvider.SendEmail(
                                umbracoContext,
                                appointmentSettingsModel.IcalUpdateEmailTemplate,
                                attendeeModel.EmailAddress,
                                attachment,
                                dictionary);
                        }
                    }
                }
            }

            //// TODO : this needs changing!!
            return("/customer/appointments");
        }
Пример #2
0
        /// <summary>
        /// Inserts the appointment.
        /// </summary>
        /// <param name="umbracoContext">The umbraco context.</param>
        /// <param name="publishedContent">Content of the published.</param>
        /// <param name="viewModel">The view model.</param>
        /// <param name="createdUser">The created user.</param>
        /// <returns></returns>
        /// <inheritdoc />
        public string InsertAppointment(
            UmbracoContext umbracoContext,
            IPublishedContent publishedContent,
            InsertAppointmentViewModel viewModel,
            string createdUser)
        {
            loggingService.Info(GetType(), "Start");

            PageModel pageModel = new PageModel(publishedContent);

            if (string.IsNullOrEmpty(pageModel.NextPageUrl))
            {
                loggingService.Info(GetType(), "Next Page Url not set");
            }

            if (string.IsNullOrEmpty(pageModel.ErrorPageUrl))
            {
                loggingService.Info(GetType(), "Error Page Url not set");
            }

            AppointmentSettingsModel settingsModel = appointmentsProvider.GetAppointmentsModel(umbracoContext);

            CustomerModel customerModel = customerProvider.GetCustomerModel(umbracoContext);

            AppointmentModel appointmentModel = insertAppointmentTranslator.Translate(viewModel);

            appointmentModel.CustomerId        = customerModel.Id;
            appointmentModel.CreatedUser       = createdUser;
            appointmentModel.LastedUpdatedUser = createdUser;

            int appointmentId = 0;

            loggingService.Info(GetType(), "Database Integration");

            appointmentId = databaseProvider.InsertAppointment(appointmentModel);

            if (appointmentId > 0)
            {
                cookieService.SetValue(AppointmentConstants.LastAppointmentIdCookie, appointmentId);
                eventPublisher.Publish(new AppointmentMadeMessage(appointmentId));
            }

            if (settingsModel.GoogleCalendarIntegration)
            {
                loggingService.Info(GetType(), "Google Calendar Integration");
            }

            if (settingsModel.IcalIntegration)
            {
                loggingService.Info(GetType(), "iCal Integration");

                ICalAppointmentModel iCalModel = iCalendarService.GetICalAppoinment(appointmentModel);

                Attachment attachment = Attachment.CreateAttachmentFromString(iCalModel.SerializedString, iCalModel.ContentType);

                Dictionary <string, string> dictionary = new Dictionary <string, string>
                {
                    { "AppointmentId", appointmentId.ToString() },
                    { "AppointmentStartTime", viewModel.StartTime.ToLongTimeString() },
                    { "AppointmentDuration", viewModel.Duration.ToString() },
                    { "AppointmentLocation", viewModel.Location },
                    { "AppointmentDescription", viewModel.Description }
                };

                //// try and send the email
                if (string.IsNullOrEmpty(settingsModel.IcalEmailAddress) == false)
                {
                    mailProvider.SendEmail(
                        umbracoContext,
                        settingsModel.IcalCreateEmailTemplate,
                        settingsModel.IcalEmailAddress,
                        attachment,
                        dictionary);

                    //// now update the database
                    if (appointmentId > 0)
                    {
                        iCalModel.AppointmentId = appointmentId;

                        databaseProvider.InsertIcalAppointment(iCalModel);
                    }
                }

                if (settingsModel.IcalSendToAttendees)
                {
                    foreach (AppointmentAttendeeModel attendeeModel in appointmentModel.Attendees)
                    {
                        mailProvider.SendEmail(
                            umbracoContext,
                            settingsModel.IcalCreateEmailTemplate,
                            attendeeModel.EmailAddress,
                            attachment,
                            dictionary);
                    }
                }
            }

            cookieService.SetValue(AppointmentConstants.LastAppointmentDuration, viewModel.Duration);

            loggingService.Info(GetType(), "End");

            return(pageModel.NextPageUrl);
        }
Пример #3
0
        /// <inheritdoc />
        /// <summary>
        /// Deletes the appointment.
        /// </summary>
        /// <param name="umbracoContext">The umbraco context.</param>
        /// <param name="appointmentId">The appointment identifier.</param>
        /// <returns></returns>
        public string DeleteAppointment(
            UmbracoContext umbracoContext,
            string appointmentId)
        {
            AppointmentSettingsModel appointmentSettingsModel = appointmentsProvider.GetAppointmentsModel(umbracoContext);

            string id = encryptionService.DecryptString(appointmentId);

            int appId = Convert.ToInt32(id);

            int customerId = GetCustomerId(umbracoContext);

            AppointmentModel appointmentModel = databaseProvider.GetAppointment(appId, customerId);

            appointmentModel.Status = (int)AppointmentStatus.Deleted;

            databaseProvider.UpdateAppointment(appointmentModel);

            if (appointmentSettingsModel.IcalIntegration &&
                string.IsNullOrEmpty(appointmentSettingsModel.IcalDeleteEmailTemplate) == false)
            {
                //// now send the delete ical email

                ICalAppointmentModel iCalModel = databaseProvider.GetIcalAppointment(appId);

                ICalAppointmentModel icalAppointmentModel = iCalendarService.GetICalAppoinment(
                    appointmentModel,
                    iCalModel.Guid,
                    iCalModel.Sequence + 1);

                Attachment attachment = Attachment.CreateAttachmentFromString(
                    icalAppointmentModel.SerializedString,
                    icalAppointmentModel.ContentType);

                Dictionary <string, string> dictionary = new Dictionary <string, string>
                {
                    { "AppointmentId", appointmentId }
                };

                mailProvider.SendEmail(
                    umbracoContext,
                    appointmentSettingsModel.IcalDeleteEmailTemplate,
                    appointmentSettingsModel.IcalEmailAddress,
                    attachment);

                if (appointmentSettingsModel.IcalSendToAttendees)
                {
                    if (appointmentModel.Attendees != null)
                    {
                        foreach (AppointmentAttendeeModel attendeeModel in appointmentModel.Attendees)
                        {
                            mailProvider.SendEmail(
                                umbracoContext,
                                appointmentSettingsModel.IcalDeleteEmailTemplate,
                                attendeeModel.EmailAddress,
                                attachment,
                                dictionary);
                        }
                    }
                }
            }

            if (appointmentSettingsModel.GoogleCalendarIntegration)
            {
            }

            //// TODO : this needs changing!!
            return("/customer/appointments");
        }
Пример #4
0
        /// <inheritdoc />
        /// <summary>
        /// Insertis the cal appointment.
        /// </summary>
        /// <param name="model">The model.</param>
        public void InsertIcalAppointment(ICalAppointmentModel model)
        {
            DatabaseContext context = ApplicationContext.Current.DatabaseContext;

            context.Database.Insert(model);
        }