Exemple #1
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task <(bool s, string msg)> DeleteAsync(long Id, CurrentUser currentUser)
        {
            var entity = await RoleRep.FindSingleAsync(o => o.Id == Id);

            if (entity == null)
            {
                return(false, "数据不存在");
            }
            await RoleRep.DeleteAsync(o => o.Id == Id);

            if (currentUser != null)
            {
                await OperateLogApp.RemoveLogAsync <Role>(currentUser, "删除角色", entity);
            }
            await RemoveCacheAsync(Id);

            return(true, "操作成功");
        }
Exemple #2
0
        /// <summary>
        /// 角色添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <R <Role> > CreateAsync(Role entity, List <long> permissionIds, CurrentUser currentUser)
        {
            entity.Id          = entity.CreateId();
            entity.CreatorTime = DateTime.Now;
            var moduledata = await ModuleApp.GetSaasModuleListAsync();

            var buttondata = await ModuleButtonApp.GetSaasModuleListAsync();

            List <long> allpermissionIds = new List <long>();

            foreach (long id in permissionIds)
            {
                allpermissionIds.Add(id);
                if (moduledata.Count(o => o.Id == id) > 0)
                {
                    var md = moduledata.Where(o => o.Id == id).FirstOrDefault();
                    if (md.ParentId != 0)
                    {
                        allpermissionIds.AddRange(await Fibonacci(md.ParentId));
                    }
                }
                else if (buttondata.Count(o => o.Id == id) > 0)
                {
                    var md = buttondata.Where(o => o.Id == id).FirstOrDefault();
                    if (md.ModuleId != 0)
                    {
                        allpermissionIds.AddRange(await Fibonacci(md.ModuleId));
                    }
                }
            }
            allpermissionIds = allpermissionIds.Distinct().ToList();
            List <RoleAuthorize> ras = new List <RoleAuthorize>();

            foreach (long id in allpermissionIds)// permissionIds
            {
                int itemType = 0;
                if (moduledata.Count(o => o.Id == id) > 0)
                {
                    itemType = 1;
                }
                else if (buttondata.Count(o => o.Id == id) > 0)
                {
                    itemType = 2;
                }
                if (itemType > 0)
                {
                    RoleAuthorize ra = new RoleAuthorize
                    {
                        ObjectId    = entity.Id,
                        ObjectType  = 1,
                        ItemId      = id,
                        ItemType    = itemType,
                        CreatorTime = DateTime.Now
                    };
                    ra.Id = ra.CreateId();
                    ras.Add(ra);
                }
            }

            UnitWork.Add <Role>(entity);
            UnitWork.BatchAdd <RoleAuthorize>(ras.ToArray());
            UnitWork.Save();


            if (currentUser != null)
            {
                await OperateLogApp.InsertLogAsync <Role>(currentUser, "添加角色", entity);
            }
            return(R <Role> .Suc(entity));
        }