Beispiel #1
0
        public override async Task  DoDeleteAsync()
        {
            List <Guid> oldIDs = null;

            if (DpType == DpTypeEnum.User)
            {
                oldIDs = DC.Set <DataPrivilege>().Where(x => x.UserCode == Entity.UserCode && x.TableName == this.Entity.TableName).Select(x => x.ID).ToList();
            }
            else
            {
                oldIDs = DC.Set <DataPrivilege>().Where(x => x.GroupCode == Entity.GroupCode && x.TableName == this.Entity.TableName).Select(x => x.ID).ToList();
            }
            foreach (var oldid in oldIDs)
            {
                DataPrivilege dp = new DataPrivilege {
                    ID = oldid
                };
                DC.Set <DataPrivilege>().Attach(dp);
                DC.DeleteEntity(dp);
            }
            await DC.SaveChangesAsync();

            if (DpType == DpTypeEnum.User)
            {
                await Wtm.RemoveUserCache(Entity.UserCode.ToString());
            }
            else
            {
                var userids = DC.Set <FrameworkUserGroup>().Where(x => x.GroupCode == Entity.GroupCode).Select(x => x.UserCode).ToArray();
                await Wtm.RemoveUserCache(userids);
            }
        }
Beispiel #2
0
        public async Task <ActionResult> DoBatchDelete(FrameworkUserBatchVM vm, IFormCollection nouse)
        {
            List <string> itcode = new List <string>();

            itcode = DC.Set <FrameworkUser>().CheckIDs(new List <string>(vm.Ids)).Select(x => x.ITCode).ToList();
            if (!ModelState.IsValid || !vm.DoBatchDelete())
            {
                return(PartialView("BatchDelete", vm));
            }
            else
            {
                using (var tran = DC.BeginTransaction())
                {
                    try
                    {
                        var ur = DC.Set <FrameworkUserRole>().Where(x => itcode.Contains(x.UserCode));
                        DC.Set <FrameworkUserRole>().RemoveRange(ur);
                        var ug = DC.Set <FrameworkUserGroup>().Where(x => itcode.Contains(x.UserCode));
                        DC.Set <FrameworkUserGroup>().RemoveRange(ug);
                        DC.SaveChanges();
                        tran.Commit();
                    }
                    catch
                    {
                        tran.Rollback();
                    }
                }

                await Wtm.RemoveUserCache(itcode.ToArray());

                return(FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.OprationSuccess"]));
            }
        }
Beispiel #3
0
        public async Task <IActionResult> BatchDelete(string[] ids)
        {
            var vm = Wtm.CreateVM <FrameworkRoleBatchVM>();

            if (ids != null && ids.Count() > 0)
            {
                vm.Ids = ids;
            }
            else
            {
                return(Ok());
            }
            if (!ModelState.IsValid || !vm.DoBatchDelete())
            {
                return(BadRequest(ModelState.GetErrorJson()));
            }
            else
            {
                List <Guid?> roleids = new List <Guid?>();
                foreach (var item in vm?.Ids)
                {
                    roleids.Add(Guid.Parse(item));
                }
                var userids = DC.Set <FrameworkUserRole>().Where(x => DC.Set <FrameworkRole>().Where(y => roleids.Contains(y.ID)).Select(y => y.RoleCode).Contains(x.RoleCode)).Select(x => x.UserCode).ToArray();
                await Wtm.RemoveUserCache(userids);

                return(Ok(ids.Count()));
            }
        }
Beispiel #4
0
        public async Task <IActionResult> BatchDelete(string[] ids)
        {
            var           vm       = Wtm.CreateVM <FrameworkRoleBatchVM>();
            List <string> RoleCode = new List <string>();

            if (ids != null && ids.Count() > 0)
            {
                RoleCode = DC.Set <FrameworkRole>().CheckIDs(new List <string>(ids)).Select(x => x.RoleCode).ToList();
                vm.Ids   = ids;
            }
            else
            {
                return(Ok());
            }
            if (!ModelState.IsValid || !vm.DoBatchDelete())
            {
                return(BadRequest(ModelState.GetErrorJson()));
            }
            else
            {
                var ur      = DC.Set <FrameworkUserRole>().Where(x => RoleCode.Contains(x.RoleCode)).ToList();
                var itcodes = ur.Select(x => x.UserCode).ToArray();
                DC.Set <FrameworkUserRole>().RemoveRange(ur);
                DC.SaveChanges();
                await Wtm.RemoveUserCache(itcodes);

                return(Ok(ids.Count()));
            }
        }
Beispiel #5
0
        public async Task <bool> DoChangeAsync()
        {
            var         all            = FC.Where(x => x.Key.StartsWith("menu_")).ToList();
            List <Guid> AllowedMenuIds = all.Where(x => x.Value.ToString() == "1").Select(x => Guid.Parse(x.Key.Replace("menu_", ""))).ToList();
            var         torem          = AllowedMenuIds.Distinct();
            var         oldIDs         = DC.Set <FunctionPrivilege>().Where(x => x.RoleCode == Entity.RoleCode).Select(x => x.ID).ToList();

            foreach (var oldid in oldIDs)
            {
                FunctionPrivilege fp = new FunctionPrivilege {
                    ID = oldid
                };
                DC.Set <FunctionPrivilege>().Attach(fp);
                DC.DeleteEntity(fp);
            }
            foreach (var menuid in AllowedMenuIds)
            {
                FunctionPrivilege fp = new FunctionPrivilege();
                fp.MenuItemId = menuid;
                fp.RoleCode   = Entity.RoleCode;
                fp.Allowed    = true;
                DC.Set <FunctionPrivilege>().Add(fp);
            }
            await DC.SaveChangesAsync();

            var userids = DC.Set <FrameworkUserRole>().Where(x => x.RoleCode == Entity.RoleCode).Select(x => x.UserCode).ToArray();
            await Wtm.RemoveUserCache(userids);

            return(true);
        }
        public async Task <ActionResult> RefreshMenu()
        {
            Cache.Delete("FFMenus");
            var userids = DC.Set <FrameworkUser>().Select(x => x.ID.ToString().ToLower()).ToArray();
            await Wtm.RemoveUserCache(userids);

            return(Ok(Localizer["Sys.OprationSuccess"]));
        }
Beispiel #7
0
        public async Task Logout()
        {
            await Wtm.RemoveUserCache(Wtm.LoginUserInfo.ITCode);

            HttpContext.Session.Clear();
            await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

            HttpContext.Response.Redirect("/");
        }
Beispiel #8
0
        public async Task <ActionResult> Delete(Guid id, IFormCollection noUse)
        {
            var vm = Wtm.CreateVM <FrameworkRoleVM>(id);

            vm.DoDelete();
            if (!ModelState.IsValid)
            {
                var userids = DC.Set <FrameworkUserRole>().Where(x => DC.Set <FrameworkRole>().Where(y => y.ID == id).Select(y => y.RoleCode).FirstOrDefault() == x.RoleCode).Select(x => x.UserCode).ToArray();
                await Wtm.RemoveUserCache(userids);

                return(PartialView(vm));
            }
            else
            {
                return(FFResult().CloseDialog().RefreshGrid());
            }
        }
Beispiel #9
0
        public async Task <bool> DoChangeAsync()
        {
            List <Guid> AllowedMenuIds = new List <Guid>();
            var         torem          = AllowedMenuIds.Distinct();

            foreach (var page in Pages)
            {
                if (page.Actions != null)
                {
                    foreach (var action in page.Actions)
                    {
                        if (AllowedMenuIds.Contains(action) == false)
                        {
                            AllowedMenuIds.Add(action);
                        }
                    }
                }
            }

            var oldIDs = DC.Set <FunctionPrivilege>().Where(x => x.RoleCode == Entity.RoleCode).Select(x => x.ID).ToList();

            foreach (var oldid in oldIDs)
            {
                FunctionPrivilege fp = new FunctionPrivilege {
                    ID = oldid
                };
                DC.Set <FunctionPrivilege>().Attach(fp);
                DC.DeleteEntity(fp);
            }
            foreach (var menuid in AllowedMenuIds)
            {
                FunctionPrivilege fp = new FunctionPrivilege();
                fp.MenuItemId = menuid;
                fp.RoleCode   = Entity.RoleCode;
                fp.Allowed    = true;
                DC.Set <FunctionPrivilege>().Add(fp);
            }
            await DC.SaveChangesAsync();

            var userids = DC.Set <FrameworkUserRole>().Where(x => x.RoleCode == Entity.RoleCode).Select(x => x.UserCode).ToArray();
            await Wtm.RemoveUserCache(userids);

            return(true);
        }
Beispiel #10
0
        public async Task <ActionResult> DoBatchDelete(FrameworkRoleBatchVM vm, IFormCollection noUse)
        {
            if (!ModelState.IsValid || !vm.DoBatchDelete())
            {
                return(PartialView("BatchDelete", vm));
            }
            else
            {
                List <Guid?> roleids = new List <Guid?>();
                foreach (var item in vm?.Ids)
                {
                    roleids.Add(Guid.Parse(item));
                }
                var userids = DC.Set <FrameworkUserRole>().Where(x => DC.Set <FrameworkRole>().Where(y => roleids.Contains(y.ID)).Select(y => y.RoleCode).Contains(x.RoleCode)).Select(x => x.UserCode).ToArray();
                await Wtm.RemoveUserCache(userids);

                return(FFResult().CloseDialog().RefreshGrid());
            }
        }
        public async Task <ActionResult> DoBatchDelete(FrameworkUserBatchVM vm, IFormCollection nouse)
        {
            if (!ModelState.IsValid || !vm.DoBatchDelete())
            {
                return(PartialView("BatchDelete", vm));
            }
            else
            {
                List <Guid?> tempids = new List <Guid?>();
                foreach (var item in vm?.Ids)
                {
                    tempids.Add(Guid.Parse(item));
                }
                var userids = DC.Set <FrameworkUser>().Where(x => tempids.Contains(x.ID)).Select(x => x.ID.ToString()).ToArray();
                await Wtm.RemoveUserCache(userids);

                return(FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.OprationSuccess"]));
            }
        }
        public async Task <ActionResult> DoBatchDelete(FrameworkGroupBatchVM vm, IFormCollection noUse)
        {
            List <string> GroupCode = DC.Set <FrameworkGroup>().CheckIDs(new List <string>(vm.Ids)).Select(x => x.GroupCode).ToList();

            if (!ModelState.IsValid || !vm.DoBatchDelete())
            {
                return(PartialView("BatchDelete", vm));
            }
            else
            {
                var gr      = DC.Set <FrameworkUserGroup>().Where(x => GroupCode.Contains(x.GroupCode)).ToList();
                var itcodes = gr.Select(x => x.UserCode).ToArray();
                DC.Set <FrameworkUserGroup>().RemoveRange(gr);
                DC.SaveChanges();
                await Wtm.RemoveUserCache(itcodes);

                return(FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.OprationSuccess"]));
            }
        }
Beispiel #13
0
        public async Task <ActionResult> DoBatchDelete(FrameworkRoleBatchVM vm, IFormCollection noUse)
        {
            List <string> RoleCode = DC.Set <FrameworkRole>().CheckIDs(new List <string>(vm.Ids)).Select(x => x.RoleCode).ToList();

            if (!ModelState.IsValid || !vm.DoBatchDelete())
            {
                return(PartialView("BatchDelete", vm));
            }
            else
            {
                var ur      = DC.Set <FrameworkUserRole>().Where(x => RoleCode.Contains(x.RoleCode)).ToList();
                var itcodes = ur.Select(x => x.UserCode).ToArray();
                DC.Set <FrameworkUserRole>().RemoveRange(ur);
                DC.SaveChanges();
                await Wtm.RemoveUserCache(itcodes);

                return(FFResult().CloseDialog().RefreshGrid());
            }
        }
        public async Task <IActionResult> BatchDelete(string[] ids)
        {
            var           vm     = Wtm.CreateVM <FrameworkUserBatchVM>();
            List <string> itcode = new List <string>();

            if (ids != null && ids.Count() > 0)
            {
                vm.Ids = ids;
                itcode = DC.Set <FrameworkUser>().CheckIDs(new List <string>(ids)).Select(x => x.ITCode).ToList();
            }
            else
            {
                return(Ok());
            }
            if (!ModelState.IsValid || !vm.DoBatchDelete())
            {
                return(BadRequest(ModelState.GetErrorJson()));
            }
            else
            {
                using (var tran = DC.BeginTransaction())
                {
                    try
                    {
                        var ur = DC.Set <FrameworkUserRole>().Where(x => itcode.Contains(x.UserCode));
                        DC.Set <FrameworkUserRole>().RemoveRange(ur);
                        var ug = DC.Set <FrameworkUserGroup>().Where(x => itcode.Contains(x.UserCode));
                        DC.Set <FrameworkUserGroup>().RemoveRange(ug);
                        DC.SaveChanges();
                        tran.Commit();
                    }
                    catch
                    {
                        tran.Rollback();
                    }
                }

                await Wtm.RemoveUserCache(itcode.ToArray());

                return(Ok(ids.Count()));
            }
        }
Beispiel #15
0
        public override async Task DoDeleteAsync()
        {
            using (var tran = DC.BeginTransaction())
            {
                try
                {
                    await base.DoDeleteAsync();

                    var ur = DC.Set <FrameworkUserGroup>().Where(x => x.GroupCode == Entity.GroupCode);
                    DC.Set <FrameworkUserGroup>().RemoveRange(ur);
                    DC.SaveChanges();
                    tran.Commit();
                    await Wtm.RemoveUserCache(ur.Select(x => x.UserCode).ToArray());
                }
                catch
                {
                    tran.Rollback();
                }
            }
        }
        public override async Task DoEditAsync(bool updateAllFields = false)
        {
            if (FC.ContainsKey("Entity.ITCode"))
            {
                FC.Remove("Entity.ITCode");
            }
            using (var trans = DC.BeginTransaction())
            {
                if (SelectedRolesCodes != null)
                {
                    List <Guid> todelete = new List <Guid>();
                    todelete.AddRange(DC.Set <FrameworkUserRole>().AsNoTracking().Where(x => x.UserCode == Entity.ITCode).Select(x => x.ID));
                    foreach (var item in todelete)
                    {
                        DC.DeleteEntity(new FrameworkUserRole {
                            ID = item
                        });
                    }
                }
                if (SelectedGroupCodes != null)
                {
                    List <Guid> todelete = new List <Guid>();
                    todelete.AddRange(DC.Set <FrameworkUserGroup>().AsNoTracking().Where(x => x.UserCode == Entity.ITCode).Select(x => x.ID));
                    foreach (var item in todelete)
                    {
                        DC.DeleteEntity(new FrameworkUserGroup {
                            ID = item
                        });
                    }
                }
                if (SelectedRolesCodes != null)
                {
                    foreach (var rolecode in SelectedRolesCodes)
                    {
                        FrameworkUserRole r = new FrameworkUserRole
                        {
                            RoleCode = rolecode,
                            UserCode = Entity.ITCode
                        };
                        DC.AddEntity(r);
                    }
                }
                if (SelectedGroupCodes != null)
                {
                    foreach (var groupcode in SelectedGroupCodes)
                    {
                        FrameworkUserGroup g = new FrameworkUserGroup
                        {
                            GroupCode = groupcode,
                            UserCode  = Entity.ITCode
                        };
                        DC.AddEntity(g);
                    }
                }
                await base.DoEditAsync(updateAllFields);

                if (MSD.IsValid)
                {
                    trans.Commit();
                    await Wtm.RemoveUserCache(Entity.ID.ToString());
                }
                else
                {
                    trans.Rollback();
                }
            }
        }
        public override async Task DoDeleteAsync()
        {
            await base.DoDeleteAsync();

            await Wtm.RemoveUserCache(Entity.ID.ToString());
        }
Beispiel #18
0
        public override async Task DoEditAsync(bool updateAllFields = false)
        {
            List <Guid> oldIDs = null;

            if (DpType == DpTypeEnum.User)
            {
                oldIDs = DC.Set <DataPrivilege>().Where(x => x.UserCode == Entity.UserCode && x.TableName == this.Entity.TableName).Select(x => x.ID).ToList();
            }
            else
            {
                oldIDs = DC.Set <DataPrivilege>().Where(x => x.GroupCode == Entity.GroupCode && x.TableName == this.Entity.TableName).Select(x => x.ID).ToList();
            }
            foreach (var oldid in oldIDs)
            {
                DataPrivilege dp = new DataPrivilege {
                    ID = oldid
                };
                DC.Set <DataPrivilege>().Attach(dp);
                DC.DeleteEntity(dp);
            }
            if (IsAll == true)
            {
                if (DpType == DpTypeEnum.User)
                {
                    DataPrivilege dp = new DataPrivilege();
                    dp.RelateId  = null;
                    dp.UserCode  = Entity.UserCode;
                    dp.TableName = this.Entity.TableName;
                    DC.Set <DataPrivilege>().Add(dp);
                }
                else
                {
                    DataPrivilege dp = new DataPrivilege();
                    dp.RelateId  = null;
                    dp.GroupCode = Entity.GroupCode;
                    dp.TableName = this.Entity.TableName;
                    DC.Set <DataPrivilege>().Add(dp);
                }
            }
            else
            {
                if (SelectedItemsID != null)
                {
                    if (DpType == DpTypeEnum.User)
                    {
                        foreach (var id in SelectedItemsID)
                        {
                            DataPrivilege dp = new DataPrivilege();
                            dp.RelateId  = id;
                            dp.UserCode  = Entity.UserCode;
                            dp.TableName = this.Entity.TableName;
                            DC.Set <DataPrivilege>().Add(dp);
                        }
                    }
                    else
                    {
                        foreach (var id in SelectedItemsID)
                        {
                            DataPrivilege dp = new DataPrivilege();
                            dp.RelateId  = id;
                            dp.GroupCode = Entity.GroupCode;
                            dp.TableName = this.Entity.TableName;
                            DC.Set <DataPrivilege>().Add(dp);
                        }
                    }
                }
            }
            await DC.SaveChangesAsync();

            if (DpType == DpTypeEnum.User)
            {
                await Wtm.RemoveUserCache(Entity.UserCode);
            }
            else
            {
                var userids = DC.Set <FrameworkUserGroup>().Where(x => x.GroupCode == Entity.GroupCode).Select(x => x.UserCode).ToArray();
                await Wtm.RemoveUserCache(userids);
            }
        }