Example #1
0
        public virtual bool Edit(ref ValidationErrors errors, SysValidTokenModel model)
        {
            try
            {
                SysValidToken entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id         = model.Id;
                entity.Token      = model.Token;
                entity.OverTime   = model.OverTime;
                entity.ModifyTime = model.ModifyTime;
                entity.CreateTime = model.CreateTime;



                if (m_Rep.Edit(entity))
                {
                    return(true);
                }
                else
                {
                    errors.Add(Resource.NoDataChange);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }
Example #2
0
        public virtual bool Create(ref ValidationErrors errors, SysValidTokenModel model)
        {
            try
            {
                SysValidToken entity = m_Rep.GetById(model.Id);
                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(false);
                }
                entity            = new SysValidToken();
                entity.Id         = model.Id;
                entity.Token      = model.Token;
                entity.OverTime   = model.OverTime;
                entity.ModifyTime = model.ModifyTime;
                entity.CreateTime = model.CreateTime;


                if (m_Rep.Create(entity))
                {
                    return(true);
                }
                else
                {
                    errors.Add(Resource.InsertFail);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }
Example #3
0
        /// <summary>
        /// 校验Excel数据,这个方法一般用于重写校验逻辑
        /// </summary>
        public virtual bool CheckImportData(string fileName, List <SysValidTokenModel> list, ref ValidationErrors errors)
        {
            var targetFile = new FileInfo(fileName);

            if (!targetFile.Exists)
            {
                errors.Add("导入的数据文件不存在");
                return(false);
            }

            var excelFile = new ExcelQueryFactory(fileName);

            //对应列头
            excelFile.AddMapping <SysValidTokenModel>(x => x.Token, "Token");
            excelFile.AddMapping <SysValidTokenModel>(x => x.OverTime, "OverTime");
            excelFile.AddMapping <SysValidTokenModel>(x => x.ModifyTime, "ModifyTime");
            excelFile.AddMapping <SysValidTokenModel>(x => x.CreateTime, "CreateTime");

            //SheetName
            var excelContent = excelFile.Worksheet <SysValidTokenModel>(0);
            int rowIndex     = 1;

            //检查数据正确性
            foreach (var row in excelContent)
            {
                var errorMessage = new StringBuilder();
                var entity       = new SysValidTokenModel();
                entity.Id         = row.Id;
                entity.Token      = row.Token;
                entity.OverTime   = row.OverTime;
                entity.ModifyTime = row.ModifyTime;
                entity.CreateTime = row.CreateTime;

                //=============================================================================
                if (errorMessage.Length > 0)
                {
                    errors.Add(string.Format(
                                   "第 {0} 列发现错误:{1}{2}",
                                   rowIndex,
                                   errorMessage,
                                   "<br/>"));
                }
                list.Add(entity);
                rowIndex += 1;
            }
            if (errors.Count > 0)
            {
                return(false);
            }
            return(true);
        }
Example #4
0
        public override bool Create(ref ValidationErrors errors, SysValidTokenModel model)
        {
            try
            {
                SysValidToken entity = m_Rep.GetById(model.Id);
                if (entity != null)
                {
                    //已经存在token,更新token
                    entity.Token      = model.Token;
                    entity.ModifyTime = ResultHelper.NowTime;
                    if (m_Rep.Edit(entity))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                entity            = new SysValidToken();
                entity.Id         = model.Id;
                entity.Token      = model.Token;
                entity.OverTime   = model.OverTime;
                entity.ModifyTime = model.ModifyTime;
                entity.CreateTime = model.CreateTime;


                if (m_Rep.Create(entity))
                {
                    return(true);
                }
                else
                {
                    errors.Add(Resource.InsertFail);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }
Example #5
0
        public virtual SysValidTokenModel GetById(object id)
        {
            if (IsExists(id))
            {
                SysValidToken      entity = m_Rep.GetById(id);
                SysValidTokenModel model  = new SysValidTokenModel();
                model.Id         = entity.Id;
                model.Token      = entity.Token;
                model.OverTime   = entity.OverTime;
                model.ModifyTime = entity.ModifyTime;
                model.CreateTime = entity.CreateTime;

                return(model);
            }
            else
            {
                return(null);
            }
        }
Example #6
0
        public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(SysValidTokenModel model)
        {
            ValidationErrors errors = new ValidationErrors();

            try
            {
                SysValidToken entity = await m_Rep.GetByIdAsync(model.Id);

                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
                entity            = new SysValidToken();
                entity.Id         = model.Id;
                entity.Token      = model.Token;
                entity.OverTime   = model.OverTime;
                entity.ModifyTime = model.ModifyTime;
                entity.CreateTime = model.CreateTime;


                if (await m_Rep.CreateAsync(entity))
                {
                    return(new Tuple <ValidationErrors, bool>(errors, true));
                }
                else
                {
                    errors.Add(Resource.InsertFail);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(new Tuple <ValidationErrors, bool>(errors, false));
            }
        }