コード例 #1
0
 public CustomerService(Lazy <ISpecialUOW> uow, Func <IUserManagerService> serviceFunc,
                        IBusinessException busEx, Func <ICustomerValidatorFactory> customerValidatorFactoryFunc) : base(uow.Value)
 {
     this.serviceFunc = serviceFunc;
     this.busEx       = busEx;
     this.uow         = uow;
     this.customerValidatorFactoryFunc = customerValidatorFactoryFunc;
 }
コード例 #2
0
        public object Invoke(MethodInfo methodInfo, object arguments, Func <object> method)
        {
            Type returnType = methodInfo.ReturnType;

            IApiResponse response = (IApiResponse)Activator.CreateInstance(returnType);

            try
            {
                IApiResult result = response as IApiResult;
                if (result != null)
                {
                    result.Data = method.Invoke();
                }
                else
                {
                    method.Invoke();
                }

                response.IsSuccess = true;
                return(response);
            }
            catch (ValidationException exception)
            {
                response.ValidationErrors = exception.Errors;
            }
            catch (BusinessException exception)
            {
                response.ErrorMessage = exception.Message;

                IApiError error = response as IApiError;
                if (error != null)
                {
                    error.ErrorCode = exception.Code;
                }
            }
            catch (Exception exception)
            {
                response.ErrorMessage = exception.Message;

                IBusinessException businessException = exception as IBusinessException;
                if (businessException != null)
                {
                    IApiError error = response as IApiError;
                    if (error != null)
                    {
                        error.ErrorCode = businessException.Code;
                    }
                }
            }

            response.IsSuccess = false;
            return(response);
        }
コード例 #3
0
        private ExceptionMessageModel BusinessOperationExceptionMessage(IBusinessException baseException)
        {
            ExceptionMessageModel model = new ExceptionMessageModel
            {
                Messages = new System.Collections.Generic.List <ExceptionMessage> {
                    new ExceptionMessage
                    {
                        Code    = baseException.BusinessOperationExceptionModel.Code,
                        Message = baseException.BusinessOperationExceptionModel.GetUFMessage()
                    }
                }
            };

            return(model);
        }
コード例 #4
0
        public async Task Advise(MethodAsyncAdviceContext context)
        {
            MethodInfo methodInfo = (MethodInfo)context.TargetMethod;
            Type       returnType = methodInfo.ReturnType.GetGenericArguments()[0];

            IApiResponse response;

            try
            {
                await context.ProceedAsync();

                return;
            }
            catch (ValidationException exception)
            {
                response = (IApiResponse)Activator.CreateInstance(returnType);
                response.ValidationErrors = exception.Errors;
            }
            catch (BusinessException exception)
            {
                response = (IApiResponse)Activator.CreateInstance(returnType);
                response.ErrorMessage = exception.Message;

                IApiError error = response as IApiError;
                if (error != null)
                {
                    error.ErrorCode = exception.Code;
                }
            }
            catch (Exception exception)
            {
                response = (IApiResponse)Activator.CreateInstance(returnType);
                response.ErrorMessage = exception.Message;

                IBusinessException businessException = exception as IBusinessException;
                if (businessException != null)
                {
                    IApiError error = response as IApiError;
                    if (error != null)
                    {
                        error.ErrorCode = businessException.Code;
                    }
                }
            }

            response.IsSuccess  = false;
            context.ReturnValue = Task.FromResult(response);
        }
コード例 #5
0
        public void Advise(MethodAdviceContext context)
        {
            MethodInfo methodInfo = (MethodInfo)context.TargetMethod;
            Type       returnType = methodInfo.ReturnType;

            IApiResponse response;

            try
            {
                context.Proceed();
                return;
            }
            catch (ValidationException exception)
            {
                response = (IApiResponse)Activator.CreateInstance(returnType);
                response.ValidationErrors = exception.Errors;
            }
            catch (BusinessException exception)
            {
                response = (IApiResponse)Activator.CreateInstance(returnType);
                response.ErrorMessage = exception.Message;

                IApiError error = response as IApiError;
                if (error != null)
                {
                    error.ErrorCode = exception.Code;
                }
            }
            catch (Exception exception)
            {
                response = (IApiResponse)Activator.CreateInstance(returnType);
                response.ErrorMessage = exception.Message;

                IBusinessException businessException = exception as IBusinessException;
                if (businessException != null)
                {
                    IApiError error = response as IApiError;
                    if (error != null)
                    {
                        error.ErrorCode = businessException.Code;
                    }
                }
            }

            response.IsSuccess  = false;
            context.ReturnValue = response;
        }
コード例 #6
0
ファイル: ResolveUser.cs プロジェクト: atul221282/SpecialApp
        /// <summary>
        /// This method must be wrapped under transaction
        /// </summary>
        /// <param name="email"></param>
        /// <param name="busEx"></param>
        /// <returns></returns>
        public async Task <IdentityResult> DeleteUsers(string email, IBusinessException busEx)
        {
            if (userResultType is UnauthorisedUser || userResultType is AnonymousUser)
            {
                busEx.Add("SpecialAppUsers", $"No user found for {email}");
            }

            busEx.ThrowIfErrors();

            var repo = uow.GetRepository <Users>();

            var users = await repo.GetAll().GetActive().FirstOrDefaultAsync(x => x.SpecialAppUsersId == userResultType.Id);

            if (users == null)
            {
                busEx.Add("Users", $"No user found for {email}");
            }

            busEx.ThrowIfErrors();

            await repo.Delete(users);

            return(await usrMngService.DeleteAsync((SpecialAppUsers)userResultType));
        }
コード例 #7
0
 public BusinessExceptionFor(Func <T> model, IBusinessException busEx)
 {
     this.model = model;
     this.Value = this.model();
     this.busEx = busEx;
 }