Ejemplo n.º 1
0
        public TRole RoleSingle(string loginKey, ref ErrorInfo err, int id)
        {
            if (!GlobalFun.UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(null);
            }
            using (DBEntities db = new DBEntities())
            {
                var        reEnt   = db.fa_role.SingleOrDefault(x => x.ID == id);
                TRole      tmp     = new TRole();
                IList <KV> allPara = new List <KV>();

                if (reEnt != null)
                {
                    tmp = Mapper.Map <TRole>(reEnt);
                }
                return(tmp);
            }
        }
Ejemplo n.º 2
0
        public async Task <ApiRequestResult> AddAsync([FromBody] RoleParam param)
        {
            try
            {
                var add = new TRole
                {
                    RoleName    = param.RoleName,
                    ParentId    = param.ParentId,
                    Description = param.Description,
                };
                await _iTRoleRepository.AddAsync(add);

                //_unitOfWork.SaveChanges();
                return(ApiRequestResult.Success("添加成功"));
            }
            catch (Exception ex)
            {
                return(ApiRequestResult.Error(ex.Message));
            }
        }
Ejemplo n.º 3
0
 public override string[] GetRolesForUser(string username)
 {
     string[] role = new string[] { };
     using (ToyStoreAccessContext db = new ToyStoreAccessContext())
     {
         // Получаем пользователя
         TBuyer user = db.TBuyers.FirstOrDefault(u => u.Firstname == username);
         if (user != null)
         {
             // получаем роль
             TRole userRole = db.TRoles.Find(user.C_TRole);
             if (userRole != null)
             {
                 role = new string[] { userRole.Name }
             }
             ;
         }
     }
     return(role);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="roleAddDto"></param>
        /// <returns></returns>
        public int AddRole(RoleAddDto roleAddDto)
        {
            var   systemCode = IocUnity.Get <RepositorySystem>().GetCode(roleAddDto.SystemId);
            TRole role       = new TRole {
                Id           = IdentityHelper.NewSequentialGuid().ToString("N"),
                OriginalCode = string.IsNullOrEmpty(roleAddDto.Code)?null:roleAddDto.Code,
                Code         = string.IsNullOrEmpty(roleAddDto.Code) ? null : $"{systemCode}-{roleAddDto.Code}",
                Name         = roleAddDto.Name,
                State        = roleAddDto.State,
                SystemId     = roleAddDto.SystemId,
                ItemId       = roleAddDto.ItemId,
                JsonItem     = roleAddDto.JsonItem
            };

            if (roleAddDto.Items.IsNullOrEmpty() && roleAddDto.Items.Count > 0)
            {
                IList <TRelationRoleItem> roleItems = new List <TRelationRoleItem>();
                foreach (var d in roleAddDto.Items)
                {
                    TRelationRoleItem relation = new TRelationRoleItem
                    {
                        Id         = IdentityHelper.NewSequentialGuid().ToString("N"),
                        RoleId     = role.Id,
                        ItemId     = d,
                        CreateTime = DateTime.Now,
                        UpdateTime = null
                    };
                    roleItems.Add(relation);
                }

                int count = 0;
                IocUnity.Get <BaseData <TRelationRoleItem> >().DapperRepository.ExcuteTransaction(c =>
                {
                    count = IocUnity.Get <RepositoryRole>().Insert(role);
                    IocUnity.Get <BaseData <TRelationRoleItem> >().Insert(roleItems);
                });
                return(count);
            }

            return(IocUnity.Get <RepositoryRole>().Insert(role));
        }
Ejemplo n.º 5
0
        public override bool IsUserInRole(string username, string roleName)
        {
            bool outputResult = false;

            // Находим пользователя
            using (ToyStoreAccessContext db = new ToyStoreAccessContext())
            {
                // Получаем пользователя
                TBuyer user = db.TBuyers.FirstOrDefault(u => u.Firstname == username);
                if (user != null)
                {
                    // получаем роль
                    TRole userRole = db.TRoles.Find(user.C_TRole);
                    //сравниваем
                    if (userRole != null && userRole.Name == roleName)
                    {
                        outputResult = true;
                    }
                }
            }
            return(outputResult);
        }
        public ActionResult Save(TRole c)
        {
            string message = "";
            bool   status  = false;

            if (ModelState.IsValid)
            {
                using (Entities1 dc = new Entities1()) {
                    if (c.intRoleID > 0)
                    {
                        var v = dc.TRoles.Where(a => a.intRoleID.Equals(c.intRoleID)).FirstOrDefault();
                        if (v != null)
                        {
                            v.strRoleName = c.strRoleName;
                        }
                        else
                        {
                            return(HttpNotFound());
                        }
                    }
                    else
                    {
                        dc.TRoles.Add(c);
                    }
                    dc.SaveChanges();
                    status  = true;
                    message = "Data Is Successfully Saved.";
                }
            }
            else
            {
                message = "Error! Please try again.";
            }

            return(new JsonResult {
                Data = new { status = status, message = message }
            });
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 修改角色
        /// </summary>
        /// <param name="tRole">角色信息</param>
        /// <param name="operational">操作信息</param>
        /// <returns>结果</returns>
        public static Result UpdateRole(TRole tRole, Operational operational)
        {
            Result result = new Result();

            try
            {
                using (var roleRepository = DbContext.CreateIRoleRepository())
                {
                    var mRole = tRole.ToMRole();
                    roleRepository.Update(mRole);
                }

                result.IsSucceed = true;
                result.Message   = "修改成功";
            }
            catch (Exception ex)
            {
                result.IsSucceed = false;
                result.Message   = Const.ErrorMessage;
                LogService.WriteLog(ex, "修改角色");
            }
            return(result);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// 角色修改
 /// </summary>
 /// <param name="tRole">角色信息</param>
 public void Update(TRole tRole)
 {
     this.RoleName        = tRole.RoleName;
     this.RoleDescription = tRole.RoleDescription;
 }
Ejemplo n.º 9
0
 public RoleClaimsAssociation(TRole role)
 {
     Role   = role;
     Claims = new HashSet <Claim>();
 }
 public void RemoveRole(TRole role)
 {
     role.Enabled = false;
     Context.TRole.Update(role);
     Context.SaveChanges();
 }
Ejemplo n.º 11
0
 partial void InsertTRole(TRole instance);
Ejemplo n.º 12
0
 /// <summary>
 /// Deletes a role from the store as an asynchronous operation.
 /// </summary>
 /// <param name="role">The role to delete from the store.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
 /// <returns>A <see cref="Task{TResult}"/> that represents the <see cref="IdentityResult"/> of the asynchronous query.</returns>
 public abstract Task <IdentityResult> DeleteAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken));
Ejemplo n.º 13
0
 /// <summary>
 /// Creates a entity representing a role claim.
 /// </summary>
 /// <param name="role">The associated role.</param>
 /// <param name="claim">The associated claim.</param>
 /// <returns>The role claim entity.</returns>
 protected virtual TRoleClaim CreateRoleClaim(TRole role, Claim claim)
 => new TRoleClaim
 {
     RoleId = role.Id, ClaimType = claim.Type, ClaimValue = claim.Value
 };
Ejemplo n.º 14
0
 /// <summary>
 /// Removes the <paramref name="claim"/> given from the specified <paramref name="role"/>.
 /// </summary>
 /// <param name="role">The role to remove the claim from.</param>
 /// <param name="claim">The claim to remove from the role.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
 /// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns>
 public abstract Task RemoveClaimAsync(TRole role, Claim claim, CancellationToken cancellationToken = default(CancellationToken));
Ejemplo n.º 15
0
 /// <summary>
 /// Get the claims associated with the specified <paramref name="role"/> as an asynchronous operation.
 /// </summary>
 /// <param name="role">The role whose claims should be retrieved.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
 /// <returns>A <see cref="Task{TResult}"/> that contains the claims granted to a role.</returns>
 public abstract Task <IList <Claim> > GetClaimsAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken));
