Example #1
0
        /// <summary>
        /// 状态更新
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <R> EnabledAsync(long Id, bool enabled, CurrentUser currentUser)
        {
            var r = await _paymentParameterRep.UpdateAsync <PaymentParameter>(new { Id = Id, Enabled = enabled });

            if (!r)
            {
                return(R.Err("更新失败"));
            }

            if (currentUser != null)
            {
                await _operateLogApp.InsertCusAsync(currentUser, "更新支付参数", JsonHelper.SerializeObject(new { Id = Id, Enabled = enabled }), Id, "PaymentParameters");
            }

            await RemoveCacheAsync(currentUser.Id);

            return(R.Suc());
        }
Example #2
0
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task <R> UpdateStatusAsync(long Id, CurrentUser CurrentUser)
        {
            var model = await GetAsync(Id);

            if (model == null)
            {
                return(R.Err(msg: Id + " 不存在"));
            }
            bool s = model.State == true ? false : true;


            bool r = await _agentRep.UpdateAsync <Agent>(new { Id = Id, state = s });

            if (r == false)
            {
                return(R.Err("修改失败"));
            }

            string logstr = "代理商状态从" + (model.State == true ? "启用到禁用" : "禁用到启用");

            await _operateLogApp.InsertCusAsync(CurrentUser, "代理商状态", logstr, Id, "AgentS");

            return(R.Suc());
        }
