コード例 #1
0
        public IActionResult GetOpenLessonsChartData()
        {
            LessonBusiness     lessonManager      = new LessonBusiness(DbContext);
            UserSessionContext userSessionContext = new UserSessionContext(this.HttpContext);

            //Filter by lessons user owns.  For Admin, show all.
            var filter = new LessonFilters {
                ShowOnlyOwnedLessons = true
            };

            int unused      = 0;
            var userLessons = lessonManager.GetLessonsPaged(userSessionContext.CurrentUser, filter, false, 0, 0, out unused)
                              .Where(x => x.StatusId != (int)Enumerations.LessonStatus.MIGRATION && x.StatusId != (int)Enumerations.LessonStatus.Closed).ToList();

            var data = from l in userLessons
                       group l by l.Status into lessonsByStatus
                       select new
            {
                Label    = lessonsByStatus.Key.Name,
                Percent  = Math.Round((((double)lessonsByStatus.Count()) / userLessons.Count() * 100), 1),
                Count    = lessonsByStatus.Count(),
                StatusId = lessonsByStatus.Key.Id,
                Sort     = lessonsByStatus.Key.SortOrder
            };

            return(Json(data.OrderBy(x => x.Sort)));
        }
コード例 #2
0
        public IActionResult GetLessonCommentList(int id, DataTableParametersViewData gridData)
        {
            UserSessionContext userContext = new UserSessionContext(this.HttpContext);

            int pageIndex = (gridData.iDisplayStart / gridData.iDisplayLength) + 1;

            pageIndex = pageIndex <= 0 ? 0 : pageIndex - 1;
            var pageSize = gridData.iDisplayLength;
            int totalCount;

            LessonBusiness lessonBusinessManager = new LessonBusiness(DbContext);

            var comments = lessonBusinessManager.GetLessonComments(id, userContext.CurrentUser, userContext.CurrentUser.RoleId == (int)Enumerations.Role.Administrator, out totalCount);

            if (comments == null)
            {
                return(Json(null));
            }

            List <object> result = new List <object>();

            foreach (var comment in comments)
            {
                Dictionary <string, string> commentData = new Dictionary <string, string>();
                commentData.Add("Enabled", comment.Enabled.ToString());
                commentData.Add("Id", comment.Id.ToString());
                commentData.Add("Date", comment.CreateDate.ToDisplayDate());
                commentData.Add("User", HttpUtility.HtmlEncode(comment.CreateUser));
                commentData.Add("Type", comment.CommentType.Name + (comment.Enabled == true ? "" : " (Deleted)"));
                commentData.Add("Comment", HttpUtility.HtmlEncode(comment.Content));
                //@Url.Action("Delete", "Lesson", new { id = Model.Id }, "http")
                string buttonHtml = userContext.CurrentUser.RoleId == (int)Enumerations.Role.Administrator ?
                                    string.Format("<div><a href='#' class='{0}delete-comment float-left' data-url='{1}' data-commentType='{2}'><span class='float-left web-sprite sprite-{3}'></span>&nbsp;{0}Delete</a><div class='clear'></div></div>",
                                                  comment.Enabled == true ? "" : "Un-",
                                                  Url.Action((comment.Enabled == true ? "" : "Un") + "DeleteComment", "Lesson", new { id = comment.Id, lessonId = id }, "http"),
                                                  comment.CommentType.Name,
                                                  comment.Enabled == true ? "delete16" : "arrow-undo")
                    : "";
                commentData.Add("Actions", buttonHtml);

                var rawCommentData = (from c in commentData
                                      select c.Value).ToArray();

                result.Add(rawCommentData);
            }

            return(Json(
                       new
            {
                eEcho = gridData.sEcho,
                iTotalRecords = totalCount,
                iTotalDisplayRecords = totalCount,
                aaData = result
            }));
        }
コード例 #3
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);
        }
コード例 #4
0
        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());
        }
