public IActionResult Post([FromBody] FacultyViewModel newFaculty) { bool result = repository.AddFaculty(newFaculty); if (result == true) { return(Ok()); } else { return(BadRequest()); } }
public HttpResponseMessage AddFaculty(FacultyModel facultyModel) { try { HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.Created) { Content = new StringContent(JsonConvert.SerializeObject(facultyRepository.AddFaculty(facultyModel))) }; return(hrm); } catch (Exception ex) { Errors errors = ErrorsHelper.GetErrors(ex); HttpResponseMessage hr = new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(errors.ToString()) }; return(hr); } }
public HttpResponseMessage AddFaculty(FacultyModel facultyModel) { try { if (facultyModel == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Data is null.")); } if (!ModelState.IsValid) { Errors errors = ErrorsHelper.GetErrors(ModelState); return(Request.CreateResponse(HttpStatusCode.BadRequest, errors)); } FacultyModel addedFaculty = facultyRepository.AddFaculty(facultyModel); return(Request.CreateResponse(HttpStatusCode.Created, addedFaculty)); } catch (Exception ex) { Errors errors = ErrorsHelper.GetErrors(ex); return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors)); } }
public IActionResult AddFaculty(FacultyModel facultyModel) { try { if (facultyModel == null) { return(BadRequest("Data is null.")); } if (!ModelState.IsValid) { Errors errors = ErrorsHelper.GetErrors(ModelState); return(BadRequest(errors)); } FacultyModel addedFaculty = facultyRepository.AddFaculty(facultyModel); return(StatusCode(StatusCodes.Status201Created, addedFaculty)); } catch (Exception ex) { Errors errors = ErrorsHelper.GetErrors(ex); return(StatusCode(StatusCodes.Status500InternalServerError, errors)); } }
private IEntityDTO AddFaculty(string facultyName, int universityID) => _facRep.AddFaculty(facultyName, universityID);