Example #3
0
        /// <summary>
        /// 保存角色权限
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="permissionCodes"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        //public async Task<R> AssignPermissionFor(long roleId, string[] permissionCodes, CurrentUser CurrentUser)
        //{
        //    //   Convert.ToInt32("re");
        //    //  string logstr = "";
        //    //try
        //    //{
        //    using (IDbContext context22 = new DbContext(Zconfig.GetMyCat()))
        //    {

        //        context22.Open();
        //        context22.BeginTransaction();

        //        IRoleApp _RoleApp2 = new RoleApp(context22);
        //        IRoleMenuApp _RoleMenuApp2 = new RoleMenuApp(context22);

        //        var rl = await _RoleMenuApp2.GetlistAsync(roleId);
        //        List<RoleMenu> rolePermissions = rl.ToList();
        //        var listadd = new List<string>();
        //        var listdelete = new List<string>();
        //        //using (context)
        //        //{


        //        #region 验证
        //        var role = await _RoleApp2.GetAsync(roleId);
        //        if (role == null)
        //            return R.Err("角色不存在");
        //        #endregion

        //        #region 权限代码
        //        #region MyRegion

        //        if (permissionCodes != null && permissionCodes.Length > 0)
        //        {
        //            //  logstr += "角色权限添加:";

        //            var dellist = rolePermissions.Where(o => !permissionCodes.Contains(o.MenuId)).Select(o => o.MenuId).ToList();


        //            foreach (string s in permissionCodes)
        //            {

        //                var obj = rolePermissions.Where(o => o.MenuId == s).FirstOrDefault();
        //                if (obj == null)
        //                {
        //                    await new RoleMenuRep(context22).InsertAsync(new RoleMenu { Id = Rnd.RndId(), RoleId = roleId, MenuId = s, CreatorTime = System.DateTime.Now });
        //                    //  logstr += s + ";";

        //                    listadd.Add(s);
        //                    //日志
        //                    //   OperateLogBLL.GetInstance().InsertLog(uinfo, "角色权限添加", objRolePermission);
        //                }
        //            }


        //            if (dellist != null && dellist.Count > 0)
        //                foreach (var p in dellist)
        //                {
        //                    listdelete.Add(p);
        //                    await new RoleMenuRep(context22).DeleteListAsync("where `MenuId`=@MenuId  and `RoleId`=@RoleId  ", new RoleMenu { MenuId = p, RoleId = roleId });
        //                }

        //        }
        //        #endregion

        //        else
        //        {
        //            await new RoleMenuRep(context22).DeleteListAsync("where  `RoleId`=@RoleId  ", new RoleMenu { RoleId = roleId });

        //            //  logstr += "删除全部角色权限:";

        //        }
        //        #endregion


        //        //}

        //        #region log
        //        if (listadd.Count > 0 || listdelete.Count > 0)
        //        {
        //            string logstr = "";
        //            if (listadd.Count > 0)
        //            {
        //                logstr += "添加权限:" + string.Join(",", listadd);
        //            }
        //            if (listdelete.Count > 0)
        //            {
        //                logstr += "删除权限:" + string.Join(",", listdelete);
        //            }
        //            await new OperateLogRep(context22).InsertCusAsync<RoleMenu, long>(CurrentUser.UserId, "角色权限", "Saas后台", 0, logstr, CurrentUser.IP);

        //        }
        //        else
        //        {
        //            if (rolePermissions != null && rolePermissions.Count > 0)
        //            {
        //                var listdeall = rolePermissions.Select(o => o.MenuId).ToList();

        //                string logstr = "";

        //                logstr += "删除权限:" + string.Join(",", listdeall);


        //                await new OperateLogRep(context22).InsertCusAsync<RoleMenu, long>(CurrentUser.UserId, "角色权限", "Saas后台", 0, logstr, CurrentUser.IP);

        //            }
        //        }
        //        #endregion


        //        //}
        //        //catch (Exception ex)
        //        //{

        //        //    NLogger.Error(ex, "角色权限保存");
        //        //    return R.Err("保存失败");
        //        //}

        //        context22.Commit();
        //        context22.Close();

        //    }
        //    return R.Suc();
        //}

        #endregion

        #region 保存角色权限
        /// <summary>
        /// 保存角色权限
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="permissionCodes"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task <R> AssignPermissionFor(long roleId, string[] permissionCodes, CurrentUser CurrentUser)
        {
            //  string logstr = "";

            #region 验证
            var role = await _RoleRep.GetAsync(roleId);

            if (role == null)
            {
                return(R.Err("角色不存在"));
            }
            #endregion

            var rl = await GetlistAsync(roleId);

            List <RoleMenu> rolePermissions = rl.ToList();
            var             listadd         = new List <string>();
            var             listdelete      = new List <string>();


            await _cache.RemoveAsync(roleId.ToString(), prefix);

            try
            {
                context.Open();
                context.BeginTransaction();


                #region 权限代码
                #region MyRegion

                if (permissionCodes != null && permissionCodes.Length > 0)
                {
                    //  logstr += "角色权限添加:";

                    var dellist = rolePermissions.Where(o => !permissionCodes.Contains(o.MenuId)).Select(o => o.MenuId).ToList();


                    foreach (string s in permissionCodes)
                    {
                        var obj = rolePermissions.Where(o => o.MenuId == s).FirstOrDefault();
                        if (obj == null)
                        {
                            var rotemenu = new RoleMenu {
                                RoleId = roleId, MenuId = s, CreatorTime = System.DateTime.Now
                            };
                            rotemenu.Id = rotemenu.CreateId();
                            await _RoleMenuRep.InsertAsync(rotemenu);

                            //  logstr += s + ";";

                            listadd.Add(s);
                            //日志
                            //   OperateLogBLL.GetInstance().InsertLog(uinfo, "角色权限添加", objRolePermission);
                        }
                    }


                    if (dellist != null && dellist.Count > 0)
                    {
                        foreach (var p in dellist)
                        {
                            listdelete.Add(p);
                            await _RoleMenuRep.DeleteListAsync("where `MenuId`=@MenuId  and `RoleId`=@RoleId  ", new RoleMenu { MenuId = p, RoleId = roleId });
                        }
                    }
                }
                #endregion

                else
                {
                    await _RoleMenuRep.DeleteListAsync("where  `RoleId`=@RoleId  ", new RoleMenu { RoleId = roleId });

                    //  logstr += "删除全部角色权限:";
                }
                #endregion



                #region log
                if (listadd.Count > 0 || listdelete.Count > 0)
                {
                    string logstr = "";
                    if (listadd.Count > 0)
                    {
                        logstr += "添加权限:" + string.Join(",", listadd);
                    }
                    if (listdelete.Count > 0)
                    {
                        logstr += "删除权限:" + string.Join(",", listdelete);
                    }
                    await _operateLogApp.InsertCusAsync(CurrentUser, "角色权限", logstr, roleId, "RoleMenus");
                }
                else
                {
                    if (rolePermissions != null && rolePermissions.Count > 0)
                    {
                        var listdeall = rolePermissions.Select(o => o.MenuId).ToList();

                        string logstr = "";

                        logstr += "删除权限:" + string.Join(",", listdeall);


                        await _operateLogApp.InsertCusAsync <RoleMenu>(CurrentUser, "角色权限", logstr);
                    }
                }
                #endregion
                context.Commit();
            }
            catch (Exception ex)
            {
                //   NLogger.Error(ex, "角色权限保存");
                return(R.Err("保存失败"));
            }
            return(R.Suc());
        }