public async Task <ActionResult <DataResponse <LGAExtModel> > > Patch([FromRoute] string id) { DataResponse <LGAExtModel> response = new DataResponse <LGAExtModel>(); LGAExtModel _DTO = null; string errorMsg = String.Empty; try { if (id != null) { // Update LGA var _LGA = await _unitOfWork.LGAs.UpdateLGARestrictions(id).ConfigureAwait(false); if (_LGA == 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 <LGAExtModel>(_LGA); 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 <LGAExtModel> > > GetByID([FromRoute] string id) { DataResponse <LGAExtModel> response = new DataResponse <LGAExtModel>(); LGAExtModel _DTO = null; try { var _LGA = await _unitOfWork.LGAs.GetAsync(id).ConfigureAwait(false); if (_LGA == null) { response.Code = ResponseCode.NOT_FOUND; response.Description = ResponseDescription.NOT_FOUND; response.Message = "LGA not found"; response.Data = _DTO; return(NotFound(response)); } _DTO = _mapper.Map <LGAExtModel>(_LGA); 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 <LGAExtModel> > > Put([FromBody] LGAModel model, [FromRoute] string id) { DataResponse <LGAExtModel> response = new DataResponse <LGAExtModel>(); LGAExtModel _DTO = null; string errorMsg = String.Empty; try { if (ModelState.IsValid && model != null) { // Custom Validations if (!LGAFactory.ValidateModel(model, id, out errorMsg)) { response.Code = ResponseCode.FAILED; response.Description = ResponseDescription.FAILED; response.Message = errorMsg; response.Data = _DTO; return(BadRequest(response)); } State _theState = await _unitOfWork.States.GetAsync(model.StateId).ConfigureAwait(false); // Check Entity Exist if (_unitOfWork.LGAs.CheckExist(model.Name, model.Code, _theState, out errorMsg, id)) { response.Code = ResponseCode.FAILED; response.Description = ResponseDescription.FAILED; response.Message = errorMsg; response.Data = _DTO; return(BadRequest(response)); } // Generate entity var _entity = LGAFactory.Create(model, _theState); // Create user var _LGA = await _unitOfWork.LGAs.UpdateAsync(_entity).ConfigureAwait(false); int done = await _unitOfWork.CompleteAsync().ConfigureAwait(false); if (done > 0) { _DTO = _mapper.Map <LGAExtModel>(_LGA); 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)); } }