Esempio n. 1
0
 public UserViewModel(INventoryUser user)
 {
     Id          = user.Id;
     UserName    = user.UserName;
     Email       = user.Email;
     Name        = user.Name;
     Surname     = user.Surname;
     Patronymic  = user.Patronymic;
     StaffNumber = user.StaffNumber;
     Roles       = user.Roles;
 }
Esempio n. 2
0
        public async Task <Result> UpdateUserAsync(INventoryUser user, IList <string> selectedRoles = null)
        {
            var identityUser = await _userManager.Users.FirstOrDefaultAsync(x => x.Id == user.Id);

            identityUser.Name        = user.Name;
            identityUser.Surname     = user.Surname;
            identityUser.Patronymic  = user.Patronymic;
            identityUser.StaffNumber = user.StaffNumber;
            identityUser.Email       = user.Email;
            var result = await _userManager.UpdateAsync(identityUser);

            if (selectedRoles != null)
            {
                await UpdateRoles(user.Id, selectedRoles);
            }
            return(new Result(result.Succeeded));
        }
Esempio n. 3
0
        public async Task <Result> CreateUserAsync(INventoryUser user, string password)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            var newUser = new NventoryUser()
            {
                Id          = user.Id,
                UserName    = user.UserName,
                Email       = user.Email,
                Name        = user.Name,
                Surname     = user.Surname,
                Patronymic  = user.Patronymic,
                StaffNumber = user.StaffNumber
            };
            var result = await _userManager.CreateAsync(newUser, password).ConfigureAwait(false);

            return(new Result(result.Succeeded, result.Errors.Select(e => e.Description).ToArray()));
        }