コード例 #5
0
        public IActionResult UnDeleteComment(int id, int lessonId)
        {
            try
            {
                UserSessionContext userSession   = new UserSessionContext(this.HttpContext);
                LessonBusiness     lessonManager = new LessonBusiness(DbContext);
                lessonManager.UnDeleteComment(id, userSession.CurrentUser);

                this.SetSuccessfulSave();
            }
            catch (Exception ex)
            {
                this.AddError(ex.Message);
            }

            return(RedirectToAction("Index", new { pageAction = Enumerations.PageAction.Edit, lessonId = lessonId }));
        }
コード例 #6
0
        public IActionResult UnDelete(int id)
        {
            try
            {
                UserSessionContext userSession   = new UserSessionContext(this.HttpContext);
                LessonBusiness     lessonManager = new LessonBusiness(DbContext);
                lessonManager.UnDeleteLesson(id, userSession.CurrentUser);

                this.ShowAlert("The lessons was successfully restored.", "sprite-accept");
            }
            catch (Exception ex)
            {
                this.AddError(ex.Message);
            }

            return(RedirectToAction("Index", new { pageAction = Enumerations.PageAction.Search }));
        }
コード例 #7
0
        private static void DoWork(object state)
        {
            try
            {
                var refreshAfterTime = new TimeSpan(Utility.SafeGetAppConfigSetting("SchedulerRefreshAfterHour", 1), 0, 0);

                Logger.Info("UserRefresh Service", "Checking if refresh is required...");
                Logger.Info("UserRefresh Service", string.Format("Last Refresh: {0}, Refresh at {1}:00 (24h)", _lastRefresh, refreshAfterTime.Hours));

                if (_lastRefresh == DateTime.MinValue ||
                    (_lastRefresh.Day != DateTime.Now.Day && //Make sure we only refresh once per day
                     DateTime.Now.TimeOfDay > refreshAfterTime))   //Only refresh after the specified time (1 AM by default)
                {
                    Logger.Info("UserRefresh Service", "Refresh required, refreshing user table...");

                    _lastRefresh = DateTime.Now;

                    /**********************************************************************************************
                     * Project: Cloud Surge Project
                     * Author: Rajib Sikdar
                     * Date: 14th April 2020
                     * Purpose: Need to check runtime error in future
                     * **********************************************************************************************/
                    LessonBusiness businessManager = new LessonBusiness();
                    businessManager.RefreshRoleUsersFromActiveDirectory();

                    Logger.Info("UserRefresh Service", "Refresh Completed.");
                }
                else
                {
                    Logger.Info("UserRefresh Service", "Refresh is not required.");
                }
            }
            catch (Exception ex)
            {
                Logger.Error("UserRefresh Service", ex.ToString());
            }
        }
コード例 #8
0
        private void InitializeUserSession(ActionExecutingContext filterContext)
        {
            Logger.Debug("Session_Start", "Begin");

            Logger.Debug("Session_Start", "var userSessionContext = new UserSessionContext(new HttpContextWrapper(HttpContext.Current));");

            var userSessionContext = new UserSessionContext(filterContext.HttpContext);

            Logger.Debug("Session_Start", "LessonBusiness businessManager = new LessonBusiness();");
            LessonBusiness businessManager = new LessonBusiness(_dbcontext);

            Logger.Debug("Session_Start", "userSessionContext.CurrentUser = businessManager.GetCurrentUser();");
            userSessionContext.CurrentUser = businessManager.GetCurrentUser();

            if (!string.IsNullOrWhiteSpace(Utility.SafeGetAppConfigSetting("Debug_UserPermission", "")))
            {
                Enumerations.Role debugPrivilege = (Enumerations.Role)Enum.Parse(typeof(Enumerations.Role), Utility.SafeGetAppConfigSetting("Debug_UserPermission", "User"));
                if (userSessionContext.CurrentUser == null)
                {
                    if (bool.Parse(Utility.SafeGetAppConfigSetting("Debug_PopulateFakeUsers", "false")))
                    {
                        userSessionContext.CurrentUser = new Data.RoleUser
                        {
                            LastName  = "User",
                            FirstName = "Debug",
                            Sid       = "S-1-5-21-861617734-1335137780-1834409622-8391"
                        };
                    }
                }

                if (userSessionContext.CurrentUser != null)
                {
                    userSessionContext.CurrentUser.RoleId = (int)debugPrivilege;
                }
            }
        }
