Exemplo n.º 1
0
        public BaseService(CosDbContext dbContext)
        {
            this.DbContext = dbContext;

            this.MailingAddressRepository   = RepositoryFactory.CreateObj <MailingAddressRepository>(dbContext);
            this.ExchangeRepository         = RepositoryFactory.CreateObj <ExchangeRepository>(dbContext);
            this.ExchangeExamineRepository  = RepositoryFactory.CreateObj <ExchangeExamineRepository>(dbContext);
            this.CooperationRepository      = RepositoryFactory.CreateObj <CooperationRepository>(dbContext);
            this.ImgRepository              = RepositoryFactory.CreateObj <ImgRepository>(dbContext);
            this.ExchangeReplyRepository    = RepositoryFactory.CreateObj <ExchangeReplyRepository>(dbContext);
            this.CooperationReplyRepository = RepositoryFactory.CreateObj <CooperationReplyRepository>(dbContext);
            this.ExchangePersonRepository   = RepositoryFactory.CreateObj <ExchangePersonRepository>(dbContext);
            this.MemberRepository           = RepositoryFactory.CreateObj <MemberRepository>(dbContext);
            this.RechargeRecordRepository   = RepositoryFactory.CreateObj <RechargeRecordRepository>(dbContext);
            this.SysParaRepository          = RepositoryFactory.CreateObj <SysParaRepository>(dbContext);
            this.ExchangeEventRepository    = RepositoryFactory.CreateObj <ExchangeEventRepository>(dbContext);
            this.DepositControlRepository   = RepositoryFactory.CreateObj <DepositControlRepository>(dbContext);
            this.LogisticRepository         = RepositoryFactory.CreateObj <LogisticRepository>(dbContext);
            this.LoginCodeRepository        = RepositoryFactory.CreateObj <LoginCodeRepository>(dbContext);
            this.ShipperCompanyRepository   = RepositoryFactory.CreateObj <ShipperCompanyRepository>(dbContext);
            this.AdminMemberRepository      = RepositoryFactory.CreateObj <AdminMemberRepository>(dbContext);
            this.CooperationClassRepository = RepositoryFactory.CreateObj <CooperationClassRepository>(dbContext);
            this.RefundRepository           = RepositoryFactory.CreateObj <RefundRepository>(dbContext);
            this.QuickNavigationRepository  = RepositoryFactory.CreateObj <QuickNavigationRepository>(dbContext);
            this.PostageRepository          = RepositoryFactory.CreateObj <PostageRepository>(dbContext);
            this.CosFileStatRepository      = RepositoryFactory.CreateObj <CosFileStatRepository>(dbContext);
            this.ExchangeClassRepository    = RepositoryFactory.CreateObj <ExchangeClassRepository>(dbContext);
            this.VoucherRepository          = RepositoryFactory.CreateObj <VoucherRepository>(dbContext);
            this.LoginIpRepository          = RepositoryFactory.CreateObj <LoginIPRepository>(dbContext);
            this.IntegralChangeRepository   = RepositoryFactory.CreateObj <IntegralChangeRepository>(dbContext);
            this.LoggingRepository          = RepositoryFactory.CreateObj <LoggingRepository>(dbContext);
            this.MemberRegisterRepository   = RepositoryFactory.CreateObj <MemberRegisterRepository>(dbContext);
            this.VersionNotesRepository     = RepositoryFactory.CreateObj <VersionNotesRepository>(dbContext);
        }
Exemplo n.º 2
0
 public ExchangeExamineService(CosDbContext nContext) : base(nContext)
 {
 }
