コード例 #1
0
        public async Task <IActionResult> GetCounty([FromBody] GetCountyCommand getCountyCommand)
        {
            var results = await _mediator.Send(getCountyCommand, HttpContext.RequestAborted);

            if (results.IsValid)
            {
                return(Ok(results.Value));
            }
            return(BadRequest(results));
        }
コード例 #2
0
        public async Task <Library.Result <GetCountyResponse> > Handle(GetCountyCommand request, CancellationToken cancellationToken)
        {
            try
            {
                using (_unitOfWork)
                {
                    Expression <Func <County, bool> > expressionFinal = county => county.Id > 0;

                    if (request.CountyId != null)
                    {
                        Expression <Func <County, bool> > expressionCountyId = c => c.CountyId == request.CountyId;

                        expressionFinal = PredicateBuilder.And(expressionFinal, expressionCountyId);
                    }

                    if (request.SubcountyId != null)
                    {
                        Expression <Func <County, bool> > expressionSubCountyId = c => c.SubcountyId == request.SubcountyId;

                        expressionFinal = PredicateBuilder.And(expressionFinal, expressionSubCountyId);
                    }

                    if (request.WardId != null)
                    {
                        Expression <Func <County, bool> > expressionWardId = c => c.WardId == request.WardId;

                        expressionFinal = PredicateBuilder.And(expressionFinal, expressionWardId);
                    }

                    var result = await _unitOfWork.Repository <County>().Get(expressionFinal).ToListAsync();

                    _unitOfWork.Dispose();

                    return(Library.Result <GetCountyResponse> .Valid(new GetCountyResponse()
                    {
                        County = result
                    }));
                }
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
                return(Library.Result <GetCountyResponse> .Invalid(e.Message));
            }
        }