Пример #1
0
        public IActionResult Create(CreateSetViewModel model)
        {
            // Checks that valid model has been returned
            if (!ModelState.IsValid)
            {
                model.Groups = UserHelper.GetGroups(UserHelper.GetUserId(HttpContext.Session));
                return(View(model));
            }

            // Creates the workset from the given information
            Worksets sets = new Worksets()
            {
                GroupID        = model.GroupID,
                WorksetName    = model.WorksetName,
                SetBy          = UserHelper.GetUserId(HttpContext.Session),
                Time_Allowed   = model.TimeAllowed,
                Date_Set       = DateTime.Now.Date,
                SetType        = model.SetType,
                Date_Due       = model.Date_Due,
                ExamStyle      = model.SelectFromList,
                RandomOrdering = model.RandomQuestions
            };

            // Checks if the workset should have no group because it was saved for later
            if (sets.GroupID == -2)
            {
                sets.GroupID = null;
            }

            // Adds the workset to the database and gets its ID
            sets.WorksetID = DatabaseConnector.AddWorkset(sets);

            // Creates the model that nit used to build the workset
            var Model = new BuildViewModel()
            {
                WorkSetID   = sets.WorksetID,
                createdWork = new CreatedWork()
                {
                    SelectFromList = sets.ExamStyle,
                    CatagoryTypes  = GetAllQuestions()
                }
            };

            return(View("Build", Model));
        }