Exemple #1
0
        public ActionResult Choose(FormCollection formCollection)
        {
            if (!Init(User))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (!_isStudent)
            {
                return(RedirectToAction("Menu", "Home"));
            }

            Student studentDb = _studentRepository.GetById(_student.Id);

            _studentRepository.RemoveCategory(studentDb);
            studentDb.Categories = new List <StudentCategory>();

            List <string> allCategory = _categoryRepository.GetAll().Select(c => c.Name).ToList();

            foreach (string category in allCategory)
            {
                string c = formCollection[category];
                if (c.StartsWith("true"))
                {
                    StudentCategory studentCategoryDb = new StudentCategory()
                    {
                        CategoryId = _categoryRepository.GetByName(category).Id,
                        StudentId  = _student.Id
                    };
                    studentDb.Categories.Add(studentCategoryDb);
                }
            }
            _studentRepository.AddCategory(studentDb);

            return(RedirectToAction("Menu", "Home"));
        }