コード例 #9
0
        public IActionResult Save(AdminViewData updatedModel)
        {
            ApplicationContext appContext = new ApplicationContext(this.Cache);

            if (ModelState.IsValid)
            {
                UserSessionContext userContext     = new UserSessionContext(this.HttpContext);
                LessonBusiness     businessManager = new LessonBusiness(DbContext);

                businessManager.SaveReferenceList(updatedModel.ReferenceValueEnabled, updatedModel.ReferenceValueDisabled, (Enumerations.ReferenceType)updatedModel.EditReferenceType, userContext.CurrentUser);
                businessManager.SaveDisciplineUserList(updatedModel.DisciplineUsers, updatedModel.PrimaryDisciplineUser, updatedModel.EditingDisciplineUsersReferenceValue, userContext.CurrentUser);
                businessManager.SavePrimaryAdminUser(updatedModel.PrimaryAdminUser, userContext.CurrentUser);

                //Update the cache
                appContext.AllUsers           = businessManager.GetAllUsers();
                appContext.AllReferenceValues = businessManager.GetAllReferenceValues();

                this.SetSuccessfulSave();

                return(RedirectToActionPermanent("Index"));
            }

            switch ((Enumerations.ReferenceType)updatedModel.EditReferenceType)
            {
            case Enumerations.ReferenceType.Project:
                updatedModel.EditingReferenceValueList = appContext.Projects;
                break;

            case Enumerations.ReferenceType.Phase:
                updatedModel.EditingReferenceValueList = appContext.Phases;
                break;

            case Enumerations.ReferenceType.Classification:
                updatedModel.EditingReferenceValueList = appContext.Classifications;
                break;

            case Enumerations.ReferenceType.Location:
                updatedModel.EditingReferenceValueList = appContext.Locations;
                break;

            case Enumerations.ReferenceType.ImpactBenefitRange:
                updatedModel.EditingReferenceValueList = appContext.ImpactBenefitRanges;
                break;

            case Enumerations.ReferenceType.CostImpact:
                updatedModel.EditingReferenceValueList = appContext.CostImpacts;
                break;

            case Enumerations.ReferenceType.RiskRanking:
                updatedModel.EditingReferenceValueList = appContext.RiskRankings;
                break;

            case Enumerations.ReferenceType.Discipline:
                updatedModel.EditingReferenceValueList = appContext.Disciplines;
                break;

            case Enumerations.ReferenceType.CredibilityChecklist:
                updatedModel.EditingReferenceValueList = appContext.CredibilityChecklists;
                break;

            case Enumerations.ReferenceType.LessonTypeValid:
                updatedModel.EditingReferenceValueList = appContext.LessonTypesValid;
                break;

            case Enumerations.ReferenceType.LessonTypeInvalid:
                updatedModel.EditingReferenceValueList = appContext.LessonTypesInvalid;
                break;

            case Enumerations.ReferenceType.Theme:
                updatedModel.EditingReferenceValueList = appContext.Themes;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            TempData["AdminData"] = updatedModel;

            return(Index());
        }
コード例 #10
0
        public IActionResult GetClosedLessonsChartData(int year, bool isValidSelected)
        {
            LessonBusiness     lessonManager      = new LessonBusiness(DbContext);
            UserSessionContext userSessionContext = new UserSessionContext(this.HttpContext);
            ApplicationContext appContext         = new ApplicationContext(this.Cache);

            int unused      = 0;
            var userLessons = lessonManager.GetLessonsPaged(userSessionContext.CurrentUser,
                                                            new LessonFilters
            {
                //Status = (int)Enumerations.LessonStatus.Closed
                SelectedStatus       = new List <int>(new int[] { (int)Enumerations.LessonStatus.Closed }),
                ShowOnlyOwnedLessons = userSessionContext.CurrentUser.RoleId != (int)Enumerations.Role.Administrator
            },
                                                            false, true, 0, 0, out unused);

            //Meaning "Pre-2010" was selected from the list, gatehr all lessons closed previous to Jan 1 2010
            if (year == 0)
            {
                userLessons = userLessons.Where(x => x.ClosedDate.HasValue && x.ClosedDate.Value.Year < 2010).ToList();
            }
            else
            {
                //Another valid year was selected
                userLessons = userLessons.Where(x => x.ClosedDate.HasValue && x.ClosedDate.Value.Year == year).ToList();
            }

            List <ReferenceValue> distinctLessonTypes = new List <ReferenceValue>();

            if (isValidSelected)
            {
                distinctLessonTypes = appContext.LessonTypesValid.Where(x => x.Enabled || userSessionContext.CurrentUser.RoleId == (int)Enumerations.Role.Administrator).Distinct().OrderBy(x => x.SortOrder).ToList();
            }
            else
            {
                distinctLessonTypes = appContext.LessonTypesInvalid.Where(x => x.Enabled || userSessionContext.CurrentUser.RoleId == (int)Enumerations.Role.Administrator).Distinct().OrderBy(x => x.SortOrder).ToList();
            }

            List <ClosedLessonType> closedLessonTypeData = new List <ClosedLessonType>();

            //Create a detail for each distinct lesson type
            foreach (var lessonType in distinctLessonTypes)
            {
                ClosedLessonType closedLessonType = new ClosedLessonType();
                closedLessonType.LessonTypeId   = lessonType.Id;
                closedLessonType.LessonTypeName = lessonType.Name;

                //Get the data for each Month
                for (int i = 1; i <= 12; i++)
                {
                    ClosedLessonTypeDetail month = new ClosedLessonTypeDetail
                    {
                        Count = userLessons.Where(x =>
                                                  (isValidSelected ? x.LessonTypeValidId : x.LessonTypeInvalidId) == lessonType.Id &&
                                                  x.ClosedDate.Value.Month == i).Count()
                    };

                    closedLessonType.Detail.Add(month);
                }

                closedLessonTypeData.Add(closedLessonType);
            }

            return(Json(closedLessonTypeData));
        }
コード例 #11
0
        public IActionResult ActionButtonBulk(List <int> selectedLessonIds)
        {
            List <SaveActionOption> options            = new List <SaveActionOption>();
            UserSessionContext      userSessionContext = new UserSessionContext(this.HttpContext);

            if (selectedLessonIds != null && selectedLessonIds.Count > 0)
            {
                bool adminRole = userSessionContext.CurrentUser.RoleId == (int)Enumerations.Role.Administrator;

                List <Lesson> selectedLessons = new List <Lesson>();

                if (userSessionContext.LastSearchResults != null)
                {
                    selectedLessons = userSessionContext.LastSearchResults.Where(x => selectedLessonIds.Contains(x.Id)).ToList();
                }
                else
                {
                    LessonBusiness lessonManager = new LessonBusiness(DbContext);
                    selectedLessons = lessonManager.GetLessons(selectedLessonIds, userSessionContext.CurrentUser);
                }

                if (selectedLessons.Select(x => x.DisciplineId).Distinct().Count() == 1)
                {
                    ViewBag.DisciplineId = selectedLessons.Select(x => x.DisciplineId).Distinct().First();
                }

                int  editableCount = selectedLessons.Where(x => Utils.IsLessonEditable(this.HttpContext, LessonViewModel.ToViewModel(HttpContext, x), userSessionContext.CurrentUser)).Count();
                bool allEditable   = editableCount == selectedLessons.Count();
                bool allReadOnly   = editableCount == 0;
                bool allEnabled    = !selectedLessons.Where(x => x.Enabled != true).Any();

                bool deleteAdded = false;
                if (allEnabled && adminRole)
                {
                    deleteAdded = true;
                    options.Add(new SaveActionOption {
                        ButtonText = "Delete Selected", IconClass = "sprite-delete16", SaveAction = Enumerations.SaveAction.Delete, SortOrder = 999
                    });
                }
                else if (allReadOnly && adminRole)
                {
                    options.Add(new SaveActionOption {
                        ButtonText = "Un-Delete Selected", IconClass = "sprite-arrow-undo", SaveAction = Enumerations.SaveAction.UnDelete
                    });
                }

                //Only show buttons if the selected items have the same status
                if (selectedLessons.Select(x => x.StatusId).Distinct().Count() == 1)
                {
                    var selectedLessonsStatus = (Enumerations.LessonStatus)selectedLessons.Select(x => x.StatusId).Distinct().First();
                    if (allEditable)
                    {
                        switch (selectedLessonsStatus)
                        {
                        case Enumerations.LessonStatus.MIGRATION:
                            options.Add(new SaveActionOption {
                                ButtonText = "Transfer Selected to Admin", IconClass = "sprite-arrow", SaveAction = Enumerations.SaveAction.NewToAdmin
                            });
                            break;

                        case Enumerations.LessonStatus.Draft:
                            options.Add(new SaveActionOption {
                                ButtonText = "Submit Selected", IconClass = "sprite-new", SaveAction = Enumerations.SaveAction.DraftToNew
                            });

                            if (!deleteAdded)
                            {
                                options.Add(new SaveActionOption {
                                    ButtonText = "Delete Selected", IconClass = "sprite-delete16", SaveAction = Enumerations.SaveAction.Delete, SortOrder = 999
                                });
                            }
                            break;

                        case Enumerations.LessonStatus.New:
                            options.Add(new SaveActionOption {
                                ButtonText = "Transfer Selected to Admin", IconClass = "sprite-arrow", SaveAction = Enumerations.SaveAction.NewToAdmin
                            });
                            break;

                        case Enumerations.LessonStatus.AdminReview:

                            options.Add(new SaveActionOption {
                                ButtonText = "Transfer Selected to BPO", IconClass = "sprite-arrow", SaveAction = Enumerations.SaveAction.AdminToBPO, SortOrder = 1
                            });
                            options.Add(new SaveActionOption {
                                ButtonText = "Request Clarification for Selected", IconClass = "sprite-note-error", SaveAction = Enumerations.SaveAction.AdminToClarification, SortOrder = 2
                            });
                            break;

                        case Enumerations.LessonStatus.Clarification:
                            options.Add(new SaveActionOption {
                                ButtonText = "Transfer Selected to Admin", IconClass = "sprite-arrow", SaveAction = Enumerations.SaveAction.ClarificationToAdmin, SortOrder = 1
                            });
                            options.Add(new SaveActionOption {
                                ButtonText = "Transfer Selected to BPO", IconClass = "sprite-arrow", SaveAction = Enumerations.SaveAction.ClarificationToBPO, SortOrder = 2
                            });
                            break;

                        case Enumerations.LessonStatus.BPOReview:

                            if (selectedLessons.Select(x => x.DisciplineId).Distinct().Count() == 1)
                            {
                                options.Add(new SaveActionOption {
                                    ButtonText = "Close Selected", IconClass = "sprite-accept", SaveAction = Enumerations.SaveAction.BPOToClose, SortOrder = 1
                                });
                            }

                            options.Add(new SaveActionOption {
                                ButtonText = "Transfer Selected to Another BPO", IconClass = "sprite-arrow", SaveAction = Enumerations.SaveAction.BPOToBPO, SortOrder = 2
                            });
                            options.Add(new SaveActionOption {
                                ButtonText = "Request Clarification for Selected", IconClass = "sprite-note-error", SaveAction = Enumerations.SaveAction.BPOToClarification, SortOrder = 3
                            });
                            options.Add(new SaveActionOption {
                                ButtonText = "Assign to User", IconClass = "sprite-note-error", SaveAction = Enumerations.SaveAction.AssignToUser, SortOrder = 4
                            });
                            break;
                        }
                    }
                }

                options.Add(new SaveActionOption {
                    ButtonText = "Action Log for Selected", IconClass = "sprite-script-edit", SaveAction = Enumerations.SaveAction.ActionLog, SortOrder = 98
                });
                options.Add(new SaveActionOption {
                    ButtonText = "Excel File for Selected", IconClass = "sprite-table-edit", SaveAction = Enumerations.SaveAction.CsvLog, SortOrder = 99
                });
            }

            if (userSessionContext.LastSearchResults != null && userSessionContext.LastSearchResults.Count > 0)
            {
                options.Add(new SaveActionOption {
                    ButtonText = "Action Log for All Results", IconClass = "sprite-script-edit", SaveAction = Enumerations.SaveAction.ActionLogAll, SortOrder = 98
                });
                options.Add(new SaveActionOption {
                    ButtonText = "Excel File for All Results", IconClass = "sprite-table-edit", SaveAction = Enumerations.SaveAction.CsvLogAll, SortOrder = 99
                });
            }

            if (options.Count > 0)
            {
                options = options.OrderBy(x => x.SortOrder).ToList();

                //Add "Menu" button (does not do anything, just causes all other options to be grouped in the drop down list)
                options.Insert(0, new SaveActionOption {
                    ButtonType = Web.ViewData.ButtonType.MainDropDown, ButtonText = "Menu", SaveAction = Enumerations.SaveAction.None
                });
            }

            return(PartialView("ActionButton", options));
        }
コード例 #12
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 }));
        }