Exemplo n.º 3
0
 public MailingAddressService(CosDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 4
0
 public RemoteController(CosDbContext dbContext)
 {
     _memberService    = new MemberService(dbContext);
     _loginCodeService = new LoginCodeService(dbContext);
     _voucherService   = new VoucherService(dbContext);
 }
Exemplo n.º 5
0
 public ExchangeEventService(CosDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 6
0
 public ExchangeClassService(CosDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="dbContext"></param>
 public ExchangeClassController(CosDbContext dbContext)
 {
     _exchangeClassService = new ExchangeClassService(dbContext);
 }
Exemplo n.º 8
0
 public LoginIPService(CosDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 9
0
 public ExchangePersonService(CosDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 10
0
 public MemberService(CosDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 11
0
 public VoucherService(CosDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 12
0
 public CosFileStatService(CosDbContext dbContext)
     : base(dbContext)
 {
 }
Exemplo n.º 13
0
 public HotSearchService(CosDbContext dbContext) : base(dbContext)
 {
     _hotSearchRepository = RepositoryFactory.CreateObj <HotSearchRepository>(dbContext);
 }
Exemplo n.º 14
0
 public QuickNavigationService(CosDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 15
0
 public DepositControlService(CosDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="dbContext"></param>
 public ExchangeExamineController(CosDbContext dbContext)
 {
     _exchangeExamineService = new ExchangeExamineService(dbContext);
 }
Exemplo n.º 17
0
 public PostageService(CosDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 18
0
 public ShipperCompanyService(CosDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 19
0
 public ExchangeReplyService(CosDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 20
0
 public CooperationClassService(CosDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 21
0
 public SysParaService(CosDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 22
0
 public VersionNotesService(CosDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 23
0
 public ImgService(CosDbContext dbContext) : base(dbContext)
 {
     _imgRepository = RepositoryFactory.CreateObj <ImgRepository>(dbContext);
 }
Exemplo n.º 24
0
 public ExchangeService(CosDbContext dbContext) : base(dbContext)
 {
     _integralChangeService = new IntegralChangeService(dbContext);
 }
Exemplo n.º 25
0
 public LogisticService(CosDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 26
0
 public CooperationReplyService(CosDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 27
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="dbContext"></param>
 public HotSearchController(CosDbContext dbContext)
 {
     _hotSearchService = new HotSearchService(dbContext);
 }
Exemplo n.º 28
0
 public RechargeRecordService(CosDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 29
0
 public LoginCodeService(CosDbContext dbContext) : base(dbContext)
 {
     _loginCodeRepository = RepositoryFactory.CreateObj <LoginCodeRepository>(dbContext);
 }
Exemplo n.º 30
0
        /// <summary>
        /// Overridden IsValid function
        /// </summary>
        /// <param name="value"></param>
        /// <param name="validationContext"></param>
        /// <returns></returns>
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            string connection = OtherConfig.CosSSMSConnString;
            DbContextOptions <CosDbContext>        dbContextOption        = new DbContextOptions <CosDbContext>();
            DbContextOptionsBuilder <CosDbContext> dbContextOptionBuilder = new DbContextOptionsBuilder <CosDbContext>(dbContextOption);
            CosDbContext dbContext = new CosDbContext(dbContextOptionBuilder.UseSqlServer(connection).Options);

            // Find the controller passed in constructor
            var controller = GetControllerList().FirstOrDefault(x => x.Name == string.Format("{0}Controller", this.RouteData["controller"]));

            if (controller == null)
            {
                // Default behavior of IsValid when no controller is found.
                return(ValidationResult.Success);
            }
            List <Type> proTypeList = new List <Type>()
            {
                value.GetType()
            };
            List <object> proList = new List <object>()
            {
                value
            };

            if (!string.IsNullOrWhiteSpace(AdditionalFields))
            {
                var fields = AdditionalFields.Split(',', StringSplitOptions.RemoveEmptyEntries);
                proTypeList.AddRange(validationContext.ObjectType.GetProperties().Where(info => fields.Any(s => info.Name.Contains(s))).Select(info => info.PropertyType));

                proList.AddRange(validationContext.ObjectType.GetProperties().Where(info => fields.Any(s => info.Name.Contains(s))).Select(info => info.GetValue(validationContext.ObjectInstance)));
            }

            // Find the Method passed in constructor
            var mi = controller.GetMethod(this.RouteData["action"].ToString(), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, proTypeList.ToArray(), null);

            if (mi == null)
            {
                // Default behavior of IsValid when action not found
                return(ValidationResult.Success);
            }

            // Create instance of the controller to be able to call non static validation method
            var instance = Activator.CreateInstance(controller, dbContext);

            // invoke the method on the controller with value and "AdditionalFields"
            JsonResult result = mi.Invoke(instance, proList.ToArray()) is Task <object> task ? (JsonResult)task.Result : (JsonResult)mi.Invoke(instance, proList.ToArray());

            // Return success or the error message string from CustomRemoteAttribute
            if (!(result.Value is string errorMessaqe))
            {
                bool isValid;
                try
                {
                    isValid = (bool)result.Value;
                }
                catch (Exception)
                {
                    isValid = false;
                }
                return(isValid ? ValidationResult.Success : new ValidationResult(base.ErrorMessageString));
            }