Exemple #1
0
        public virtual bool Edit(ref ValidationErrors errors, SysRightModel model)
        {
            try
            {
                SysRight entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id        = model.Id;
                entity.ModuleId  = model.ModuleId;
                entity.RoleId    = model.RoleId;
                entity.Rightflag = model.Rightflag;



                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);
            }
        }
Exemple #2
0
        public virtual bool Create(ref ValidationErrors errors, SysRightModel model)
        {
            try
            {
                SysRight entity = m_Rep.GetById(model.Id);
                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(false);
                }
                entity           = new SysRight();
                entity.Id        = model.Id;
                entity.ModuleId  = model.ModuleId;
                entity.RoleId    = model.RoleId;
                entity.Rightflag = model.Rightflag;


                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);
            }
        }
Exemple #3
0
        public bool Edit(ref ValidationErrors errors, SysRightModel model)
        {
            try
            {
                SysRight entity = sysRightRep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Suggestion.Disable);
                    return(false);
                }
                entity.Id        = model.Id;
                entity.ModuleId  = model.ModuleId;
                entity.Rightflag = model.Rightflag;
                entity.RoleId    = model.RoleId;

                if (sysRightRep.Edit(entity) == 1)
                {
                    return(true);
                }
                else
                {
                    errors.Add(Suggestion.EditFail);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }
Exemple #4
0
        /// <summary>
        /// 校验Excel数据,这个方法一般用于重写校验逻辑
        /// </summary>
        public virtual bool CheckImportData(string fileName, List <SysRightModel> list, ref ValidationErrors errors)
        {
            var targetFile = new FileInfo(fileName);

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

            var excelFile = new ExcelQueryFactory(fileName);

            //对应列头
            excelFile.AddMapping <SysRightModel>(x => x.ModuleId, "模块ID");
            excelFile.AddMapping <SysRightModel>(x => x.RoleId, "角色组ID");
            excelFile.AddMapping <SysRightModel>(x => x.Rightflag, "是否有权限");

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

            //检查数据正确性
            foreach (var row in excelContent)
            {
                var errorMessage = new StringBuilder();
                var entity       = new SysRightModel();
                entity.Id        = row.Id;
                entity.ModuleId  = row.ModuleId;
                entity.RoleId    = row.RoleId;
                entity.Rightflag = row.Rightflag;

                //=============================================================================
                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);
        }
Exemple #5
0
 public SysRightModel GetById(string id)
 {
     if (IsExist(id))
     {
         SysRight      entity = sysRightRep.GetById(id);
         SysRightModel model  = new SysRightModel();
         model.Id        = entity.Id;
         model.ModuleId  = entity.ModuleId;
         model.Rightflag = entity.Rightflag;
         model.RoleId    = entity.RoleId;
         return(model);
     }
     else
     {
         return(null);
     }
 }
Exemple #6
0
        public virtual SysRightModel GetById(object id)
        {
            if (IsExists(id))
            {
                SysRight      entity = m_Rep.GetById(id);
                SysRightModel model  = new SysRightModel();
                model.Id        = entity.Id;
                model.ModuleId  = entity.ModuleId;
                model.RoleId    = entity.RoleId;
                model.Rightflag = entity.Rightflag;

                return(model);
            }
            else
            {
                return(null);
            }
        }
Exemple #7
0
        public virtual async Task <SysRightModel> GetByIdAsync(object id)
        {
            if (IsExists(id))
            {
                SysRight entity = await m_Rep.GetByIdAsync(id);

                SysRightModel model = new SysRightModel();
                model.Id        = entity.Id;
                model.ModuleId  = entity.ModuleId;
                model.RoleId    = entity.RoleId;
                model.Rightflag = entity.Rightflag;

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

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

                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
                entity           = new SysRight();
                entity.Id        = model.Id;
                entity.ModuleId  = model.ModuleId;
                entity.RoleId    = model.RoleId;
                entity.Rightflag = model.Rightflag;


                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));
            }
        }
Exemple #9
0
        public virtual async Task <Tuple <ValidationErrors, bool> > EditAsync(SysRightModel model)
        {
            ValidationErrors errors = new ValidationErrors();

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

                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
                entity.Id        = model.Id;
                entity.ModuleId  = model.ModuleId;
                entity.RoleId    = model.RoleId;
                entity.Rightflag = model.Rightflag;


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