public IActionResult Edit(RoleViewModels roleModel)
        {
            RoleContext roleContext = new RoleContext(connectionString);

            roleModel.Region = roles();
            //Rajouter des contrôles dynamiques

            //if(bugModel.IdentifiantSeverite == 2)
            //{
            //    ModelState.AddModelError("IdentifiantSeverite", "Ne peut être égal à 2");
            //}

            IActionResult retour = null;

            if (ModelState.IsValid)
            {
                Role role = new Role();

                role.Identifiant = (int)roleModel.Identifiant;
                role.Nom         = roleModel.Nom;


                bool isOK = roleContext.Update(role);
                retour = RedirectToAction("Index");
            }
            else
            {
                retour = View(roleModel);
            }

            return(retour);
        }
Esempio n. 2
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            UserContext.Build(builder);
            RoleContext.Build(builder);
        }
Esempio n. 3
0
        /// <summary>
        /// 下移角色。
        /// </summary>
        /// <param name="role">角色实例。</param>
        /// <param name="cancellationToken">取消标识。</param>
        /// <returns>返回移动结果。</returns>
        public virtual async Task <bool> MoveDownAsync(TRole role, CancellationToken cancellationToken = default)
        {
            if (role == null)
            {
                throw new ArgumentNullException(nameof(role));
            }
            // ReSharper disable once SuspiciousTypeConversion.Global
            if (role is IRoleEventHandler <TRole> handler)
            {
                return(await RoleContext.BeginTransactionAsync(async db =>
                {
                    if (!await db.MoveDownAsync(role.Id, x => x.RoleLevel, MoveExpression(role), cancellationToken))
                    {
                        return false;
                    }

                    if (!await handler.OnUpdateAsync(db, cancellationToken))
                    {
                        return false;
                    }

                    return true;
                }, cancellationToken : cancellationToken));
            }
            return(await RoleContext.MoveDownAsync(role.Id, x => x.RoleLevel, MoveExpression(role), cancellationToken));
        }
Esempio n. 4
0
        /// <summary>
        /// 下移角色。
        /// </summary>
        /// <param name="role">角色实例。</param>
        /// <returns>返回移动结果。</returns>
        public virtual bool MoveDown(TRole role)
        {
            if (role == null)
            {
                throw new ArgumentNullException(nameof(role));
            }
            // ReSharper disable once SuspiciousTypeConversion.Global
            if (role is IRoleEventHandler <TRole> handler)
            {
                return(RoleContext.BeginTransaction(db =>
                {
                    if (!db.MoveDown(role.Id, x => x.RoleLevel, MoveExpression(role)))
                    {
                        return false;
                    }

                    if (!handler.OnUpdate(db))
                    {
                        return false;
                    }

                    return true;
                }));
            }
            return(RoleContext.MoveDown(role.Id, x => x.RoleLevel, MoveExpression(role)));
        }
Esempio n. 5
0
 /// <summary>
 /// 更新用户角色。
 /// </summary>
 /// <param name="role">用户角色实例。</param>
 /// <returns>返回角色更新结果。</returns>
 public virtual IdentityResult Update(TRole role)
 {
     if (role == null)
     {
         throw new ArgumentNullException(nameof(role));
     }
     // ReSharper disable once SuspiciousTypeConversion.Global
     if (role is IRoleEventHandler <TRole> handler)
     {
         if (RoleContext.BeginTransaction(db =>
         {
             if (!handler.OnUpdate(db))
             {
                 return(false);
             }
             if (!db.Update(role))
             {
                 return(false);
             }
             return(true);
         }))
         {
             return(IdentityResult.Success);
         }
     }
     else if (RoleContext.Update(role))
     {
         return(IdentityResult.Success);
     }
     return(IdentityResult.Failed(ErrorDescriber.DefaultError()));
 }
Esempio n. 6
0
        // [Route("api/FetchEmployeeData/UpdateEmployees")]
        public int UpdateRole([FromBody] RoleAttribute role)
        {
            RoleContext context = HttpContext.RequestServices.GetService(typeof(RMG.Models.RoleContext)) as RoleContext;

            context.UpdateRole(role);
            return(1);
        }