Ejemplo n.º 16
0
        public async Task ReadAsync(TProtocol iprot,
                                    CancellationToken cancellationToken)
        {
            iprot.IncrementRecursionDepth();

            try
            {
                TField field;
                await iprot.ReadStructBeginAsync(cancellationToken);

                while (true)
                {
                    field = await iprot.ReadFieldBeginAsync(cancellationToken);

                    if (field.Type == TType.Stop)
                    {
                        break;
                    }

                    switch (field.ID)
                    {
                    case 1:
                        if (field.Type == TType.Bool)
                        {
                            Read_only = await iprot.ReadBoolAsync(cancellationToken);
                        }
                        else
                        {
                            await TProtocolUtil.SkipAsync(iprot,
                                                          field.Type,
                                                          cancellationToken);
                        }

                        break;

                    case 2:
                        if (field.Type == TType.String)
                        {
                            Version = await iprot.ReadStringAsync(cancellationToken);
                        }
                        else
                        {
                            await TProtocolUtil.SkipAsync(iprot,
                                                          field.Type,
                                                          cancellationToken);
                        }

                        break;

                    case 3:
                        if (field.Type == TType.Bool)
                        {
                            Rendering_enabled = await iprot.ReadBoolAsync(cancellationToken);
                        }
                        else
                        {
                            await TProtocolUtil.SkipAsync(iprot,
                                                          field.Type,
                                                          cancellationToken);
                        }

                        break;

                    case 4:
                        if (field.Type == TType.I64)
                        {
                            Start_time = await iprot.ReadI64Async(cancellationToken);
                        }
                        else
                        {
                            await TProtocolUtil.SkipAsync(iprot,
                                                          field.Type,
                                                          cancellationToken);
                        }

                        break;

                    case 5:
                        if (field.Type == TType.String)
                        {
                            Edition = await iprot.ReadStringAsync(cancellationToken);
                        }
                        else
                        {
                            await TProtocolUtil.SkipAsync(iprot,
                                                          field.Type,
                                                          cancellationToken);
                        }

                        break;

                    case 6:
                        if (field.Type == TType.String)
                        {
                            Host_name = await iprot.ReadStringAsync(cancellationToken);
                        }
                        else
                        {
                            await TProtocolUtil.SkipAsync(iprot,
                                                          field.Type,
                                                          cancellationToken);
                        }

                        break;

                    case 7:
                        if (field.Type == TType.Bool)
                        {
                            Poly_rendering_enabled = await iprot.ReadBoolAsync(cancellationToken);
                        }
                        else
                        {
                            await TProtocolUtil.SkipAsync(iprot,
                                                          field.Type,
                                                          cancellationToken);
                        }

                        break;

                    case 8:
                        if (field.Type == TType.I32)
                        {
                            Role = (TRole)await iprot.ReadI32Async(cancellationToken);
                        }
                        else
                        {
                            await TProtocolUtil.SkipAsync(iprot,
                                                          field.Type,
                                                          cancellationToken);
                        }

                        break;

                    default:
                        await TProtocolUtil.SkipAsync(iprot,
                                                      field.Type,
                                                      cancellationToken);

                        break;
                    }

                    await iprot.ReadFieldEndAsync(cancellationToken);
                }

                await iprot.ReadStructEndAsync(cancellationToken);
            }
            finally
            {
                iprot.DecrementRecursionDepth();
            }
        }
 public void AddRole(TRole role)
 {
     Context.TRole.Add(role);
     Context.SaveChanges();
 }
