示例#1
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));
        }