Esempio n. 1
0
        private void SendNotification(Lesson lesson, Enumerations.NotificationEmailType notificationType)
        {
            List <EmailInfo> email = new List <EmailInfo>();

            if (lesson != null)
            {
                email = GenerateNotifications(new List <Lesson> {
                    lesson
                }, notificationType);
            }

            LessonBusiness lessonManager = new LessonBusiness(DbContext);

            lessonManager.SendEmails(email);
        }
        public IActionResult SendNotifications(AdminViewData updatedModel)
        {
            ApplicationContext appContext = new ApplicationContext(this.Cache);

            if (ViewData.ModelState["NotificationDays"].Errors.Count == 0)
            {
                UserSessionContext userContext     = new UserSessionContext(this.HttpContext);
                LessonBusiness     businessManager = new LessonBusiness(DbContext);
                var notificationType = (Enumerations.NotificationEmailType)updatedModel.EmailNotificationType;

                List <Lesson> lessons = businessManager.GetLessonsForNotification(notificationType, updatedModel.NotificationDays);

                if (lessons != null && lessons.Count > 0)
                {
                    List <EmailInfo> emailList = new List <EmailInfo>();

                    foreach (var lesson in lessons)
                    {
                        //If this key exists in the web.config, re-direct all eamils to that address.
                        string overrideEmailAddress = Utility.SafeGetAppConfigSetting <string>("Debug_OverrideEmailAddress", null);

                        EmailTemplateViewData model = new EmailTemplateViewData(LessonViewModel.ToViewModel(this.HttpContext, lesson), notificationType, appContext, overrideEmailAddress);
                        string emailMessageBody     = Utils.RenderPartialViewToString(this, "EmailTemplate", model);

                        EmailInfo emailInfo = new EmailInfo
                        {
                            Body    = emailMessageBody,
                            MailTo  = model.Redirecting ? model.OverrideMailTo : model.MailTo,
                            Subject = model.Subject
                        };

                        emailList.Add(emailInfo);
                    }

                    businessManager.SendEmails(emailList);
                }

                this.SetEmailsSent();

                return(RedirectPermanent("Index"));
            }

            ModelState.Clear();

            AddError("X Days is invalid");

            return(Index());
        }
