public IActionResult AddOrUpdateRegistrationRequest([FromForm] RegistrationRequestViewModel model) { try { if (model == null) { throw new ArgumentNullException(nameof(model), "Model cannot be null or empty"); } if (model.IsValid(ModelState) == false) { model.LoadMaritalStatuses(registrationRequestRepository); model.LoadRelationships(registrationRequestRepository); model.LoadStatesOfMexico(registrationRequestRepository); model.LoadMunicipalitiesOfMexico(registrationRequestRepository); model.LoadRegistrationRequestStatuses(registrationRequestRepository); model.CreationDate = DateTime.Now.ToCentralMexicoTime(); return(View("ShowForm", model)); } if (model.Id > 0) // update item { registrationRequestRepository.Update(model); } else // add new item { registrationRequestRepository.Add(model); } } catch (BusinessLogicException ex) { ModelState.AddModelError("", ex.Message); model.LoadMaritalStatuses(registrationRequestRepository); model.LoadRelationships(registrationRequestRepository); model.LoadStatesOfMexico(registrationRequestRepository); model.LoadMunicipalitiesOfMexico(registrationRequestRepository); model.LoadRegistrationRequestStatuses(registrationRequestRepository); return(View("ShowForm", model)); } catch (Exception) { throw; } return(RedirectToAction("Index")); }
public IActionResult AddRegistrationRequest([FromBody] RegistrationRequest registrationRequest) { if (registrationRequest == null) { return(BadRequest("registrationRequest cannot be null or empty")); } try { registrationRequestRepository.Add(registrationRequest); } catch (BusinessLogicException ble) { logger.LogWarning(ble.Message); return(StatusCode(StatusCodes.Status400BadRequest, ble.Message)); } catch (Exception ex) { logger.LogError(ex, null); return(StatusCode(StatusCodes.Status500InternalServerError, Constants.UNHANDLED_EXCEPTION_MESSAGE)); } return(Ok()); }