public async Task <IActionResult> PostCourse([FromBody] Course course) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _courseBusiness.Add(course); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (CourseExists(course.Id)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetCourse", new { id = course.Id }, course)); }
public ActionResult Create([Bind(Include = "CourseId,CourseName,CourseCode,Credit,Discription,DepartmentId,SemesterId")] Course course) { if (ModelState.IsValid) { if (!_courseBusiness.IsCourseNameEnrolled(course.CourseName, course.DepartmentId)) { if (!_courseBusiness.IsCourseCodeEnrolled(course.CourseCode, course.DepartmentId)) { _courseBusiness.Add(course); // return RedirectToAction("Index"); ViewBag.Message = "Course Created Successfully!"; } else { ViewBag.Message = "Course Already Exists In This Department!"; } } else { ViewBag.Message = "Course Already Exists In This Department!"; } } ViewBag.DepartmentId = new SelectList(_departmentBusiness.GetAll(), "DepartmentId", "DeptName"); ViewBag.SemesterId = new SelectList(_semesterBusiness.GetAll(), "SemesterId", "SemesterName"); return(View(course)); }