Example #1
0
        public int UpdateRight(SysRightOperateModel model)
        {
            //转换
            SysRightOperate rightOperate = new SysRightOperate();

            rightOperate.Id      = model.Id;
            rightOperate.RightId = model.RightId;
            rightOperate.KeyCode = model.KeyCode;
            rightOperate.IsValid = model.IsValid;
            //判断rightOperate是否存在,如果存在就更新rightOperate,否则就添加一条
            using (DBContainer db = new DBContainer())
            {
                SysRightOperate right = db.SysRightOperate.Where(a => a.Id == rightOperate.Id).FirstOrDefault();
                if (right != null)
                {
                    right.IsValid = rightOperate.IsValid;
                }
                else
                {
                    db.Set <SysRightOperate>().Add(rightOperate);
                }
                if (db.SaveChanges() > 0)
                {
                    //更新角色--模块的有效标志RightFlag
                    var sysRight = (from r in db.SysRight
                                    where r.Id == rightOperate.RightId
                                    select r).First();
                    db.P_Sys_UpdateSysRightRightFlag(sysRight.ModuleId, sysRight.RoleId);
                    return(1);
                }
            }
            return(0);
        }
 public int UpdateRight(SysRightOperate model)
 {
     //判断rightOperate是否存在,如果存在就更新rightOperate,否则就添加一条
     using (DBContainer db = new DBContainer())
     {
         SysRightOperate right = db.SysRightOperate.FirstOrDefault(o => o.Id == model.Id);
         if (right != null)
         {
             right.RightId         = model.RightId;
             right.KeyCode         = model.KeyCode;
             right.IsValid         = model.IsValid;
             db.Entry(right).State = System.Data.Entity.EntityState.Modified;
         }
         else
         {
             db.SysRightOperate.Add(model);
         }
         if (db.SaveChanges() > 0)
         {
             //更新角色--模块的有效标志RightFlag
             var sysRight = (from r in db.SysRight where r.Id == model.RightId select r).First();
             db.P_Sys_UpdateSysRightRightFlag(sysRight.ModuleId, sysRight.RoleId);
             return(1);
         }
     }
     return(0);
 }
        public virtual bool Edit(ref ValidationErrors errors, SysRightOperateModel model)
        {
            try
            {
                SysRightOperate entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id      = model.Id;
                entity.RightId = model.RightId;
                entity.KeyCode = model.KeyCode;
                entity.IsValid = model.IsValid;



                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 #4
0
        /// <summary>
        /// 更新权限表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>

        public bool UpdateRight(SysRightOperate model)
        {
            using (DBContainer db = new DBContainer())
            {
                SysRightOperate right = db.SysRightOperate.SingleOrDefault(r => r.Id == model.Id);
                if (right != null)
                {
                    //也许right在上一句查询中已被添加到db容器中
                    right.IsValid = model.IsValid;
                    db.Set <SysRightOperate>().Attach(right);
                    db.Entry <SysRightOperate>(right).State = EntityState.Modified;
                }
                else
                {
                    db.Set <SysRightOperate>().Add(model);
                }
                //
                int i = db.SaveChanges();
                if (i > 0)
                {
                    var sysRight = (from r in db.SysRight
                                    where r.Id == model.RightId
                                    select r).First();
                    db.P_Sys_UpdateSysRightRightFlag(sysRight.ModuleId, sysRight.RoleId);
                    return(true);
                }
                return(false);
            }
        }
Example #5
0
        public int UpdateRight(SysRightOperateModel model)
        {
            //转换
            SysRightOperate rightOperate = new SysRightOperate();

            rightOperate.Id      = model.Id;
            rightOperate.RightId = model.RightId;
            rightOperate.KeyCode = model.KeyCode;
            rightOperate.IsValid = model.IsValid;

            using (var db = new SysMgr_DBEntities())
            {
                SysRightOperate right = db.SysRightOperate.Where(a => a.Id == rightOperate.Id).FirstOrDefault();
                if (right != null)
                {
                    right.IsValid = rightOperate.IsValid;
                }
                else
                {
                    db.SysRightOperate.Add(rightOperate);
                }
                if (db.SaveChanges() > 0)
                {
                    //更新角色--模块的有效标志RightFlag
                    var sysRight = (from r in db.SysRight
                                    where r.Id == rightOperate.RightId
                                    select r).FirstOrDefault();
                    db.P_Sys_UpdateSysRightRightFlag(sysRight.ModuleId, sysRight.RoleId);
                    return(1);
                }
            }
            return(0);
        }
        public virtual bool Create(ref ValidationErrors errors, SysRightOperateModel model)
        {
            try
            {
                SysRightOperate entity = m_Rep.GetById(model.Id);
                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(false);
                }
                entity         = new SysRightOperate();
                entity.Id      = model.Id;
                entity.RightId = model.RightId;
                entity.KeyCode = model.KeyCode;
                entity.IsValid = model.IsValid;


                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 #7
0
 public static bool Insert(SysRightOperate sysRightOperate)
 {
     using (var context = db.Context())
     {
         return(context.Insert <SysRightOperate>("SysRightOperate", sysRightOperate)
                .Execute() > 0);
     }
 }
Example #8
0
        public int UpdateRight(SysRightOperateModel model)
        {
            //转换
            SysRightOperate rightOperate = new SysRightOperate();

            rightOperate.Id      = model.Id;
            rightOperate.RightId = model.RightId;
            rightOperate.KeyCode = model.KeyCode;
            rightOperate.IsValid = model.IsValid;
            return(m_Rep.UpdateRight(rightOperate));
        }
Example #9
0
        public static bool Update(SysRightOperate sysRightOperate)
        {
            using (var context = db.Context())
            {
                return(context.Update <SysRightOperate>("SysRightOperate", sysRightOperate)
                       .AutoMap(x => x.Id)

                       .Where("Id", sysRightOperate.Id)

                       .Execute() > 0);
            }
        }
Example #10
0
        public virtual SysRightOperateModel GetById(object id)
        {
            if (IsExists(id))
            {
                SysRightOperate      entity = m_Rep.GetById(id);
                SysRightOperateModel model  = new SysRightOperateModel();
                model.Id      = entity.Id;
                model.RightId = entity.RightId;
                model.KeyCode = entity.KeyCode;
                model.IsValid = entity.IsValid;

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

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

                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
                entity         = new SysRightOperate();
                entity.Id      = model.Id;
                entity.RightId = model.RightId;
                entity.KeyCode = model.KeyCode;
                entity.IsValid = model.IsValid;


                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));
            }
        }
Example #12
0
 public int UpdateRight(SysRightOperate model)
 {
     using (OriginEntities db = new OriginEntities())
     {
         SysRightOperate right = db.SysRightOperate.Where(a => a.Id == model.Id).FirstOrDefault();
         if (right != null)
         {
             right.IsValid = model.IsValid;
         }
         else
         {
             db.SysRightOperate.Add(model);
         }
         if (db.SaveChanges() > 0)
         {
             var sysRight = (from r in db.SysRight
                             where r.Id == model.RightId
                             select r).First();
             db.P_Sys_UpdateSysRightRightFlag(sysRight.ModuleId, sysRight.RoleId);
             return(1);
         }
         return(0);
     }
 }
Example #13
0
 public bool UpdateRight(ValidationErrors errors, SysRightOperateModel model)
 {
     try
     {
         if (model != null)
         {
             SysRightOperate entity = new SysRightOperate()
             {
                 Id      = model.Id,
                 RightId = model.RightId,
                 KeyCode = model.KeyCode,
                 IsValid = model.IsValid
             };
             if (Rep.UpdateRight(entity))
             {
                 return(true);
             }
             else
             {
                 errors.add(Suggestion.UpdateFail);
                 return(false);
             }
         }
         else
         {
             errors.add(Suggestion.UpdateFail);
             return(false);
         }
     }
     catch (Exception ex)
     {
         errors.add(ex.Message);
         ExceptionHandler.WriteException(ex);
         return(false);
     }
 }
Example #14
0
        /// <summary>
        /// 保存数据
        /// </summary>
        public virtual void SaveImportData(IEnumerable <SysRightOperateModel> list)
        {
            try
            {
                using (DBContainer db = new DBContainer())
                {
                    foreach (var model in list)
                    {
                        SysRightOperate entity = new SysRightOperate();
                        entity.Id      = ResultHelper.NewId;
                        entity.RightId = model.RightId;
                        entity.KeyCode = model.KeyCode;
                        entity.IsValid = model.IsValid;

                        db.SysRightOperate.Add(entity);
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Example #15
0
        public virtual async Task <Tuple <ValidationErrors, bool> > EditAsync(SysRightOperateModel model)
        {
            ValidationErrors errors = new ValidationErrors();

            try
            {
                SysRightOperate 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.RightId = model.RightId;
                entity.KeyCode = model.KeyCode;
                entity.IsValid = model.IsValid;


                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));
            }
        }
Example #16
0
 public int UpdateRight(SysRightOperate model)
 {
     return(SysRightDAL.UpdateRight(model));
 }
Example #17
0
 public static bool Delete(SysRightOperate sysRightOperate)
 {
     return(Delete(sysRightOperate.Id));
 }
Example #18
0
 public int UpdateRight(SysRightOperate model)
 {
     return(sysRightRep.UpdateRight(model));
 }
Example #19
0
        public Resp_Binary UpdateRight(SysRightOperate_Update request)
        {
            if (request.IsNull() && request.ModuleOperateIds.Count < 1)
            {
                return new Resp_Binary {
                           message = "请选择要操作的记录"
                }
            }
            ;

            if (request.ModuleId < 1)
            {
                return new Resp_Binary {
                           message = "请选择一个模块"
                }
            }
            ;

            if (request.RoleId < 1)
            {
                return new Resp_Binary {
                           message = "请选择一个角色"
                }
            }
            ;


            var sysRight = _sysRightRepository.GetByWhere(r => r.SysRoleId == request.RoleId && r.SysModuleId == request.ModuleId).FirstOrDefault();

            if (sysRight.IsNull())
            {
                if (request.ModuleOperateIds.Exists(t => t.IsRightValid == 1))
                {
                    sysRight = new SysRight {
                        SysModuleId = request.ModuleId, SysRoleId = request.RoleId, Rightflag = 1
                    }
                }
                ;
                else
                {
                    sysRight = new SysRight {
                        SysModuleId = request.ModuleId, SysRoleId = request.RoleId, Rightflag = 0
                    }
                };

                _sysRightRepository.Insert(sysRight);
            }
            else
            {
                using (var context = new SKContext())
                {
                    var delsysRight = context.SysRights.Single(t => t.ID == sysRight.ID);
                    delsysRight.SysRightOperates.Clear();
                    var temp = context.SysRightOperates.Local.Where(p => p.SysRight == null).ToList();
                    temp.ForEach(r => context.SysRightOperates.Remove(r));
                    var s = context.SaveChanges();
                }
            }


            request.ModuleOperateIds.ForEach(t =>
            {
                var sysRightOperate = new SysRightOperate {
                    RightId = sysRight.ID, SysModuleOperateId = t.ID, IsValid = t.IsRightValid
                };
                sysRight.SysRightOperates.Add(sysRightOperate);
            });

            var count = _sysRightRepository.UnitOfWork.Commite();

            if (count > 0)
            {
                var sysRightAfter = _sysRightRepository.GetByWhere(r => r.SysRoleId == request.RoleId && r.SysModuleId == request.ModuleId).FirstOrDefault();
                if (sysRightAfter.SysRightOperates.FirstOrDefault(ss => ss.IsValid == 1).IsNull())       //更新用户权限
                {
                    sysRightAfter.Rightflag = 0;
                    _sysRightRepository.Update(sysRightAfter);
                }
                else
                {
                    sysRightAfter.Rightflag = 1;
                    _sysRightRepository.Update(sysRightAfter);
                }

                var module = _sysModuleRepository.GetByWhere(r => r.ID == request.ModuleId).FirstOrDefault();
                UpateParentModuleRight(module);
                void UpateParentModuleRight(SysModule source)
                {
                    if (source.IsNotNull())
                    {
                        var parent = source.SuperSysModule;
                        if (parent.IsNotNull())
                        {
                            var sysSuperRight   = _sysRightRepository.GetByWhere(r => r.SysRoleId == request.RoleId && r.SysModuleId == parent.ID).FirstOrDefault();
                            var sysSourceRights = _sysRightRepository.GetByWhere(r => r.SysRoleId == request.RoleId && r.Rightflag == 1);
                            var _Rightflag      = 0;
                            if (!sysSourceRights.IsNullOrEmpty())
                            {
                                _Rightflag = 1;
                            }
                            if (sysSuperRight.IsNull())
                            {
                                sysRight = new SysRight {
                                    SysModuleId = parent.ID, SysRoleId = request.RoleId, Rightflag = _Rightflag
                                };
                                _sysRightRepository.Insert(sysRight);
                            }
                            else
                            {
                                sysSuperRight.Rightflag = _Rightflag;
                                _sysRightRepository.Update(sysSuperRight);
                            }
                            UpateParentModuleRight(parent);
                        }
                    }
                }

                _sysRightRepository.UnitOfWork.Commite();
                return(Resp_Binary.Modify_Sucess);
            }
            return(Resp_Binary.Modify_Failed);
        }