コード例 #13
0
        public IActionResult Index(Enumerations.PageAction pageAction, int?lessonId)
        {
            UserSessionContext userContext = new UserSessionContext(this.HttpContext);

            var            lessonModel     = new LessonViewModel(this.HttpContext);
            LessonBusiness businessManager = new LessonBusiness(DbContext);

            SearchViewModel userSearch = new SearchViewModel();

            //Set Lesson List search based on page action
            switch (pageAction)
            {
            case Enumerations.PageAction.Submit:
                //Show only current user's draft lessons
                userSearch = new SearchViewModel {
                    OwnerSid = userContext.CurrentUser.Sid, Status = (int?)Enumerations.LessonStatus.Draft
                };
                break;

            case Enumerations.PageAction.Edit:
                //Show only editable lessons
                userSearch = new SearchViewModel {
                    ShowEditableOnly = true
                };
                break;

            case Enumerations.PageAction.Search:
                //Show the last search
                userSearch = userContext.LastSearch;
                break;

            case Enumerations.PageAction.MyLessons:
                //Show all owned lessons (or filtered lessons of comming from dashboard)
                userSearch = (SearchViewModel)TempData["MyLessonModel"] ?? new SearchViewModel {
                    ShowOnlyOwnedLessons = true
                };
                break;

            default:
                throw new ArgumentOutOfRangeException("pageAction");
            }

            if (TempData.ContainsKey("Lesson"))
            {
                //Existing lesson (Edit Validation)
                lessonModel = (LessonViewModel)TempData["Lesson"];
            }
            else if (lessonId.HasValue &&
                     (pageAction == Enumerations.PageAction.Edit || pageAction == Enumerations.PageAction.Submit))
            {
                //Existing Lesson (Edit Existing)
                var lesson = businessManager.GetLessonById(lessonId.Value);
                lessonModel = LessonViewModel.ToViewModel(this.HttpContext, lesson);

                if (!Utils.IsLessonVisible(lessonModel, userContext.CurrentUser))
                {
                    return(RedirectToAction("Search"));
                }
            }
            else
            {
                if (pageAction != Enumerations.PageAction.Edit)
                {
                    if (lessonId.HasValue)
                    {
                        //Submit with "Save Changes", leave on submit tab with the recently added lesson
                        var lesson = businessManager.GetLessonById(lessonId.Value);
                        lessonModel = LessonViewModel.ToViewModel(this.HttpContext, lesson);
                    }
                    else
                    {
                        //New Lesson (Submit)
                        lessonModel = userContext.DraftDefaults;
                    }
                }
                else
                {
                    int unused = 0;
                    //Edit / Review, set to first lesson in search list
                    var lesson = businessManager.GetLessonsPaged(userContext.CurrentUser, userSearch, false, true, 0, 1, out unused).FirstOrDefault();
                    lessonModel = LessonViewModel.ToViewModel(this.HttpContext, lesson);
                    if (lesson != null)
                    {
                        lessonId = lesson.Id;
                    }
                    else
                    {
                        ViewBag.NothingToEdit = true;
                    }
                }
            }

            lessonModel.ReturnToAction = pageAction;

            var submittedUsers = businessManager.GetSubmittedByUsers();

            ViewBag.SubmittedByUsers = submittedUsers;

            userContext.LastSystemSearch = userSearch;

            LessonIndexViewModel model = new LessonIndexViewModel(this.HttpContext)
            {
                PageAction  = pageAction,
                LessonId    = lessonId,
                Lesson      = lessonModel,
                SearchModel = userSearch
            };

            return(View("Index", model));
        }