Esempio n. 7
0
        /// <summary>
        /// 添加用户角色。
        /// </summary>
        /// <param name="role">用户角色实例。</param>
        /// <param name="cancellationToken">取消标识。</param>
        /// <returns>返回角色添加结果。</returns>
        public override async Task <IdentityResult> CreateAsync(TRole role, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (role == null)
            {
                throw new ArgumentNullException(nameof(role));
            }
            role.RoleLevel = await GetMaxRoleLevelAsync(role) + 1;//获取当前角色等级

            // ReSharper disable once SuspiciousTypeConversion.Global
            if (role is IRoleEventHandler <TRole> handler)
            {
                if (await RoleContext.BeginTransactionAsync(async db =>
                {
                    if (!await db.CreateAsync(role, cancellationToken))
                    {
                        return(false);
                    }
                    if (!await handler.OnCreatedAsync(db, cancellationToken))
                    {
                        return(false);
                    }
                    return(true);
                }, cancellationToken: cancellationToken))
                {
                    return(IdentityResult.Success);
                }
            }
            else if (await RoleContext.CreateAsync(role, cancellationToken))
            {
                return(IdentityResult.Success);
            }
            return(IdentityResult.Failed(ErrorDescriber.DefaultError()));
        }
Esempio n. 8
0
        //此SellOrderService.cs类由代码生成器生成,默认是没有任何代码,如果需要写业务代码,请在此类中实现
        //如果默认的增、删、改、查、导入、导出、审核满足不了业务,请参考下面的方法进行业务代码扩展(扩展代码是对ServiceFunFilter.cs的实现)

        //==============常用操作=======================
        //访问数据库
        //1、使用 repository. 使用原生EF  repository.DbContext
        //    repository.DbContext.Set<Sys_User>().Find()
        //    SellOrderRepository.Instance.Find()
        //    SellOrderListRepository.Instance.Find()
        //    DBServerProvider.SqlDapper
        //    DBServerProvider.DbContext
        //    以上方式都能访问数据库

        //2、使用EF事务 repository.DbContextBeginTransaction或 SellOrderRepository.Instance.DbContextBeginTransaction

        //3、Dapper 使用:repository.DapperContext , DBServerProvider.SqlDapper

        //4、获取Memory/Redis对象
        // base.CacheContext
        // AutofacContainerModule.GetService<ICacheService>()
        // VOL.Core.Utilities.HttpContext.Current.RequestServices
        // VOL.Core.Utilities.HttpContext.Current.RequestServices.GetService(typeof(ICacheService))

        //5、使用HttpContext:VOL.Core.Utilities.HttpContext

        //获取用户信息/权限
        //6、UserContext.Current/UserContext.Current.Permissions

        //7、获取配置信息appsettings.json
        // AppSetting   /    AppSetting.Configuration

        //8、查看权限验证规则 Vol.Core->Filters文件夹下权限控制类

        //9、其他封装了大量的常用扩展方法Vol.Core->Extensions文件夹下(如:字符串扩展、表达式扩展、实体验证(EntityProperties)扩展方法)

        //10、实体数据合法性校验(ServiceBase.cs有大量实体校验示例)
        //SellOrder order = new SellOrder();
        //校验指定字段x.TranNo, x.Auditor的类型、长度等合法性
        //order.ValidationEntity(x => new { x.TranNo, x.Auditor});

        //11、获取实体的配置信息,如:字段中文名称、最大长度、字段主键等信息
        // Type type = typeof(SellOrder);
        //获取主键字段
        // PropertyInfo key = type.GetKeyProperty();
        //获取主键字段名
        // type.GetKeyName();
        //判断某个字段是否有EditableAttribute属性
        //  key.ContainsCustomAttributes(typeof(EditableAttribute));

        //12、常用工具类Vol.Core->Utilities

        //写入日志 : Logger.Info();

        //其中有一部分真实扩展代码实现:Partial->Sys_UserService.cs  , Partial->Sys_RoleService ,Partial->Sys_DictionaryService


        public override PageGridData <SellOrder> GetPageData(PageDataOptions options)
        {
            //查询前可以自已设定查询表达式的条件
            QueryRelativeExpression = (IQueryable <SellOrder> queryable) =>
            {
                //当前用户只能操作自己(与下级角色)创建的数据,如:查询、删除、修改等操作
                IQueryable <int> userQuery = RoleContext.GetCurrentAllChildUser();
                queryable = queryable.Where(x => x.CreateID == UserContext.Current.UserId || userQuery.Contains(x.CreateID ?? 0));
                return(queryable);
            };

            //此处是从前台提交的原生的查询条件,这里可以自己过滤
            QueryRelativeList = (List <SearchParameters> parameters) =>
            {
            };
            //指定多个字段进行排序
            OrderByExpression = x => new Dictionary <object, QueryOrderBy>()
            {
                { x.CreateDate, QueryOrderBy.Desc },
                { x.SellNo, QueryOrderBy.Desc }
            };

            //查询完成后,在返回页面前可对查询的数据进行操作
            GetPageDataOnExecuted = (PageGridData <SellOrder> grid) =>
            {
                //可对查询的结果的数据操作
                List <SellOrder> sellOrders = grid.rows;
            };
            return(base.GetPageData(options));
        }
        public IActionResult Create(RoleViewModels roleModel)
        {
            RoleContext roleContext = new RoleContext(connectionString);

            roleModel.Region = roles();

            IActionResult retour = null;

            if (ModelState.IsValid)
            {
                Role role = new Role();

                role.Identifiant = roleModel.Identifiant;
                role.Nom         = roleModel.Nom;



                bool isOK = roleContext.Insert(role);
                retour = RedirectToAction("Index");
            }
            else
            {
                retour = View(roleModel);
            }

            return(retour);
        }
