Пример #1
0
        public IActionResult Update(StudentCRUDViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Crud", model));
            }

            model.Student.Education = educationRepo.Educations.FirstOrDefault(e => e.Name == model.Student.Education.Name);
            studentRepo.Update(model.Student);

            return(View("Overview", studentRepo.Students));
        }
Пример #2
0
        public IActionResult Create(StudentCRUDViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.GenerateModel(educationRepo.Educations.ToList());
                ViewBag.crud = "create";

                return(View("Crud", model));
            }

            model.Student.Education = educationRepo.Educations.FirstOrDefault(e => e.Name == model.Student.Education.Name);
            studentRepo.Create(model.Student);
            SaveSession(model?.Student?.Education?.Name, model.Student.Semester);

            return(View("Overview", studentRepo.Students));
        }
Пример #3
0
        public IActionResult Crud(string crud, long studentId)
        {
            ViewBag.crud = crud;
            StudentCRUDViewModel model = new StudentCRUDViewModel();

            model.GenerateModel(educationRepo.Educations.ToList());
            model.Student.Education.Name = HttpContext.Session.GetString("Education");
            model.Student.Semester       = (int)HttpContext.Session.GetInt32("Semester");

            if (crud == "edit")
            {
                foreach (Student s in studentRepo.Students)
                {
                    if (studentId == s.StudentId)
                    {
                        model.Student = s;
                    }
                }
            }

            return(View("Crud", model));
        }