public IActionResult Delete(int courseId) { string userId = _userManager.GetUserId(HttpContext.User); try { if (_courseLogic.Delete(userId, courseId)) { return(RedirectToAction(nameof(Index), "Course")); } else { return(StatusCode(500)); } } catch (NotFoundException) { return(NotFound()); } catch (IllegalAccessException) { return(Challenge()); } }
public JsonResult DeleteCourse(long courseId) { JsonResponseModel result = new JsonResponseModel(); try { if (courseId > 0) { CourseLogic courseLogic = new CourseLogic(); EventLogic eventLogic = new EventLogic(); EVENT courseEvent = eventLogic.GetEntitiesBy(e => e.Course_Id == courseId).LastOrDefault(); if (courseEvent == null) { courseLogic.Delete(c => c.Id == courseId); result.IsError = false; result.Message = "Operation Successful!"; } else { result.IsError = true; result.Message = "Course is already attached to an event, hence cannot be deleted"; } } else { result.IsError = true; result.Message = "Invalid parameter"; } } catch (Exception ex) { result.IsError = true; result.Message = ex.Message; } return(Json(result, JsonRequestBehavior.AllowGet)); }
public IActionResult Delete([FromBody] Course course) { _courseLogic.Delete(course); return(Ok()); }