public JsonResult Delete(int id) { var matchingNurs = User.FindAll("Nursery").FirstOrDefault(claim => claim.Value == _repository.GetClassNurseryId(id).ToString()); if (User.IsInRole("Admin") || matchingNurs != null) { _repository.DeleteClass(id); return(Json(new { Message = "Deleted" })); } else { Response.StatusCode = (int)HttpStatusCode.Unauthorized; return(Json("Unauthorized to delete this class")); } }