Ejemplo n.º 18
0
 partial void UpdateTRole(TRole instance);
 public TRole UpdateRole(TRole role)
 {
     Context.TRole.Update(role);
     Context.SaveChanges();
     return(Context.TRole.Find(role.TRoleId));
 }
Ejemplo n.º 20
0
 partial void DeleteTRole(TRole instance);
 public Task <IdentityResult> ValidateAsync(RoleManager <TRole> manager, TRole role)
 {
     return(Task.FromResult(IdentityResult.Failed(ErrorMessage)));
 }
Ejemplo n.º 22
0
        public bool RoleSave(string loginKey, ref ErrorInfo err, TRole inEnt, IList <string> allPar = null)
        {
            if (!GlobalFun.UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(false);
            }
            using (DBEntities db = new DBEntities())
            {
                try
                {
                    var  ent   = db.fa_role.SingleOrDefault(a => a.ID == inEnt.ID);
                    bool isAdd = false;
                    if (ent == null)
                    {
                        isAdd  = true;
                        ent    = Mapper.Map <fa_role>(inEnt);
                        ent.ID = Fun.GetSeqID <fa_role>();
                    }
                    else
                    {
                        ent = Fun.ClassToCopy <ProInterface.Models.ROLE, fa_role>(inEnt, ent, allPar);
                    }

                    ent.fa_module.Clear();
                    if (!string.IsNullOrEmpty(inEnt.ModuleAllStr))
                    {
                        IList <int> moduleID = inEnt.ModuleAllStr.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                        ent.fa_module = db.fa_module.Where(x => moduleID.Contains(x.ID)).ToList();
                    }
                    if (!string.IsNullOrEmpty(inEnt.RoleConfigsStr))
                    {
                        inEnt.RoleConfigs = JSON.EncodeToEntity <IList <ROLE_CONFIG> >(inEnt.RoleConfigsStr);
                        foreach (var t in inEnt.RoleConfigs)
                        {
                            var cfg = ent.fa_role_config.SingleOrDefault(x => x.NAME == t.NAME);
                            if (cfg == null)
                            {
                                ent.fa_role_config.Add(new fa_role_config
                                {
                                    NAME    = t.NAME,
                                    ROLE_ID = ent.ID,
                                    VALUE   = t.VALUE
                                });
                            }
                            else
                            {
                                cfg.VALUE = t.VALUE;
                            }
                        }
                    }
                    foreach (var t in ent.fa_role_config.ToList())
                    {
                        if (inEnt.RoleConfigs.SingleOrDefault(x => x.NAME == t.NAME) == null)
                        {
                            db.fa_role_config.Remove(t);
                        }
                    }

                    if (isAdd)
                    {
                        db.fa_role.Add(ent);
                    }
                    Fun.DBEntitiesCommit(db, ref err);

                    GlobalFun.UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit);
                    return(true);
                }
                catch (DbEntityValidationException e)
                {
                    err.IsError = true;
                    err.Message = e.Message;
                    err.Excep   = e;
                    return(false);
                }
            }
        }