Esempio n. 3
0
        public IActionResult BulkSave(LessonIndexViewModel updatedModel)
        {
            UserSessionContext userSessionContext = new UserSessionContext(this.HttpContext);
            ApplicationContext appContext         = new ApplicationContext(this.HttpContext);
            LessonBusiness     lessonManager      = new LessonBusiness(DbContext);
            var              selectedLessonIds    = string.IsNullOrWhiteSpace(updatedModel.BulkSelectedLessons) ? new List <int>() : updatedModel.BulkSelectedLessons.Split(',').Select(x => int.Parse(x)).ToList();
            var              selectedLessons      = userSessionContext.LastSearchResults.Where(x => selectedLessonIds.Contains(x.Id));
            List <string>    errorMessages        = new List <string>();
            bool             hasSuccesses         = false;
            List <EmailInfo> emailsToSend         = new List <EmailInfo>();
            List <Lesson>    AssignLessonIds      = new List <Lesson>();

            if (updatedModel.BulkLesson.SaveAction == Enumerations.SaveAction.ActionLog ||
                updatedModel.BulkLesson.SaveAction == Enumerations.SaveAction.CsvLog ||
                updatedModel.BulkLesson.SaveAction == Enumerations.SaveAction.CsvLogAll ||
                updatedModel.BulkLesson.SaveAction == Enumerations.SaveAction.ActionLogAll)
            {
                Enumerations.LogType logType = Enumerations.LogType.ActionLog;

                if (updatedModel.BulkLesson.SaveAction == Enumerations.SaveAction.CsvLog ||
                    updatedModel.BulkLesson.SaveAction == Enumerations.SaveAction.CsvLogAll)
                {
                    logType = userSessionContext.CurrentUser.RoleId == (int)Enumerations.Role.Administrator ? Enumerations.LogType.AdminLog : Enumerations.LogType.GenericLog;
                }

                if (updatedModel.BulkLesson.SaveAction == Enumerations.SaveAction.CsvLogAll ||
                    updatedModel.BulkLesson.SaveAction == Enumerations.SaveAction.ActionLogAll)
                {
                    userSessionContext.ExportLog = lessonManager.GenerateLog(userSessionContext.CurrentUser, userSessionContext.LastSystemSearch, logType);
                }
                else
                {
                    userSessionContext.ExportLog = lessonManager.GenerateLog(selectedLessonIds, logType);
                }
            }
            else
            {
                foreach (var selectedLesson in selectedLessons)
                {
                    if (updatedModel.BulkLesson.SaveAction == Enumerations.SaveAction.Delete ||
                        updatedModel.BulkLesson.SaveAction == Enumerations.SaveAction.UnDelete)
                    {
                        //Just save, no need to validate
                        lessonManager.SaveLesson(selectedLesson, userSessionContext.CurrentUser, null, updatedModel.BulkLesson.SaveAction);
                        hasSuccesses = true;
                    }
                    else
                    {
                        List <Lesson> successLessons = new List <Lesson>();

                        if (updatedModel.BulkLesson.SaveAction == Enumerations.SaveAction.BPOToClose)
                        {
                            selectedLesson.Resolution          = updatedModel.BulkLesson.Resolution;
                            selectedLesson.LessonTypeValidId   = updatedModel.BulkLesson.LessonTypeValidId;
                            selectedLesson.LessonTypeInvalidId = updatedModel.BulkLesson.LessonTypeInvalidId;
                        }

                        var model = LessonViewModel.ToViewModel(this.HttpContext, selectedLesson);
                        model.TransferBpoDisciplineId = updatedModel.BulkLesson.TransferBpoDisciplineId;
                        model.SaveAction = updatedModel.BulkLesson.SaveAction;

                        var validatedErrors = model.Validate(null);

                        if (validatedErrors.Count() == 0)
                        {
                            string comment = null;
                            switch (updatedModel.BulkLesson.SaveAction)
                            {
                            case Enumerations.SaveAction.AdminToClarification:
                            case Enumerations.SaveAction.BPOToClarification:
                            case Enumerations.SaveAction.ClarificationToBPO:
                            case Enumerations.SaveAction.ClarificationToAdmin:
                                comment = updatedModel.BulkLesson.ClarificationComment;
                                break;

                            case Enumerations.SaveAction.AdminToBPO:
                            case Enumerations.SaveAction.BPOToBPO:
                                selectedLesson.DisciplineId = updatedModel.BulkLesson.TransferBpoDisciplineId;
                                comment = updatedModel.BulkLesson.TransferBpoComment;
                                break;

                            case Enumerations.SaveAction.BPOToClose:
                                comment = updatedModel.BulkLesson.CloseComment;
                                break;

                            case Enumerations.SaveAction.AssignToUser:
                                //selectedLesson.ValidatedBy = updatedModel.BulkLesson.AssignToUserId;
                                selectedLesson.AssignTo = updatedModel.BulkLesson.AssignToUserId;
                                break;
                            }

                            var result = lessonManager.SaveLesson(selectedLesson, userSessionContext.CurrentUser, comment, updatedModel.BulkLesson.SaveAction);

                            successLessons.Add(selectedLesson);

                            hasSuccesses = true;
                        }
                        else
                        {
                            foreach (var validationResult in validatedErrors)
                            {
                                errorMessages.Add(model.Id + ": " + validationResult.ErrorMessage);
                            }
                        }

                        //Send email notification
                        switch (updatedModel.BulkLesson.SaveAction)
                        {
                        case Enumerations.SaveAction.DraftToNew:
                            emailsToSend.AddRange(GenerateNotifications(successLessons, Enumerations.NotificationEmailType.N1_NewToAdmin));
                            break;

                        case Enumerations.SaveAction.AdminToClarification:
                            emailsToSend.AddRange(GenerateNotifications(successLessons, Enumerations.NotificationEmailType.N3_AdminToClarification));
                            break;

                        case Enumerations.SaveAction.AdminToBPO:
                        case Enumerations.SaveAction.BPOToBPO:
                        case Enumerations.SaveAction.ClosedToBPO:     //TODO: Validate this notification should be sent
                            emailsToSend.AddRange(GenerateNotifications(successLessons, Enumerations.NotificationEmailType.N2_AdminToBPO_And_BPOToBPO));
                            break;

                        case Enumerations.SaveAction.BPOToClarification:
                            emailsToSend.AddRange(GenerateNotifications(successLessons, Enumerations.NotificationEmailType.N5_BPOToClarification));
                            break;

                        case Enumerations.SaveAction.BPOToClose:
                            emailsToSend.AddRange(GenerateNotifications(successLessons, Enumerations.NotificationEmailType.N7_BPOToCloseLLC));
                            break;

                        case Enumerations.SaveAction.ClarificationToAdmin:
                            emailsToSend.AddRange(GenerateNotifications(successLessons, Enumerations.NotificationEmailType.N4_ClarificationToAdmin));
                            break;

                        case Enumerations.SaveAction.ClarificationToBPO:
                            emailsToSend.AddRange(GenerateNotifications(successLessons, Enumerations.NotificationEmailType.N6_ClarificationToBPO));
                            break;

                        case Enumerations.SaveAction.AssignToUser:
                            if (successLessons.Count > 0)
                            {
                                AssignLessonIds.Add(successLessons.First());
                            }
                            break;
                        }
                    }
                }

                if (AssignLessonIds.Count > 0)
                {
                    emailsToSend.AddRange(GenerateNotification(AssignLessonIds));
                }

                if (emailsToSend.Count > 0)
                {
                    LessonBusiness businessManager = new LessonBusiness(DbContext);
                    businessManager.SendEmails(emailsToSend);
                }
            }

            ModelState.Clear();

            if (errorMessages.Count > 0)
            {
                string message = hasSuccesses ? "Items have been saved, however the following Lessons could not be processed:" : "No Lessons could be processed.  The following errors occured:";
                errorMessages.Insert(0, message);

                foreach (var error in errorMessages)
                {
                    this.AddError(error);
                }
            }
            else if (hasSuccesses)
            {
                SetSuccessfulSave();
            }

            //Make sure to re-populate correctly if we came from a system initiated search back to MyLessons
            TempData["MyLessonModel"] = userSessionContext.LastSystemSearch;

            return(RedirectToActionPermanent("Index", new { pageAction = updatedModel.BulkLesson.ReturnToAction }));
        }