示例#1
0
        public ActionResult GetCalendarUrl()
        {
            LoggingService.Info(GetType());

            AppointmentSettingsModel model = appointmentsProvider.GetAppointmentsModel(UmbracoContext);

            if (model != null)
            {
                if (model.GoogleCalendarEnabled &&
                    string.IsNullOrEmpty(model.GoogleCalendarUrl) == false)
                {
                    return(Content(model.GoogleCalendarUrl));
                }
            }

            return(Content(""));
        }
示例#2
0
        /// <summary>
        /// Gets the calendar URL.
        /// </summary>
        /// <param name="umbracoContext">The umbraco context.</param>
        /// <returns></returns>
        public string GetCalendarUrl(UmbracoContext umbracoContext)
        {
            AppointmentSettingsModel model = appointmentsProvider.GetAppointmentsModel(umbracoContext);

            return(model.GoogleCalendarUrl);
        }
示例#3
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);
        }