Example #1
0
        public BillTypeDtoValidator(IBillType billtype, IHttpContextAccessor _context)
        {
            this.billtype = billtype;
            this._context = _context;

            CascadeMode = CascadeMode.Stop;



            RuleFor(item => item.isout)
            .NotNull().WithMessage("{PropertyName}没有传递或者空")
            .WithName("类型");



            RuleFor(item => item.typename)
            .NotNull().WithMessage("{PropertyName}没有传递或者空")
            .NotEmpty().WithMessage("{PropertyName}为空")
            .MaximumLength(10).WithMessage("{PropertyName}最大长度请小于10位")
            .Must((item, name) =>
            {
                var user = _context.HttpContext.User;

                var claims = user.Claims;

                var mobile = (claims != null && claims.Count() > 0) ? (claims.FirstOrDefault(item => item.Type == System.Security.Claims.ClaimTypes.Name)?.Value) : string.Empty;

                return(!this.billtype.IsExistName(name, mobile));

                //return !this.billtype.IsExistName( name , item.mobile );

                //return true;
            }).When(item => !string.IsNullOrWhiteSpace(item.typename)).WithMessage(item => string.Format("{0}:{1}不唯一", "{PropertyName}", item.typename))
            .WithName("名称");
        }
Example #2
0
        public BillTypesController(IBillType Ibilltype, IMapper mapper, IMemoryCache memoryCache)
        {
            this.Ibilltype = Ibilltype;

            this.mapper = mapper;

            this.memoryCache = memoryCache;
        }
Example #3
0
 public static void WriteInfo(IBillType billType, string request, string response)
 {
     try
     {
         LogUtil logUtil = new LogUtil();
         logUtil.Write(billType, request, response, Info_Log);
     }
     catch
     {
         ;
     }
 }
