public bool EventHasNotPassed(Event eventForInvitation)
        {
            var todaysDate   = ConvertDateTime.ToSwissTimezone(DateTime.UtcNow);
            var compareDates = eventForInvitation.StartDate.GetValueOrDefault().CompareTo(todaysDate);

            bool notPassed = compareDates >= 0;

            return(notPassed);
        }
        public static DateTime GetRemanderDate(Event eventToEdit)
        {
            // ReSharper disable once PossibleInvalidOperationException
            var remanderDateUtc = TimeZoneInfo.ConvertTimeToUtc((DateTime)eventToEdit.ReminderDate);

            var remainderDate = ConvertDateTime.ToSwissTimezone(remanderDateUtc);

            return(remainderDate);
        }
Example #3
0
        public ActionResult CopyEvent(
            [Bind(Include = "Title,Location,Description,StartDate,EndDate")] Event @event)
        {
            if (!ModelState.IsValid)
            {
                return(View("Create", @event));
            }
            // ReSharper disable once PossibleInvalidOperationException
            ConvertDateTime.ToSwissTimezone(TimeZoneInfo.ConvertTimeToUtc((DateTime)@event.StartDate));

            /*
             * Todo: the line below is only for debugging purposes:
             *       Its to log current time to see if the application is using client or server machine
             *       local time
             */
            ErrorSignal.FromCurrentContext().Raise(new Exception(String.Format("The current Event Date(local swiss time) is: {0}.  - (From Events controller)", @event.StartDate)));

            _service.SaveEvent(@event);
            return(RedirectToAction("SendEventsInvitation", "Invitation", new { id = @event.Id }));
        }
Example #4
0
        public ActionResult SendEventsInvitation([Bind(Include =
                                                           "ParticipantsEmails,EventDate,EventId,SendRemainder,ReminderDate,ListDate")] InvitationViewModel model)
        {
            var id = model.EventId;

            if (!ModelState.IsValid)
            {
                return(View(ReturnInvitationModel(id)));
            }

            //ToDo: change list and remainder dates to swiss time to be used for sending email

            // get event from database
            var eventForInvitation = GetEvent(id);

            eventForInvitation.ListDate =
                // ReSharper disable once PossibleInvalidOperationException
                ConvertDateTime.ToSwissTimezone(TimeZoneInfo.ConvertTimeToUtc((DateTime)model.ListDate));

            if (model.ReminderDate != null)
            {
                eventForInvitation.ReminderDate = ConvertDateTime.ToSwissTimezone(TimeZoneInfo.ConvertTimeToUtc((DateTime)model.ReminderDate));
                Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("{ From Invitation controller sending invitation } Remainder date is on " + eventForInvitation.ReminderDate));
            }

            /*
             * This is used to check time on the server
             * when this is deployed
             */

            Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("{ From Invitation controller sending invitation } List date is on " + eventForInvitation.ListDate));


            //Check if invitations can still be sent
            var notPassed = _service.EventHasNotPassed(eventForInvitation);

            if (!notPassed)
            {
                return(View("_CantInvite", eventForInvitation));
            }



            var unsavedContacts        = new UnsavedContactViewModel();
            EmailInformation emailInfo = null;
            var allSaved = false;
            var contacts = new List <Contact>();
            var emails   = new List <EmailInformation>();

            //loop through emails
            var emailList = model.ParticipantsEmails.Split(',').ToList();

            foreach (var participantEmail in emailList)
            {
                var email = _service.RemoveBrackets(participantEmail);

                //save new participant
                SaveParticipantInDb(email, eventForInvitation);


                #region Create and send Email

                emailInfo = ComposeEmailInfo(eventForInvitation, email);
                emails.Add(emailInfo);

                //Send Invitation Email
                try
                {
                    PostalEmailManager.SendEmail(emailInfo, new InvitationEmail());

                    //todo: this is to be removed before deployment for production
                    Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Email sent to " + emailInfo.ParticipantEmail));

                    if (model.SendRemainder)
                    {
                        var remainderDate = Service.GetRemanderDate(eventForInvitation);
                        JobManager.ScheduleRemainderEmail(emails, remainderDate);

                        //todo: this is to be removed before deployment for production
                        Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("remainder is set at " + remainderDate));
                    }
                }
                catch (Exception exception)
                {
                    Elmah.ErrorSignal.FromCurrentContext().Raise(exception);
                    return(RedirectToAction("Error"));
                }


                #endregion

                #region after sending email, save unsaved contacts

                var contactEmails = _contactsController.GetUserContacts(UserId);
                allSaved = contactEmails.Any(c => c.Email == email);

                if (allSaved)
                {
                    continue;
                }
                var contact = new Contact {
                    Email = email
                };
                contacts.Add(contact);
                unsavedContacts.Contacts = contacts;

                #endregion
            }

            #region Scheduling List email

            // start participant list summary scheduler
            var listDate = Service.GetListDate(eventForInvitation);
            JobManager.ScheduleParticipantListEmail(emailInfo, listDate);

            #endregion

            //redirect to details if all contacts are saved
            if (allSaved)
            {
                Response.Cookies.Add(new HttpCookie("successCookie", "Action is completed successfully"));

                return(RedirectToAction("Details", "Events", new { id }));
            }

            //Let user save his contacts return view with list of unsaved contacts
            unsavedContacts.EventId = eventForInvitation.Id;
            TempData["model"]       = unsavedContacts;     //Pass list to SaveEmails action
            return(RedirectToAction("SaveEmails"));
        }