Esempio n. 10
0
 /// <summary>
 /// 获取用户角色列表。
 /// </summary>
 /// <param name="userId">用户Id。</param>
 /// <returns>返回角色列表。</returns>
 public virtual IEnumerable <TRole> GetRoles(int userId)
 {
     return(RoleContext.AsQueryable()
            .Select()
            .InnerJoin <TUserRole>((r, ur) => r.RoleId == ur.RoleId)
            .Where <TUserRole>(x => x.UserId == userId)
            .AsEnumerable());
 }
Esempio n. 11
0
 /// <summary>
 /// 获取用户角色列表。
 /// </summary>
 /// <param name="userId">用户Id。</param>
 /// <param name="cancellationToken">取消标识。</param>
 /// <returns>返回角色列表。</returns>
 public virtual Task <IEnumerable <TRole> > GetRolesAsync(int userId, CancellationToken cancellationToken = default)
 {
     return(RoleContext.AsQueryable()
            .Select()
            .InnerJoin <TUserRole>((r, ur) => r.RoleId == ur.RoleId)
            .Where <TUserRole>(x => x.UserId == userId)
            .AsEnumerableAsync(cancellationToken));
 }
Esempio n. 12
0
 private WebResponseContent RemoveCache(WebResponseContent webResponse)
 {
     if (webResponse.Status)
     {
         RoleContext.Refresh();
     }
     return(webResponse);
 }
Esempio n. 13
0
        //  [Route("api/RoleAttribute/Create")]
        public int Create([FromBody] List <RoleAttribute> Role)
        {
            RoleContext context = HttpContext.RequestServices.GetService(typeof(RMG.Models.RoleContext)) as RoleContext;

            foreach (RMG.Models.RoleAttribute e in Role)
            {
                context.AddRole(e);
            }
            return(1);
        }
Esempio n. 14
0
        /// <summary>
        /// 获取用户的所有角色。
        /// </summary>
        /// <param name="user">用户实例对象。</param>
        /// <param name="cancellationToken">取消标志。</param>
        /// <returns>返回当前用户的所有角色列表。</returns>
        public override async Task <IList <string> > GetRolesAsync(TUser user, CancellationToken cancellationToken = default)
        {
            var roles = await RoleContext.AsQueryable()
                        .Select(x => x.Name)
                        .InnerJoin <TUserRole>((r, ur) => r.RoleId == ur.RoleId)
                        .Where <TUserRole>(x => x.UserId == user.UserId)
                        .AsEnumerableAsync(reader => reader.GetString(0), cancellationToken);

            return(roles.ToList());
        }
