Пример #1
0
        public IActionResult CreateTeaches(string cid, string iid, string semester)
        {
            //check if primary key is already exists
            var cidkey    = _gradeDbContext.Teaches.FirstOrDefault(i => i.CourseId.Equals(cid, System.StringComparison.InvariantCultureIgnoreCase));
            var courseKey = _gradeDbContext.Course.FirstOrDefault(i => i.CourseId.Equals(cid, System.StringComparison.InvariantCultureIgnoreCase));
            var instKey   = _gradeDbContext.Instructor.FirstOrDefault(i => i.InstructorId.Equals(iid, System.StringComparison.InvariantCultureIgnoreCase));

            //We need the courseid NOT TO BE in teaches table --> cidkey
            //We need the courseid to BE in course table      --> courseKeyz
            //We need the instructorId to be in instr table   --> instKey
            if (cidkey == null && courseKey != null && instKey != null)
            {
                _gradeDbContext.Add(new TeachesModel
                {
                    CourseId     = cid,
                    InstructorId = iid,
                    Semester     = semester
                });

                _gradeDbContext.SaveChanges();
                _gradeDbContext.Dispose();
                return(RedirectToAction("Index"));
            }
            else
            {
                return(BadRequest($"Cannot insert teaches:{cid} already exists, instructor id {iid} or course id {cid} is not created!"));
            }
        }
Пример #2
0
        public IActionResult CreateCourse(string id, string title, ushort hours)
        {
            //check if primary key is already exists
            var key = _gradeDbContext.Course.FirstOrDefault(i => i.CourseId.Equals(id, System.StringComparison.InvariantCultureIgnoreCase));

            if (key == null)
            {
                _gradeDbContext.Add(new CourseModel
                {
                    CourseId    = id,
                    Title       = title,
                    CreditHours = hours
                });

                _gradeDbContext.SaveChanges();
                _gradeDbContext.Dispose();
                return(RedirectToAction("Index"));
            }
            else
            {
                return(BadRequest($"Cannot insert course: {id} already exists"));
            }
        }
Пример #3
0
        public IActionResult CreateInstructor(string id, string name, string department)
        {
            //check if primary key is already exists
            var key = _gradeDbContext.Instructor.FirstOrDefault(i => i.InstructorId.Equals(id, System.StringComparison.InvariantCultureIgnoreCase));

            if (key == null)
            {
                _gradeDbContext.Add(new InstructorModel
                {
                    InstructorId   = id,
                    InstructorName = name,
                    Department     = department
                });

                _gradeDbContext.SaveChanges();
                _gradeDbContext.Dispose();
                return(RedirectToAction("Index"));
            }
            else
            {
                return(BadRequest($"Cannot insert instructor: {id} already exists"));
            }
        }