Exemple #1
0
        public async Task <ResultCrmDb> AddUserToRoleAsync(RoleLinkArgs args)//(IEnumerable<int> idUser, int idRole)
        {
            var result = new ResultCrmDb();

            try
            {
                var link = new List <UserLinkRole>();
                foreach (var id in args.IdUsers)//idUser)
                {
                    var add = await _crmDbContext.userlinkrole.FirstOrDefaultAsync(l => l.UserRoleId == args.IdRole& l.UserId == id);

                    if (add != null)
                    {
                        throw new Exception("К роли уже добавлен данный пользователь.");
                    }
                    link.Add(new UserLinkRole()
                    {
                        UserId = id, UserRoleId = args.IdRole
                    });
                }
                await _crmDbContext.userlinkrole.AddRangeAsync(link);// AddAsync(link);

                await _crmDbContext.SaveChangesAsync();
            }
            catch (Exception e)
            {
                result.AddError("", e.Message);
            }
            return(result);
        }
Exemple #2
0
 public async Task <IActionResult> AddUserToRole(RoleLinkArgs args)               //(IEnumerable<int> idUser, int idRole)
 {
     return(Tools.CreateResult(true, "", await _roles.AddUserToRoleAsync(args))); //(idUser,idRole));
 }