示例#1
0
        /// <inheritdoc />
        /// <summary>
        /// Inserts the event.
        /// </summary>
        /// <param name="umbracoContext">The umbraco context.</param>
        /// <param name="viewModel">The view model.</param>
        public void InsertEvent(
            UmbracoContext umbracoContext,
            InsertAppointmentViewModel viewModel)
        {
            CalendarService calendarService = GetCalendarService(umbracoContext);

            Event googleEvent = googleEventTranslator.Translate(viewModel);

            Event insertedEvent = googleCalendarServices.InsertEvent(calendarService, googleEvent);
        }
        /// <inheritdoc />
        /// <summary>
        /// Translates the specified view model.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <returns></returns>
        public AppointmentModel Translate(InsertAppointmentViewModel viewModel)
        {
            DateTime startTime = viewModel.StartTime.ToUniversalTime();
            DateTime now       = DateTime.Now.ToUniversalTime();

            AppointmentModel model = new AppointmentModel
            {
                CreatedTime       = now,
                LasteUpdatedTime  = now,
                StartTime         = startTime,
                Duration          = viewModel.Duration,
                Description       = viewModel.Description,
                Location          = viewModel.Location,
                PaymentId         = string.Empty,
                ServiceProviderId = viewModel.ServiceProviderId,
                Attendees         = GetAttendees(viewModel.Attendees)
            };

            return(model);
        }
示例#3
0
        public ActionResult InsertAppointment(InsertAppointmentViewModel viewModel)
        {
            LoggingService.Info(GetType());

            if (rulesEngineService.IsCustomerAppointmentsEnabled() == false)
            {
                ThrowAccessDeniedException("No Access to insert appointment");
            }

            if (!ModelState.IsValid)
            {
                return(CurrentUmbracoPage());
            }

            IPublishedContent publishedContent = GetContentById(CurrentPage.Id.ToString());

            string nextUrl = appointmentsManager.InsertAppointment(
                UmbracoContext,
                publishedContent,
                viewModel,
                Members.CurrentUserName);

            return(Redirect(nextUrl));
        }
示例#4
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);
        }
示例#5
0
 /// <inheritdoc />
 /// <summary>
 /// Translates the specified view model.
 /// </summary>
 /// <param name="viewModel">The view model.</param>
 /// <returns></returns>
 public Event Translate(InsertAppointmentViewModel viewModel)
 {
     return(new Event());
 }