Esempio n. 15
0
        //查询
        public override PageGridData <SellOrder> GetPageData(PageDataOptions options)
        {
            //2020.08.15
            //设置原生查询的sql语句,这里必须返回select * 表所有字段
            //(先内部过滤数据,内部调用EF方法FromSqlRaw,自己写的sql注意sql注入的问题),不会影响界面上提交的查询

            /*
             *  string date = DateTime.Now.AddYears(-10).ToString("yyyy-MM-dd");
             *  QuerySql = $@"select * from SellOrder
             *                         where createdate>'{date}'
             *                             and  Order_Id in (select Order_Id from SellOrderList)
             *                             and CreateID={UserContext.Current.UserId}";
             */

            //2020.08.15
            //此处与上面QuerySql只需要实现其中一个就可以了
            //查询前可以自已设定查询表达式的条件
            QueryRelativeExpression = (IQueryable <SellOrder> queryable) =>
            {
                //当前用户只能操作自己(与下级角色)创建的数据,如:查询、删除、修改等操作
                IQueryable <int> userQuery = RoleContext.GetCurrentAllChildUser();
                queryable = queryable.Where(x => x.CreateID == UserContext.Current.UserId || userQuery.Contains(x.CreateID ?? 0));
                return(queryable);
            };

            //此处是从前台提交的原生的查询条件,这里可以自己过滤
            QueryRelativeList = (List <SearchParameters> parameters) =>
            {
            };
            //指定多个字段进行排序
            OrderByExpression = x => new Dictionary <object, QueryOrderBy>()
            {
                { x.CreateDate, QueryOrderBy.Desc },
                { x.SellNo, QueryOrderBy.Desc }
            };

            //查询完成后,在返回页面前可对查询的数据进行操作
            GetPageDataOnExecuted = (PageGridData <SellOrder> grid) =>
            {
                //可对查询的结果的数据操作
                List <SellOrder> sellOrders = grid.rows;
            };
            //查询table界面显示求和
            SummaryExpress = (IQueryable <SellOrder> queryable) =>
            {
                return(queryable.GroupBy(x => 1).Select(x => new
                {
                    //AvgPrice注意大小写和数据库字段大小写一样
                    Qty = x.Sum(o => o.Qty).ToString("f2")
                })
                       .FirstOrDefault());
            };

            return(base.GetPageData(options));
        }
Esempio n. 16
0
        public RoleGame Update(RoleGame rg, RoleContext context)
        {
            RoleGame newrg = this.Convert(context);

            rg.Players       = newrg.Players;
            rg.DungeonMaster = newrg.DungeonMaster;
            rg.Game          = newrg.Game;
            rg.Name          = newrg.Name;
            rg.Dificultty    = newrg.Dificultty;
            return(rg);
        }
Esempio n. 17
0
        public IActionResult Delete(int id)
        {
            RoleContext roleContext = new RoleContext(connectionString);
            bool        isOK        = roleContext.Delete(id);

            DeleteRoleViewModels model = new DeleteRoleViewModels();

            model.IsDeleted = isOK;

            return(View(model));
        }
Esempio n. 18
0
        public Player Update(Player p, RoleContext context)
        {
            Player newP = this.Convert(context);

            p.Name          = newP.Name;
            p.Mail          = newP.Mail;
            p.Nickname      = newP.Nickname;
            p.PlayedGames   = newP.PlayedGames;
            p.DirectedGames = newP.DirectedGames;
            return(p);
        }
Esempio n. 19
0
        public RoleController(RoleContext context)
        {
            this.Context = context;

            if (this.Context.Roles.Count() == 0)
            {
                this.Context.Roles.Add(new Role
                {
                });

                this.Context.SaveChanges();
            }
        }
Esempio n. 20
0
        /// <summary>
        /// 更新用户角色。
        /// </summary>
        /// <param name="role">用户角色实例。</param>
        /// <returns>返回角色更新结果。</returns>
        public virtual IdentityResult Update(TRole role)
        {
            if (role == null)
            {
                throw new ArgumentNullException(nameof(role));
            }

            if (RoleContext.Update(role))
            {
                return(IdentityResult.Success);
            }

            return(IdentityResult.Failed(ErrorDescriber.DefaultError()));
        }
Esempio n. 21
0
        private List <SelectListItem> roles()
        {
            RoleContext roleContext = new RoleContext(connectionString);

            List <Role>           roles          = roleContext.GetAll();
            List <SelectListItem> selectListItem = new List <SelectListItem>();

            foreach (Role role in roles)
            {
                selectListItem.Add(new SelectListItem(role.Nom, role.Identifiant.ToString()));
            }

            return(selectListItem);
        }
Esempio n. 22
0
        public IActionResult Edit(int id)
        {
            RoleContext    roleContext = new RoleContext(connectionString);
            Role           role        = roleContext.Get(id);
            RoleViewModels roleModel   = new RoleViewModels();

            roleModel.Identifiant = role.Identifiant;
            roleModel.Nom         = role.Nom;


            roleModel.Region = roles();

            return(View(roleModel));
        }
