public IActionResult CreateCourseCampusForApplication(int applicationId, [FromBody] IEnumerable <CourseCampusForApplicationCreationDto> courseCampusesForApplication) { if (courseCampusesForApplication == null) { return(NotFound()); } if (!ModelState.IsValid) { //return BadRequest(); // return 422 // Custom Error Handler => returns the Key Value pair Error of the specific property /* * Use Case 1 by following CourseCampusForApplicationManipulationDto Validation Rules:- * Request Body => * [ * { * "CourseCampusId": 0, * "IsPrimaryLocation" : true * }, * { * "CourseCampusId": 619, * "IsPrimaryLocation" : true * } * ] * Response => * { * "[0].CourseCampusId": [ * "Please provide valid value for CourseCampusId between 1 to 1000000" * ] * } */ return(new UnprocessableEntityObjectResult(ModelState)); } if (!_applicationInfoRepository.ApplicationExists(applicationId)) { return(NotFound()); } foreach (CourseCampusForApplicationCreationDto courseCampusForApplication in courseCampusesForApplication) { var acc = Mapper.Map <Entities.ApplicationCourseCampus>(courseCampusForApplication); if (!_applicationInfoRepository.CourseCampusExists(acc.CourseCampusId)) { return(NotFound()); } else { _applicationInfoRepository.AddCourseCampusForApplication( applicationId, acc //cc.CourseCampus //_applicationInfoRepository.GetCourseCampus(cc.CourseCampusId) ); } } if (!_applicationInfoRepository.Save()) { return(StatusCode(500, "A problem happened while handling your request.")); } #region Only to Add Etags to each CourseCampusesForApplication otherwise Do Not Send Content After Post // CREATE ETAGS FOR POST AS WELL, NO DID HERE BEVAUSE POST SHOULD RETURN ON 1 APPLICATIONCOURSECAMPUS, SO THAT ETAG COULD BE ADDED TO RESPONSE OF EACH RETURNED OBJECT. THIS IS BECAUSE COLLECTION/IEnumerable DOES NOT NEED AN ETAG. // CREATE ETAGS FOR POST AS WELL, NO DID HERE BEVAUSE POST SHOULD RETURN ON 1 APPLICATIONCOURSECAMPUS, SO THAT ETAG COULD BE ADDED TO RESPONSE OF EACH RETURNED OBJECT. THIS IS BECAUSE COLLECTION/IEnumerable DOES NOT NEED AN ETAG. // CREATE ETAGS FOR POST AS WELL, NO DID HERE BEVAUSE POST SHOULD RETURN ON 1 APPLICATIONCOURSECAMPUS, SO THAT ETAG COULD BE ADDED TO RESPONSE OF EACH RETURNED OBJECT. THIS IS BECAUSE COLLECTION/IEnumerable DOES NOT NEED AN ETAG. // CREATE ETAGS FOR POST AS WELL, NO DID HERE BEVAUSE POST SHOULD RETURN ON 1 APPLICATIONCOURSECAMPUS, SO THAT ETAG COULD BE ADDED TO RESPONSE OF EACH RETURNED OBJECT. THIS IS BECAUSE COLLECTION/IEnumerable DOES NOT NEED AN ETAG. // CREATE ETAGS FOR POST AS WELL, NO DID HERE BEVAUSE POST SHOULD RETURN ON 1 APPLICATIONCOURSECAMPUS, SO THAT ETAG COULD BE ADDED TO RESPONSE OF EACH RETURNED OBJECT. THIS IS BECAUSE COLLECTION/IEnumerable DOES NOT NEED AN ETAG. //foreach (CourseCampusForApplicationCreationDto courseCampusForApplication in courseCampusesForApplication) //{ // AddETagForPost(_applicationInfoRepository.GetCourseCampusForApplicationByProvidingApplicationIdAndCourseCampusId( // applicationId, // courseCampusForApplication.CourseCampusId // ) // ); //} #endregion return(Ok()); }
public IActionResult CreateCourseCampusForApplication(int applicationId, [FromBody] IEnumerable <CourseCampusForApplicationCreationDto> courseCampusesForApplication) { if (courseCampusesForApplication == null) { return(NotFound()); } if (!ModelState.IsValid) { //return BadRequest(); // return 422 // Custom Error Handler => returns the Key Value pair Error of the specific property /* * Use Case 1 by following CourseCampusForApplicationManipulationDto Validation Rules:- * Request Body => * [ * { * "CourseCampusId": 0, * "IsPrimaryLocation" : true * }, * { * "CourseCampusId": 619, * "IsPrimaryLocation" : true * } * ] * Response => * { * "[0].CourseCampusId": [ * "Please provide valid value for CourseCampusId between 1 to 1000000" * ] * } */ return(new UnprocessableEntityObjectResult(ModelState)); } if (!_applicationInfoRepository.ApplicationExists(applicationId)) { return(NotFound()); } foreach (CourseCampusForApplicationCreationDto courseCampusForApplication in courseCampusesForApplication) { var acc = Mapper.Map <Entities.ApplicationCourseCampus>(courseCampusForApplication); if (!_applicationInfoRepository.CourseCampusExists(acc.CourseCampusId)) { return(NotFound()); } else { _applicationInfoRepository.AddCourseCampusForApplication( applicationId, acc //cc.CourseCampus //_applicationInfoRepository.GetCourseCampus(cc.CourseCampusId) ); } } if (!_applicationInfoRepository.Save()) { return(StatusCode(500, "A problem happened while handling your request.")); } return(Ok()); }