Example #4
0
        private void Write(IBillType billType, string request, string response, string fileName)
        {
            try
            {
                if (!Directory.Exists(Path.Combine(DirPath, billType.BillType)))
                {
                    Directory.CreateDirectory(Path.Combine(DirPath, billType.BillType));
                }
                string filePath = Path.Combine(DirPath, billType.BillType + @"\" + fileName);
                if (File.Exists(filePath))
                {
                    FileInfo fileInfo = new FileInfo(filePath);
                    if (fileInfo.Length >= FileSize)
                    {
                        using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
                        {
                            byte[] buffer = new byte[stream.Length];
                            stream.Read(buffer, 0, buffer.Length);
                            stream.Flush();

                            //备份数据
                            using (FileStream newStream = new FileStream(Path.Combine(fileInfo.DirectoryName, DateTime.Now.ToString("yyyyMMdd") + fileName),
                                                                         FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
                            {
                                newStream.Write(buffer, 0, buffer.Length);
                                newStream.Flush();
                            }
                        }
                        //清空数据
                        File.WriteAllText(filePath, string.Empty, UTF8Encoding.UTF8);
                    }
                }
                var sj = string.Format("DateTime:{1}{0}Request:{2}{0}Response:{3}{0}",
                                       Environment.NewLine, DateTime.Now.ToString(), request, response);
                using (FileStream stream = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
                {
                    byte[] buffer = UTF8Encoding.UTF8.GetBytes(sj);
                    stream.Write(buffer, 0, buffer.Length);
                    stream.Flush();
                }
            }
            catch
            {
                ;
            }
        }
Example #5
0
 public BillTypeVM(IBillType billType)
 {
     this.BillTypeId = billType.BillTypeId;
     this.Name       = billType.Name;
 }
Example #6
0
        public IBillType DbBillTypeToIBillType(BillTypeDict entity)
        {
            IBillType billType = _factory.BillFactory.NewBillType(entity.BillTypeDictId, entity.Name);

            return(billType);
        }
Example #7
0
        public static void WriteError(IBillType billType, string request, Exception ex, string error = "")
        {
            LogUtil logUtil = new LogUtil();

            logUtil.Write(billType, request, string.Format("StackTrace:{0}Exception:{1}{2}", ex.StackTrace, ex.ToString(), error), Error_Log);
        }
Example #8
0
        public static void WriteError(IBillType billType, string request, string response)
        {
            LogUtil logUtil = new LogUtil();

            logUtil.Write(billType, request, response, Error_Log);
        }
Example #9
0
        public static void WriteError(IBillType billType, string error)
        {
            LogUtil logUtil = new LogUtil();

            logUtil.Write(billType, string.Empty, error, Error_Log);
        }
Example #10
0
        public BillDtoValidator(IBillType billtype, IBill bill, IHttpContextAccessor _context)
        {
            this.billtype = billtype;
            this.bill     = bill;
            this._context = _context;

            CascadeMode = CascadeMode.Stop;



            RuleFor(item => item.isadd)
            .NotNull().WithMessage("{PropertyName}没有传递或者空")
            .WithName("操作类型");


            RuleFor(item => item.billtypeid)
            .NotNull().WithMessage("{PropertyName}没有传递或者空")
            .GreaterThan(0).WithMessage("{PropertyName}请大于0")
            // 判断id是否合法
            .Must((item, billtypeid) =>
            {
                // 判断分2步: 第1判断是否为系统公用的 第2判断是否为该用户专用的

                bool bl = this.billtype.IsExistSystemType(billtypeid);

                if (bl)
                {
                    return(true);
                }
                else
                {
                    var user = _context.HttpContext.User;

                    var claims = user.Claims;

                    var mobile = (claims != null && claims.Count() > 0) ? (claims.FirstOrDefault(item => item.Type == System.Security.Claims.ClaimTypes.Name)?.Value) : string.Empty;

                    bl = this.billtype.IsExistUserType(billtypeid, mobile);

                    return(bl);
                }

                //return true;
            }).WithMessage(item => string.Format("{0}:{1}错误!它不是系统公用类型或者不是该用户专属类型", "{PropertyName}", item.billtypeid))
            .WithName("账目类型ID");

            RuleFor(item => item.isout)
            .Cascade(CascadeMode.Stop)
            .NotNull().WithMessage("{PropertyName}没有传递或者空")
            // 判断类型id和出入是否一致
            .Must((item, isout) =>
            {
                var _billtypeid = item.billtypeid;

                return(this.billtype.IsExistType(_billtypeid, isout));

                //return true;
            }).WithMessage("账目类型ID与账目进出类型不相符")
            .WithName("账目进出类型");

            RuleFor(item => item.moneydate)
            .NotNull().WithMessage("{PropertyName}没有传递或者空")
            .NotEmpty().WithMessage("{PropertyName}为空")
            .Length(10, 10).WithMessage("{PropertyName}长度不对!(格式:xxxx-xx-xx)")
            .Must((item, moneydate) =>
            {
                try
                {
                    Convert.ToDateTime(moneydate);
                }
                catch (Exception)
                {
                    return(false);
                }

                return(true);
            }).WithMessage("{PropertyName}不是正确日期格式(格式:xxxx-xx-xx)")
            .WithName("账目日期");

            RuleFor(item => item.moneys)
            .NotNull().WithMessage("{PropertyName}没有传递或者空")
            .GreaterThan(0).WithMessage("{PropertyName}请大于0")
            .WithName("金额");


            // 修改时,才验证
            RuleFor(item => item.ids)
            .Cascade(CascadeMode.Stop)
            .NotNull().When(item => !item.isadd).WithMessage("{PropertyName}没有传递或者空")
            .GreaterThan(0).When(item => !item.isadd).WithMessage("{PropertyName}请大于0")
            .Must((item, ids) =>
            {
                if (!item.isadd)
                {
                    var user = _context.HttpContext.User;

                    var claims = user.Claims;

                    var mobile = (claims != null && claims.Count() > 0) ? (claims.FirstOrDefault(item => item.Type == System.Security.Claims.ClaimTypes.Name)?.Value) : string.Empty;

                    return(this.bill.IsExistId(ids, mobile));
                }

                return(true);
            }).When(item => !item.isadd).WithMessage("{PropertyName}错误")
            .WithName("记录ID");
        }