Esempio n. 23
0
        public RoleVO FindAdminRole(RoleContext ctx)
        {
            RoleVO role = null;

            try
            {
                role = ctx.Role.Where(s => s.Name == "Admin").SingleOrDefault();
            }
            catch
            {
                throw;
            }
            return(role);
        }
Esempio n. 24
0
        /// <summary>
        /// 添加角色。
        /// </summary>
        /// <param name="role">角色实例。</param>
        /// <returns>返回添加结果。</returns>
        public virtual IdentityResult Create(TRole role)
        {
            if (role == null)
            {
                throw new ArgumentNullException(nameof(role));
            }
            role.RoleLevel = GetMaxRoleLevel(role) + 1;//获取当前角色等级

            if (RoleContext.Create(role))
            {
                return(IdentityResult.Success);
            }

            return(IdentityResult.Failed(ErrorDescriber.DefaultError()));
        }
Esempio n. 25
0
        /// <summary>
        /// 删除用户角色。
        /// </summary>
        /// <param name="role">用户角色实例。</param>
        /// <param name="cancellationToken">取消标识。</param>
        /// <returns>返回角色删除结果。</returns>
        public override async Task <IdentityResult> DeleteAsync(TRole role, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (role == null)
            {
                throw new ArgumentNullException(nameof(role));
            }

            if (await RoleContext.DeleteAsync(role.Id, cancellationToken))
            {
                return(IdentityResult.Success);
            }

            return(IdentityResult.Failed(ErrorDescriber.DefaultError()));
        }
Esempio n. 26
0
        public IActionResult Index()
        {
            ViewBag.Title = "Rôles";

            RoleIndexViewModels model = new RoleIndexViewModels();

            model.Title = "Les Rôles sont :";

            RoleContext roleContext = new RoleContext(connectionString);
            List <Role> roles       = roleContext.GetAll();

            model.Roles = roles;

            return(View(model));
        }
        /// <summary>
        /// 获取解决的数据源,只能看到自己与下级所有角色
        /// </summary>
        /// <param name="context"></param>
        /// <param name="originalSql"></param>
        /// <returns></returns>
        public static string GetRolesSql(string originalSql)
        {
            if (UserContext.Current.IsSuperAdmin)
            {
                return(originalSql);
            }
            int        currnetRoleId = UserContext.Current.RoleId;
            List <int> roleIds       = RoleContext.GetAllChildrenIds(currnetRoleId);

            roleIds.Add(currnetRoleId);
            string sql = $@"SELECT Role_Id as 'key',RoleName as 'value' FROM Sys_Role 
                           WHERE Enable=1  and Role_Id in ({string.Join(',', roleIds)})";

            return(sql);
        }
Esempio n. 28
0
        /// <summary>
        /// 添加用户角色。
        /// </summary>
        /// <param name="role">用户角色实例。</param>
        /// <param name="cancellationToken">取消标识。</param>
        /// <returns>返回角色添加结果。</returns>
        public override async Task <IdentityResult> CreateAsync(TRole role, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (role == null)
            {
                throw new ArgumentNullException(nameof(role));
            }
            role.RoleLevel = await GetMaxRoleLevelAsync(role) + 1;//获取当前角色等级

            if (await RoleContext.CreateAsync(role, cancellationToken))
            {
                return(IdentityResult.Success);
            }

            return(IdentityResult.Failed(ErrorDescriber.DefaultError()));
        }
Esempio n. 29
0
        public RoleVO GetRoleById(int id)
        {
            RoleVO model = new RoleVO();

            try
            {
                using (var ctx = new RoleContext())
                {
                    IRoleDA da = new RoleDA();
                    model = da.FindRoleById(ctx, id);
                }
            }catch
            {
                throw;
            }
            return(model);
        }
Esempio n. 30
0
        public RoleVO FindRoleById(RoleContext ctx, int id)
        {
            RoleVO role = new RoleVO();

            try
            {
                var query = (from r in ctx.Role
                             where r.Id == id
                             select new { r.Name }).Single();
                role.Id   = id;
                role.Name = FillItemForDatabase.FillItem(query.Name);
            }
            catch
            {
                throw;
            }
            return(role);
        }
Esempio n. 31
0
 public void Dispose()
 {
     if (userContext != null)
         userContext.Dispose();
     userContext = null;
 }