Esempio n. 1
0
        public IActionResult AddGrade(GradeModel model)
        {
            if (ModelState.IsValid)
            {
                StudentModel student = StudentManager.GetByNameAndSurname(model.Name, model.Surname).ToModel();

                if (student == null)
                {
                    ModelState.AddModelError("pass", "In list of students don't exists student with this name and surname!");
                }
                else
                {
                    SubjectModel subject = SubjectManager.GetBySubjectName(model.SubjectName).ToModel();

                    if (subject == null)
                    {
                        ModelState.AddModelError("pass", "In list of subjects don't exists subject with this name!");
                    }
                    else
                    {
                        var grade = GradeManager.GetByGradesInterval1To10().ToList();

                        if (grade != null)
                        {
                            ModelState.AddModelError("pass", "The grade aren't in interval 1 to 10!");
                        }
                        else
                        {
                            GradeManager.AddNewGrade(model.Name, model.Surname, model.SubjectName, model.Grade, model.Description);

                            return(RedirectToAction(nameof(GradeIndex)));
                        }
                    }
                }
            }

            return(View(model));
        }