Пример #1
0
        private bool IsKeyValid(UpdateMarkModel model)
        {
            // check for student
            if (!_exist.StudentExists(model.StudentID))
            {
                resp.code = 404; // Not found
                resp.messages.Add("Student not found");
            }

            // check for subject
            if (!_exist.SubjectExists(model.SubjectID))
            {
                resp.code = 404; // Not found
                resp.messages.Add("Subject not found");
            }

            // check for semester
            if (!_exist.SemesterExists(model.SemesterID))
            {
                resp.code = 404; // Not found
                resp.messages.Add("Semester not found");
            }

            // check for result type
            if (!_exist.ResultTypeExists(model.ResultTypeID))
            {
                resp.code = 404; // Not found
                resp.messages.Add("Result Type not found");
            }

            return(true);
        }
        public ActionResult CreateNewYear(int year)
        {
            if (year != 0)
            {
                // semester 1
                Semester semester1 = new Semester()
                {
                    Label = 1,
                    Year  = year
                };

                // if exist -> do nothing
                if (!_exist.SemesterExists(semester1.Label, semester1.Year))
                {
                    _semesterService.CreateSemester(semester1);
                }
                else
                {
                    resp.code = 400; // Bad request
                    resp.messages.Add(new { year = "Semester already exist" });
                    return(BadRequest(resp));
                }

                // semester 2
                Semester semester2 = new Semester()
                {
                    Label = 2,
                    Year  = year
                };

                // if exist -> do nothing
                if (!_exist.SemesterExists(semester2.Label, semester2.Year))
                {
                    _semesterService.CreateSemester(semester2);
                }
                else
                {
                    resp.code = 400; // Bad request
                    resp.messages.Add(new { year = "Semester already exist" });
                    return(BadRequest(resp));
                }
            }

            return(Ok());
        }