Exemplo n.º 1
0
        public IActionResult Build(BuildViewModel Model)
        {
            // Check if the model is valid
            if (!ModelState.IsValid)
            {
                Model.createdWork = new CreatedWork()
                {
                    SelectFromList = DatabaseConnector.GetWorkset(Model.WorkSetID).ExamStyle,
                    CatagoryTypes  = GetAllQuestions()
                };
                return(View(Model));
            }

            // Delete any work that may already exist for that workset
            DatabaseConnector.DeleteWork(Model.WorkSetID);

            // Add each piece of work to the database
            foreach (var work in Model.Work)
            {
                DatabaseConnector.AddWork(new Work()
                {
                    Difficulty   = 1,
                    QuestionType = work.TypeID,
                    Seed         = work.Seed,
                    WorkSetID    = Model.WorkSetID
                });
            }
            // Commit any changes to the database
            DatabaseConnector.PushChanges();

            return(Redirect("~/Work/Set"));
        }