コード例 #1
0
        public virtual SearchFirstResponse <TDto> SearchFirst(SearchFirstRequest <TDto> request)
        {
            var response = new SearchFirstResponse <TDto> {
                IsSuccess = false, Item = null
            };

            try
            {
                if (_repository != null)
                {
                    response.Item = MapToDto(
                        _repository.SearchFirst(new SearchFirstRequest <TEntity>(request.Predicate, request.RequestBase)));
                    response.IsSuccess = true;
                    return(response);
                }

                response.ErrorMessage = "Response returned no results.";
                response.Item         = new TDto();
                return(response);
            }
            catch (DbEntityValidationException dbx)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = dbx.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(dbx.Message, " The validation errors are: ", fullErrorMessage);

                // Throw a new DbEntityValidationException with the improved exception message.
                throw new System.Exception(exceptionMessage);
            }
            catch (System.Exception ex)
            {
                ErrorHandler.LogException(ex);
                response.ErrorMessage = ErrorsEnum.ExceptionEncountered.FriendlyErrorMessage();
                response.IsSuccess    = false;
                response.ErrorCode    = (int)ErrorsEnum.ExceptionEncountered;
                return(response);
            }
        }
コード例 #2
0
        public TEntity SearchFirst(SearchFirstRequest <TEntity> request)
        {
            var expression = request.Predicate.ToBooleanExpression <TEntity>();

            return(DbSet.FirstOrDefault(expression));
        }
コード例 #3
0
 public SearchFirstResponse <ProductDto> SearchFirst(SearchFirstRequest <ProductDto> request)
 {
     return(BranchLogic.SearchFirst(request));
 }