Beispiel #1
0
        public void TestSaveEvents()
        {
            var eEvent = new Event
                             {
                                 Description = "Description",
                                 End = new EventDateTime { Date = DateTime.Today.AddDays(1).ToString("dd.MM.yyyy") },
                                 Start = new EventDateTime { Date = DateTime.Today.ToString("dd.MM.yyyy") },
                                 Summary = "Summary"
                             };

            var calendar = new Calendar();
            bool success = calendar.InsertEvents(new[] { eEvent });

            Assert.True(success);
        }
        /// <summary>
        /// Creates the events after business info participated.
        /// </summary>
        /// <param name="peopleContact">The people contact.</param>
        /// <param name="calendar">The calendar.</param>
        /// <returns>Task.</returns>
        private void CreateEventsAfterBusinessInfoParticipatedAsync(PeopleContact peopleContact, Calendar calendar)
        {
            CreateEventsAfterBusinessInfoParticipated(peopleContact);

            if (calendar.UseGoogleCalendar && !calendar.Authorized)
                return;

            var events = new Event[1];
            DateTime startDate = peopleContact.BusinessInfoParticipated.GetValueOrDefault(DateTime.Today).AddDays(2);
            events[0] = new Event
            {
                Start = new EventDateTime { DateTime = startDate },
                End = new EventDateTime { DateTime = startDate.AddDays(3) },
                Summary = String.Format(GoogleCalendarResource.PeopleContactController_CreateEventsAfterBusinessInfoParticipatedAsync_Summary, peopleContact.LastName, peopleContact.FirstName),
                Description = String.Format(GoogleCalendarResource.PeopleContactController_CreateEventsAfterBusinessInfoParticipatedAsync_Description, peopleContact.LastName, peopleContact.FirstName)
            };
            calendar.InsertEvents(events);
        }
        /// <summary>
        /// Checks the workflow.
        /// </summary>
        /// <param name="peopleContact">The peopleContactEdit.</param>
        /// <param name="previousPeopleContact">The previous people contact.</param>
        /// <param name="calendar">The calendar.</param>
        /// <returns>Task.</returns>
        private void CheckWorkflow(PeopleContact peopleContact, PeopleContact previousPeopleContact, Calendar calendar)
        {
            if (calendar.UseGoogleCalendar && !calendar.Authorized)
            {
                TempData[StatusMessageTempKey] = ValidationResource.Global_CannotConnectToGoogleCalendar_ErrorMessage;
            }

            if (!previousPeopleContact.Presented.HasValue && peopleContact.Presented.HasValue)
            {
                CreateEventsAfterPresentedAsync(peopleContact, calendar);
                return;
            }

            if (!previousPeopleContact.SecondContacted.HasValue && peopleContact.SecondContacted.HasValue)
            {
                CreateEventsAfterSecondContactedAsync(peopleContact, calendar);
            }

            if (!previousPeopleContact.BusinessInfoParticipated.HasValue && peopleContact.BusinessInfoParticipated.HasValue)
            {
                CreateEventsAfterBusinessInfoParticipatedAsync(peopleContact, calendar);
            }

            if (peopleContact.SecondMeeting.HasValue && peopleContact.ThirdMeeting.HasValue && peopleContact.TrackingEmailSent && peopleContact.SecondTrackingEmailSent)
            {
                peopleContact.WorkflowState = WorkflowState.Finished;
            }
        }
        /// <summary>
        /// Creates the events after presented.
        /// </summary>
        /// <param name="peopleContact">The people contact.</param>
        /// <param name="calendar">The calendar.</param>
        /// <returns>Task.</returns>
        private void CreateEventsAfterPresentedAsync(PeopleContact peopleContact, Calendar calendar)
        {
            CreateEventsAfterPresented(peopleContact);

            if (calendar == null || (calendar.UseGoogleCalendar && !calendar.Authorized))
                return;

            var events = new Event[2];
            DateTime startDate = peopleContact.Presented.GetValueOrDefault(DateTime.Today).AddDays(1);
            events[0] = new Event
                            {
                                Start = new EventDateTime { DateTime = startDate },
                                End = new EventDateTime { DateTime = startDate.AddDays(1) },
                                Summary = String.Format(GoogleCalendarResource.PeopleContactController_CreateEventsAfterPresentedAsync1_Summary, peopleContact.LastName, peopleContact.FirstName),
                                Description = String.Format(GoogleCalendarResource.PeopleContactController_CreateEventsAfterPresentedAsync1_Description, peopleContact.LastName, peopleContact.FirstName)
                            };

            events[1] = new Event
                            {
                                Start = new EventDateTime { DateTime = startDate },
                                End = new EventDateTime { DateTime = startDate.AddDays(14) },
                                Summary = String.Format(GoogleCalendarResource.PeopleContactController_CreateEventsAfterPresentedAsync2_Summary, peopleContact.LastName, peopleContact.FirstName),
                                Description = String.Format(GoogleCalendarResource.PeopleContactController_CreateEventsAfterPresentedAsync2_Description, peopleContact.LastName, peopleContact.FirstName)
                            };
            calendar.InsertEvents(events);
        }
        public async Task<ActionResult> EditTask(PeopleContactTask peopleContactTask, CancellationToken cancellationToken)
        {
            if (peopleContactTask.RegistrarId != UserId)
                return RedirectToAccessDenied();

            PeopleContact peopleContact = PeopleContactCache.GetDetailWithRegister(Db, peopleContactTask.PeopleContactId);
            if (peopleContact.RegistrarId != UserId)
                return RedirectToAccessDenied();

            var previousPeopleContact = new PeopleContact();
            previousPeopleContact.CopyFrom(peopleContact);

            PeopleContactTask tempPeopleContactTask = peopleContact.GetPeopleContactTasks(peopleContactTask.FieldName);
            peopleContactTask.Text = tempPeopleContactTask.Text;

            if (peopleContactTask.FieldValue == null)
            {
                ModelState.AddModelError(BaseCache.FieldValueField, String.Format(ValidationResource.Global_Required_ErrorMessage, FieldResource.Global_Date_Name));
            }
            else
            {
                switch (peopleContactTask.FieldName)
                {
                    case BaseCache.TrackingEmailSentField:
                        peopleContact.TrackingEmailSent = true;
                        if (peopleContact.Presented != null && (peopleContactTask.FieldValue < peopleContact.Presented.Value || peopleContactTask.FieldValue > DateTime.Today))
                        {
                            ModelState.AddModelError(BaseCache.FieldValueField, ValidationResource.PeopleContact_TrackingEmailSentAndPresentedComparing_ErrorMessage);
                        }
                        break;

                    case BaseCache.SecondContactedField:
                        peopleContact.SecondContacted = peopleContactTask.FieldValue;
                        if (peopleContact.Presented != null && (peopleContactTask.FieldValue < peopleContact.Presented.Value || peopleContactTask.FieldValue > DateTime.Today))
                        {
                            ModelState.AddModelError(BaseCache.FieldValueField, ValidationResource.PeopleContact_SecondContactedAndPresentedComparing_ErrorMessage);
                        }
                        break;

                    case BaseCache.SecondTrackingEmailSentField:
                        peopleContact.SecondTrackingEmailSent = true;
                        if (peopleContact.SecondContacted != null && (peopleContactTask.FieldValue < peopleContact.SecondContacted.Value || peopleContactTask.FieldValue > DateTime.Today))
                        {
                            ModelState.AddModelError(BaseCache.FieldValueField, ValidationResource.PeopleContact_SecondTrackingEmailSentAndSecondContactedComparing_ErrorMessage);
                        }
                        break;

                    case BaseCache.BusinessInfoParticipatedField:
                        peopleContact.BusinessInfoParticipated = peopleContactTask.FieldValue;
                        if (peopleContact.Presented != null && (peopleContactTask.FieldValue < peopleContact.Presented.Value || peopleContactTask.FieldValue > DateTime.Today))
                        {
                            ModelState.AddModelError(BaseCache.FieldValueField, ValidationResource.PeopleContact_BusinessInfoParticipatedAndPresentedComparing_ErrorMessage);
                        }
                        break;

                    case BaseCache.SecondMeetingField:
                        peopleContact.SecondMeeting = peopleContactTask.FieldValue;
                        if (peopleContact.SecondContacted != null && (peopleContactTask.FieldValue < peopleContact.SecondContacted.Value || peopleContactTask.FieldValue > DateTime.Today))
                        {
                            ModelState.AddModelError(BaseCache.FieldValueField, ValidationResource.PeopleContact_SecondMeetingAndSecondContactedComparing_ErrorMessage);
                        }
                        break;

                    case BaseCache.ThirdMeetingField:
                        peopleContact.ThirdMeeting = peopleContactTask.FieldValue;
                        if (peopleContact.BusinessInfoParticipated != null && (peopleContactTask.FieldValue < peopleContact.BusinessInfoParticipated.Value || peopleContactTask.FieldValue > DateTime.Today))
                        {
                            ModelState.AddModelError(BaseCache.FieldValueField, ValidationResource.PeopleContact_ThirdMeetingAndBusinessInfoParticipatedComparing_ErrorMessage);
                        }
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }

            if (ModelState.IsValid)
            {
                var calendar = new Calendar
                {
                    GoogleCredentialsJson = peopleContact.Registrar.GoogleCredentialsJson,
                    GoogleCalendarId = peopleContact.Registrar.GoogleCalendarId,
                    UseGoogleCalendarByUser = peopleContact.Registrar.UseGoogleCalendar,
                    UseMail = peopleContact.Registrar.UseMail,
                    EmailTo = peopleContact.Registrar.Email1,
                    ReminderTime = peopleContact.Registrar.ReminderTime,
                    IsEventsPrivate = peopleContact.Registrar.IsEventsPrivate
                };
                await calendar.AuthorizeAsync(this, cancellationToken);
                CheckWorkflow(peopleContact, previousPeopleContact, calendar);

                Db.Entry(peopleContact).State = EntityState.Modified;
                Db.SaveChanges();

                return View("EditTaskSummary", "_PopupLayout", peopleContactTask);
            }

            return View("EditTask", "_PopupLayout", peopleContactTask);
        }