public async Task <ActionResult <DataResponse <StateExtModel> > > Patch([FromRoute] string id) { DataResponse <StateExtModel> response = new DataResponse <StateExtModel>(); StateExtModel _DTO = null; string errorMsg = String.Empty; try { if (id != null) { // Update state var _state = await _unitOfWork.States.UpdateStateRestrictions(id).ConfigureAwait(false); if (_state == null) { response.Code = ResponseCode.FAILED; response.Description = ResponseDescription.FAILED; response.Message = errorMsg; response.Data = _DTO; return(NotFound(response)); } int done = await _unitOfWork.CompleteAsync().ConfigureAwait(false); if (done > 0) { _DTO = _mapper.Map <StateExtModel>(_state); response.Code = ResponseCode.SUCCESS; response.Description = ResponseDescription.SUCCESS; response.Message = null; response.Data = _DTO; return(Ok(_DTO)); } } response.Code = ResponseCode.FAILED; response.Description = ResponseDescription.FAILED; response.Message = "Invalid user input"; response.Data = _DTO; return(BadRequest(response)); } catch (Exception ex) { Guid _ErrorCode = Guid.NewGuid(); Log.Error("Fatal Error [{ErrorCode}]: {Message}", _ErrorCode, ex.Message); response.Code = ResponseCode.SYSTEM_ERROR; response.Description = ResponseDescription.SYSTEM_ERROR; response.Message = $"System Error: Something went wrong here! Kindly contact the support with this error code [{_ErrorCode}]"; response.Data = _DTO; return(BadRequest(response)); } }
public async Task <ActionResult <DataResponse <StateExtModel> > > GetByID([FromRoute] string id) { DataResponse <StateExtModel> response = new DataResponse <StateExtModel>(); StateExtModel _DTO = null; try { var _state = await _unitOfWork.States.GetAsync(id).ConfigureAwait(false); if (_state == null) { response.Code = ResponseCode.NOT_FOUND; response.Description = ResponseDescription.NOT_FOUND; response.Message = "state not found"; response.Data = _DTO; return(NotFound(response)); } _DTO = _mapper.Map <StateExtModel>(_state); response.Code = ResponseCode.SUCCESS; response.Description = ResponseDescription.SUCCESS; response.Message = null; response.Data = _DTO; return(Ok(response)); } catch (Exception ex) { Guid _ErrorCode = Guid.NewGuid(); Log.Error("Fatal Error [{ErrorCode}]: {Message}", _ErrorCode, ex.Message); response.Code = ResponseCode.SYSTEM_ERROR; response.Description = ResponseDescription.SYSTEM_ERROR; response.Message = $"System Error: Something went wrong here! Kindly contact the support with this error code [{_ErrorCode}]"; response.Data = _DTO; return(BadRequest(response)); } }
public async Task <ActionResult <DataResponse <StateExtModel> > > Put([FromBody] StateModel model, [FromRoute] string id) { DataResponse <StateExtModel> response = new DataResponse <StateExtModel>(); StateExtModel _DTO = null; string errorMsg = String.Empty; try { if (ModelState.IsValid && model != null) { // Custom Validations if (!StateFactory.ValidateModel(model, id, out errorMsg)) { response.Code = ResponseCode.FAILED; response.Description = ResponseDescription.FAILED; response.Message = errorMsg; response.Data = _DTO; return(BadRequest(response)); } Country _theCountry = await _unitOfWork.Countries.GetAsync(model.CountryId).ConfigureAwait(false); // Check Entity Exist if (_unitOfWork.States.CheckExist(model.Name, model.Code, _theCountry, out errorMsg, id)) { response.Code = ResponseCode.FAILED; response.Description = ResponseDescription.FAILED; response.Message = errorMsg; response.Data = _DTO; return(BadRequest(response)); } // Generate entity var _entity = StateFactory.Create(model, _theCountry); // Create user var _state = await _unitOfWork.States.UpdateAsync(_entity).ConfigureAwait(false); int done = await _unitOfWork.CompleteAsync().ConfigureAwait(false); if (done > 0) { _DTO = _mapper.Map <StateExtModel>(_state); response.Code = ResponseCode.SUCCESS; response.Description = ResponseDescription.SUCCESS; response.Message = null; response.Data = _DTO; return(Ok(_DTO)); } } response.Code = ResponseCode.FAILED; response.Description = ResponseDescription.FAILED; response.Message = "Invalid user input"; response.Data = _DTO; return(BadRequest(response)); } catch (Exception ex) { Guid _ErrorCode = Guid.NewGuid(); Log.Error("Fatal Error [{ErrorCode}]: {Message}", _ErrorCode, ex.Message); response.Code = ResponseCode.SYSTEM_ERROR; response.Description = ResponseDescription.SYSTEM_ERROR; response.Message = $"System Error: Something went wrong here! Kindly contact the support with this error code [{_ErrorCode}]"; response.Data = _DTO; return(BadRequest(response)); } }