コード例 #14
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));
        }
コード例 #15
0
        public IActionResult GetLessonList(DataTableParametersViewData gridData)
        {
            UserSessionContext userContext = new UserSessionContext(this.HttpContext);

            //Ensure iDisplayLength never causes a divide by zero exception
            gridData.iDisplayLength = (gridData.iDisplayLength == 0) ? 10 : gridData.iDisplayLength;

            int pageIndex = (gridData.iDisplayStart / gridData.iDisplayLength) + 1;

            pageIndex = pageIndex <= 0 ? 0 : pageIndex - 1;
            var pageSize   = gridData.iDisplayLength;
            int totalCount = 0;

            LessonBusiness lessonBusinessManager = new LessonBusiness(DbContext);

            string gridMessage = "";

            switch (gridData.NavigationPage)
            {
            case Enumerations.NavigationPage.Review:
            case Enumerations.NavigationPage.Edit:
            case Enumerations.NavigationPage.Validate:
                gridMessage = "Lessons Requiring Action";
                break;

            case Enumerations.NavigationPage.MyLessons:
                gridMessage = "My Lessons";
                //if (gridData.SearchModel.Status.HasValue)//TODO: Add logic for multiple options
                //{
                //    gridMessage = "My " + Utility.StringValue((Enumerations.LessonStatus)gridData.SearchModel.Status.Value) + " Lessons";
                //}
                if (gridData.SearchModel.SelectedStatus != null && gridData.SearchModel.SelectedStatus.Count > 0)   //TODO: Add logic for multiple options
                {
                    string StatusList = "";
                    foreach (int StatusID in gridData.SearchModel.SelectedStatus)
                    {
                        StatusList += Utility.StringValue((Enumerations.LessonStatus)StatusID);
                        StatusList += ", ";
                    }
                    gridMessage = "My " + StatusList + " Lessons";
                }
                break;

            case Enumerations.NavigationPage.Search:
                gridMessage = "Filtered Search Results";
                break;

            case Enumerations.NavigationPage.Submit:
                gridMessage = "My Draft Lessons";
                break;
            }

            List <Lesson> lessons = null;

            if (!gridData.SearchModel.Blank)
            {
                List <SortColumn> sortColumns = null;

                if (gridData.iSortingCols > 0)
                {
                    sortColumns = new List <SortColumn>();

                    if (gridData.iSortingCols > 5)
                    {
                        sortColumns.Add(new SortColumn {
                            Column = (Enumerations.LessonListSortColumn)gridData.iSortCol_5, Direction = gridData.sSortDir_5 == "asc" ? Enumerations.SortDirection.Ascending : Enumerations.SortDirection.Descending, SortOrder = 6
                        });
                    }

                    if (gridData.iSortingCols > 4)
                    {
                        sortColumns.Add(new SortColumn {
                            Column = (Enumerations.LessonListSortColumn)gridData.iSortCol_4, Direction = gridData.sSortDir_4 == "asc" ? Enumerations.SortDirection.Ascending : Enumerations.SortDirection.Descending, SortOrder = 5
                        });
                    }

                    if (gridData.iSortingCols > 3)
                    {
                        sortColumns.Add(new SortColumn {
                            Column = (Enumerations.LessonListSortColumn)gridData.iSortCol_3, Direction = gridData.sSortDir_3 == "asc" ? Enumerations.SortDirection.Ascending : Enumerations.SortDirection.Descending, SortOrder = 4
                        });
                    }

                    if (gridData.iSortingCols > 2)
                    {
                        sortColumns.Add(new SortColumn {
                            Column = (Enumerations.LessonListSortColumn)gridData.iSortCol_2, Direction = gridData.sSortDir_2 == "asc" ? Enumerations.SortDirection.Ascending : Enumerations.SortDirection.Descending, SortOrder = 3
                        });
                    }

                    if (gridData.iSortingCols > 1)
                    {
                        sortColumns.Add(new SortColumn {
                            Column = (Enumerations.LessonListSortColumn)gridData.iSortCol_1, Direction = gridData.sSortDir_1 == "asc" ? Enumerations.SortDirection.Ascending : Enumerations.SortDirection.Descending, SortOrder = 2
                        });
                    }

                    sortColumns.Add(new SortColumn {
                        Column = (Enumerations.LessonListSortColumn)gridData.iSortCol_0, Direction = gridData.sSortDir_0 == "asc" ? Enumerations.SortDirection.Ascending : Enumerations.SortDirection.Descending, SortOrder = 1
                    });
                }

                lessons = lessonBusinessManager.GetLessonsPaged(sortColumns, userContext.CurrentUser, gridData.SearchModel, false, true, pageIndex, pageSize, out totalCount);
            }

            userContext.LastSearchResults = lessons;

            List <object> result = new List <object>();

            if (lessons != null)
            {
                foreach (var lesson in lessons)
                {
                    Dictionary <string, string> lessonData = new Dictionary <string, string>();
                    lessonData.Add("Enabled", lesson.Enabled.ToString());
                    lessonData.Add("Selected", false.ToString());
                    lessonData.Add("Id", lesson.Id.ToString());
                    lessonData.Add("Status", lesson.Status.Name + (lesson.Enabled == true ? "" : " (Deleted)"));
                    lessonData.Add("Title", HttpUtility.HtmlEncode(lesson.Title));
                    lessonData.Add("Discipline", lesson.Discipline == null ? "" : HttpUtility.HtmlEncode(lesson.Discipline.Name));
                    lessonData.Add("SubmitDate", lesson.SubmittedDate.HasValue ? lesson.SubmittedDate.Value.ToShortDateString() : "");
                    lessonData.Add("Contact", HttpUtility.HtmlEncode(Utility.ContactToDisplayString(lesson.ContactLastName, lesson.ContactFirstName)));
                    string buttonHtml = Utils.RenderPartialViewToString(this, "GridButton", LessonViewModel.ToViewModel(this.HttpContext, lesson));
                    lessonData.Add("Actions", buttonHtml);
                    lessonData.Add("LessonId", lesson.Id.ToString());
                    lessonData.Add("StatusId", lesson.StatusId.ToString());

                    var rawLessonData = (from l in lessonData
                                         select l.Value).ToArray();

                    result.Add(rawLessonData);
                }
            }

            return(Json(
                       new
            {
                eEcho = gridData.sEcho,
                iTotalRecords = totalCount,
                iTotalDisplayRecords = totalCount,
                aaData = result,
                gridMessage = gridMessage
            }));
        }