Exemple #1
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 }));
        }
Exemple #2
0
        private IActionResult Save(LessonViewModel updatedModel)
        {
            if (ModelState.IsValid)
            {
                if (!updatedModel.IsLessonTypeValidSelected)
                {
                    updatedModel.LessonTypeValidId = null;
                }

                UserSessionContext userContext = new UserSessionContext(this.HttpContext);
                ApplicationContext appContext  = new ApplicationContext(this.HttpContext);

                //Populate the Coordinator
                if (!string.IsNullOrWhiteSpace(updatedModel.CoordinatorOwnerSid))
                {
                    if (updatedModel.CoordinatorOwnerSid == Constants.TextDefaults.LLCListPrimaryAdminLabel)
                    {
                        updatedModel.Coordinator = Constants.TextDefaults.LLCListPrimaryAdminLabel;
                    }
                    else
                    {
                        updatedModel.Coordinator = appContext.Coordinators.Where(x => x.Sid == updatedModel.CoordinatorOwnerSid).First().Name;
                    }
                }

                LessonBusiness lessonManager = new LessonBusiness(DbContext);

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

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

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

                var dataModel = updatedModel.ToDataModel();

                var result = lessonManager.SaveLesson(dataModel, userContext.CurrentUser, comment, updatedModel.SaveAction);

                //Send email notification                switch (updatedModel.SaveAction)
                switch (updatedModel.SaveAction)
                {
                case Enumerations.SaveAction.DraftToNew:
                    SendNotification(result, Enumerations.NotificationEmailType.N1_NewToAdmin);
                    break;

                case Enumerations.SaveAction.AdminToClarification:
                    SendNotification(result, Enumerations.NotificationEmailType.N3_AdminToClarification);
                    break;

                case Enumerations.SaveAction.AdminToBPO:
                case Enumerations.SaveAction.BPOToBPO:
                case Enumerations.SaveAction.ClosedToBPO:     //TODO: Validate this notification should be sent
                    SendNotification(result, Enumerations.NotificationEmailType.N2_AdminToBPO_And_BPOToBPO);
                    break;

                case Enumerations.SaveAction.BPOToClarification:
                    SendNotification(result, Enumerations.NotificationEmailType.N5_BPOToClarification);
                    break;

                case Enumerations.SaveAction.BPOToClose:
                    SendNotification(result, Enumerations.NotificationEmailType.N7_BPOToCloseLLC);
                    if (result.OwnerSid != result.CoordinatorOwnerSid)
                    {
                        SendNotification(result, Enumerations.NotificationEmailType.N7_BPOToCloseOwner);
                    }
                    break;

                case Enumerations.SaveAction.ClarificationToAdmin:
                    SendNotification(result, Enumerations.NotificationEmailType.N4_ClarificationToAdmin);
                    break;

                case Enumerations.SaveAction.ClarificationToBPO:
                    SendNotification(result, Enumerations.NotificationEmailType.N6_ClarificationToBPO);
                    break;

                case Enumerations.SaveAction.AssignToUser:
                    SendNotification(result, Enumerations.NotificationEmailType.N10_AssignToUser);
                    break;
                }

                if (updatedModel.SaveAction == Enumerations.SaveAction.DraftToNew)
                {
                    //Issue 88 - Show a different save message when submiting
                    this.ShowAlert("The lesson has successfully been submitted for validation.", "sprite-accept");
                }
                else
                {
                    SetSuccessfulSave();
                }

                if (updatedModel.SaveAction == Enumerations.SaveAction.SaveDraft)
                {
                    return(RedirectToActionPermanent("Index", new { pageAction = Enumerations.PageAction.Submit }));
                }

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

            TempData["Lesson"] = updatedModel;

            var pageAction = Enumerations.PageAction.Edit;

            if (updatedModel.Status == Enumerations.LessonStatus.Draft)
            {
                pageAction = Enumerations.PageAction.Submit;
            }

            return(Index(pageAction, updatedModel.Id));
        }