コード例 #1
0
ファイル: MappingExtensions.cs プロジェクト: emreoz37/MyBlog
        /// <summary>
        /// Execute a mapping from the Dto to a new entity
        /// </summary>
        /// <typeparam name="TEntity">Entity type</typeparam>
        /// <param name="Dto">Dto to map from</param>
        /// <returns>Mapped entity</returns>
        public static TEntity ToEntity <TEntity>(this BaseRequestDto Dto) where TEntity : BaseEntity
        {
            if (Dto == null)
            {
                throw new ArgumentNullException(nameof(Dto));
            }

            return(Dto.Map <TEntity>());
        }
コード例 #2
0
        private string GetLanguageCode(IInvocation invocation)
        {
            if (invocation.Arguments.Length > 0)
            {
                BaseRequestDto dto = GetRequestDtoBase(invocation);

                if (dto != null)
                {
                    return(dto.LanguageCode);
                }
            }

            return(ConfigurationManager.AppSettings["DefaultLanguageCode"] ?? "tr-TR");
        }
コード例 #3
0
ファイル: BaseApiController.cs プロジェクト: SygnCll/Wallet
        private TResultDTO InternalAuthentication <TResultDTO>(BaseRequestDto request) where TResultDTO : BaseResponseDTO, new()
        {
            TResultDTO result = new TResultDTO();

            var userResponse = this.userDomainService.AuthenticationUser(new Domain.Contract.DomainUserRequestDTO()
            {
                UserName = request.UserName, Password = request.Password
            });

            result.Header.ResponseCode = userResponse.ResponseCode;
            result.Header.Message      = userResponse.Message;
            result.Header.Status       = userResponse.Status;

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Validate API request input dto.
        /// </summary>
        /// <typeparam name="TRequest"></typeparam>
        /// <param name="request">request input.</param>
        /// <returns>ValidationResult</returns>
        private ValidationResult ValidateRequestDto <TRequest>(BaseRequestDto <TRequest> request)
        {
            ValidationResult results = new ValidationResult();
            IValidator <BaseRequestDto <TRequest> > baseValidator = new BaseRequestValidator <TRequest>();

            results = baseValidator.Validate(request);
            if (results.IsValid)
            {
                Type customValidator = System.Reflection.Assembly.Load(typeof(TRequest).Assembly.GetName()).GetTypes().Where(x => x.IsSubclassOf(typeof(AbstractValidator <TRequest>))).FirstOrDefault();
                if (customValidator != null)
                {
                    IValidator <TRequest> innerDataValidator = (IValidator <TRequest>)Activator.CreateInstance(customValidator);
                    results = innerDataValidator.Validate(request.Data);
                }
            }
            return(results);
        }
コード例 #5
0
        public async Task <JsonContentResult> Handle <TRequest, TResponse>(Func <BaseRequestDto <TRequest>, Task <BaseResponseDto <TResponse> > > useCaseRequest, BaseRequestDto <TRequest> request)
        {
            ValidationResult            validationResult = ValidateRequestDto(request);
            BaseResponseDto <TResponse> response         = new BaseResponseDto <TResponse>();

            if (validationResult.IsValid)
            {
                response = await useCaseRequest.Invoke(request);

                if (response != null)
                {
                    ContentResult.StatusCode = (int)HttpStatusCode.OK;
                    ContentResult.Content    = JsonHandler.Serialize(response);
                }
            }
            else
            {
                Dictionary <string, List <string> > dict = new Dictionary <string, List <string> >();
                validationResult.Errors.GroupBy(p => p.PropertyName).ToList().ForEach(item => dict.Add(item.Key, item.Select(e => e.ErrorMessage).ToList()));
                response.ReturnError(HttpEnum.ResponseStatus.InvalidData, HttpEnum.ResponseStatus.InvalidData.ToString(), Guid.NewGuid().ToString(), propErrors: dict);
            }
            ContentResult.StatusCode = (int)HttpStatusCode.OK;
            ContentResult.Content    = JsonHandler.Serialize(response);
            return(ContentResult);
        }