Пример #1
0
        public IActionResult ActionButton(Enumerations.PageAction pageAction, Enumerations.LessonStatus lessonStatus, bool readOnly, bool lessonEnabled)
        {
            UserSessionContext      userSessionContext = new UserSessionContext(this.HttpContext);
            List <SaveActionOption> options            = new List <SaveActionOption>();

            string buttonText = "";

            switch (pageAction)
            {
            case Enumerations.PageAction.Submit:
                if (!readOnly && lessonStatus == Enumerations.LessonStatus.Draft)
                {
                    options.Add(new SaveActionOption {
                        ButtonType = ButtonType.MainDropDown, ButtonText = "Save", IconClass = "sprite-disk", SaveAction = Enumerations.SaveAction.SaveChanges
                    });
                    options.Add(new SaveActionOption {
                        ButtonType = ButtonType.SecondaryAction, ButtonText = "Submit", IconClass = "sprite-new", SaveAction = Enumerations.SaveAction.DraftToNew
                    });
                    options.Add(new SaveActionOption {
                        ButtonText = "Save Draft & Add Another Lesson", IconClass = "sprite-report-disk", SaveAction = Enumerations.SaveAction.SaveDraft
                    });
                }
                else
                {
                    options.Add(new SaveActionOption {
                        ButtonType = ButtonType.MainDropDown, ButtonText = "Submit Another", IconClass = "sprite-add", SaveAction = Enumerations.SaveAction.SubmitAnother
                    });
                }
                break;

            case Enumerations.PageAction.Edit:
                if (readOnly && !lessonEnabled && userSessionContext.CurrentUser.RoleId == (int)Enumerations.Role.Administrator)
                {
                    options.Add(new SaveActionOption {
                        ButtonType = ButtonType.MainDropDown, ButtonText = "Un-Delete", IconClass = "sprite-arrow-undo", SaveAction = Enumerations.SaveAction.UnDelete
                    });
                }

                if (!readOnly)
                {
                    switch (lessonStatus)
                    {
                    case Enumerations.LessonStatus.MIGRATION:
                        options.Add(new SaveActionOption {
                            ButtonType = ButtonType.MainDropDown, ButtonText = "Save", IconClass = "sprite-disk", SaveAction = Enumerations.SaveAction.SaveChanges
                        });
                        options.Add(new SaveActionOption {
                            ButtonText = "Transfer to Admin", IconClass = "sprite-arrow", SaveAction = Enumerations.SaveAction.NewToAdmin
                        });
                        break;

                    case Enumerations.LessonStatus.Draft:
                        options.Add(new SaveActionOption {
                            ButtonType = ButtonType.MainDropDown, ButtonText = "Save", IconClass = "sprite-disk", SaveAction = Enumerations.SaveAction.SaveChanges
                        });
                        options.Add(new SaveActionOption {
                            ButtonText = "Submit", IconClass = "sprite-new", SaveAction = Enumerations.SaveAction.DraftToNew
                        });
                        break;

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

                    case Enumerations.LessonStatus.AdminReview:
                        options.Add(new SaveActionOption {
                            ButtonType = ButtonType.MainDropDown, ButtonText = "Save", IconClass = "sprite-disk", SaveAction = Enumerations.SaveAction.SaveChanges
                        });
                        options.Add(new SaveActionOption {
                            ButtonText = "Transfer to BPO", IconClass = "sprite-arrow", SaveAction = Enumerations.SaveAction.AdminToBPO
                        });
                        options.Add(new SaveActionOption {
                            ButtonText = "Request Clarification", IconClass = "sprite-note-error", SaveAction = Enumerations.SaveAction.AdminToClarification
                        });
                        break;

                    case Enumerations.LessonStatus.Clarification:
                        options.Add(new SaveActionOption {
                            ButtonType = ButtonType.MainDropDown, ButtonText = "Save", IconClass = "sprite-disk", SaveAction = Enumerations.SaveAction.SaveChanges
                        });
                        options.Add(new SaveActionOption {
                            ButtonText = "Clarify and Transfer to Admin", IconClass = "sprite-arrow", SaveAction = Enumerations.SaveAction.ClarificationToAdmin
                        });
                        options.Add(new SaveActionOption {
                            ButtonText = "Clarify and Transfer to BPO", IconClass = "sprite-arrow", SaveAction = Enumerations.SaveAction.ClarificationToBPO
                        });
                        break;

                    case Enumerations.LessonStatus.BPOReview:
                        options.Add(new SaveActionOption {
                            ButtonType = ButtonType.MainDropDown, ButtonText = "Save", IconClass = "sprite-disk", SaveAction = Enumerations.SaveAction.SaveChanges
                        });
                        options.Add(new SaveActionOption {
                            ButtonText = "Close", IconClass = "sprite-accept", SaveAction = Enumerations.SaveAction.BPOToClose
                        });
                        options.Add(new SaveActionOption {
                            ButtonText = "Transfer to Another BPO", IconClass = "sprite-arrow", SaveAction = Enumerations.SaveAction.BPOToBPO
                        });
                        options.Add(new SaveActionOption {
                            ButtonText = "Request Clarification", IconClass = "sprite-note-error", SaveAction = Enumerations.SaveAction.BPOToClarification
                        });
                        options.Add(new SaveActionOption {
                            ButtonText = "Assign to User", IconClass = "sprite-note-error", SaveAction = Enumerations.SaveAction.AssignToUser
                        });
                        break;

                    case Enumerations.LessonStatus.Closed:
                        if (userSessionContext.CurrentUser.RoleId == (int)Enumerations.Role.Administrator && lessonEnabled)
                        {
                            options.Add(new SaveActionOption {
                                ButtonType = ButtonType.MainDropDown, ButtonText = "Save", IconClass = "sprite-disk", SaveAction = Enumerations.SaveAction.SaveChanges
                            });
                            options.Add(new SaveActionOption {
                                ButtonText = "Return to BPO Review", IconClass = "sprite-arrow-180", SaveAction = Enumerations.SaveAction.ClosedToBPO
                            });
                        }
                        break;
                    }

                    if (lessonEnabled && userSessionContext.CurrentUser.RoleId == (int)Enumerations.Role.Administrator)
                    {
                        options.Add(new SaveActionOption {
                            ButtonText = "Delete", IconClass = "sprite-delete16", SaveAction = Enumerations.SaveAction.Delete
                        });
                    }
                }
                break;

            case Enumerations.PageAction.Search:
                options.Add(new SaveActionOption {
                    ButtonType = ButtonType.MainDropDown, ButtonText = "Search", IconClass = "sprite-find"
                });
                options.Add(new SaveActionOption {
                    ButtonText = "Clear Search Results", IconClass = "sprite-page-find"
                });
                break;
            }

            return(PartialView(options));
        }
Пример #2
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));
        }