Esempio n. 1
0
        /// <summary>
        /// 保存皮肤
        /// </summary>
        /// <param name="theme"></param>
        /// <param name="id"></param>
        public bool SaveTheme(string theme, string id)
        {
            SysPerson p = this.GetById(id);

            p.PageStyle = theme;
            repository.Edit(db, p);
            int count = repository.Save(db);

            return(count > 0);
        }
Esempio n. 2
0
        /// <summary>
        /// 编辑一个人员
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据上下文</param>
        /// <param name="entity">一个人员</param>
        /// <returns>是否编辑成功</returns>
        public bool Edit(ref ValidationErrors validationErrors, SysEntities db, SysPerson entity)
        {  /*
            * 不操作 原有 现有
            * 增加   原没 现有
            * 删除   原有 现没
            */
            if (entity == null)
            {
                return(false);
            }
            int       count      = 1;
            SysPerson editEntity = repository.Edit(db, entity);

            List <string> addSysRoleId    = new List <string>();
            List <string> deleteSysRoleId = new List <string>();

            GetDiffrent(entity.SysRoleId.GetIdSort(), entity.SysRoleIdOld.GetIdSort(), ref addSysRoleId, ref deleteSysRoleId);
            if (addSysRoleId != null && addSysRoleId.Count() > 0)
            {
                foreach (var item in addSysRoleId)
                {
                    SysRole sys = new SysRole {
                        Id = item
                    };
                    db.SysRole.Attach(sys);
                    editEntity.SysRole.Add(sys);
                    count++;
                }
            }
            if (deleteSysRoleId != null && deleteSysRoleId.Count() > 0)
            {
                List <SysRole> listEntity = new List <SysRole>();
                foreach (var item in deleteSysRoleId)
                {
                    SysRole sys = new SysRole {
                        Id = item
                    };
                    listEntity.Add(sys);
                    db.SysRole.Attach(sys);
                }
                foreach (SysRole item in listEntity)
                {
                    editEntity.SysRole.Remove(item);//查询数据库
                    count++;
                }
            }

            if (count == repository.Save(db))
            {
                return(true);
            }
            else
            {
                validationErrors.Add("编辑人员出错了");
            }
            return(false);
        }