示例#1
0
        public async Task <OperationDetails> Create(UserBLL userBll)
        {
            ApplicationUser user = await _db.UserManager.FindByEmailAsync(userBll.Email);

            if (user == null)
            {
                user = new ApplicationUser {
                    Email = userBll.Email, UserName = userBll.Email
                };
                var result = await _db.UserManager.CreateAsync(user, userBll.Password);

                if (result.Errors.Count() > 0)
                {
                    return(new OperationDetails(false, result.Errors.FirstOrDefault(), ""));
                }

                await _db.UserManager.AddToRoleAsync(user.Id, userBll.Role);

                UserProfile userProfile = new UserProfile
                {
                    Id       = user.Id,
                    Birthday = userBll.Birthday,
                    Name     = userBll.Name
                };
                _db.UserRepository.Add(userProfile);
                await _db.SaveAsync();

                return(new OperationDetails(true, "The registration was successful", ""));
            }
            return(new OperationDetails(false, "Email is already exists.", "Email"));
        }
示例#2
0
        public async Task <OperationDetails> Create(UserDto userDto)
        {
            ApplicationUser user = await unit.UserManager.FindByEmailAsync(userDto.Email);

            if (user == null)
            {
                user = new ApplicationUser {
                    Email = userDto.Email, UserName = userDto.Email
                };
                var result = await unit.UserManager.CreateAsync(user, userDto.Password);

                if (result.Errors.Count() > 0)
                {
                    return(new OperationDetails(false, result.Errors.FirstOrDefault(), ""));
                }

                // добавляем роли
                await unit.UserManager.AddToRolesAsync(user.Id, userDto.Roles.ToArray());

                // создаем профиль клиента
                ClientProfile clientProfile = new ClientProfile {
                    Id = user.Id, Address = userDto.Address, Name = userDto.Name
                };
                unit.ClientManager.Create(clientProfile);
                await unit.SaveAsync();

                return(new OperationDetails(true, "Registration successful", ""));
            }
            else
            {
                return(new OperationDetails(false, "User with such login already exists", "Email"));
            }
        }
示例#3
0
        public async Task <Result> CreateAsync(ApplicationUserDTO userDto)
        {
            ApplicationUser user = await Database.UserManager.FindByEmailAsync(userDto.Email);

            if (user == null)
            {
                user = new ApplicationUser {
                    Email = userDto.Email, UserName = userDto.Email
                };
                var result = await Database.UserManager.CreateAsync(user, userDto.Password);

                if (result.Errors.Count() > 0)
                {
                    return(new Result(false, result.Errors.FirstOrDefault(), ""));
                }
                await Database.UserManager.AddToRoleAsync(user.Id, userDto.Role);

                ApplicationProfile clientProfile = new ApplicationProfile {
                    Id = user.Id, Name = userDto.ApplicationProfile.Name, Balance = userDto.ApplicationProfile.Balance, CreditCard = userDto.ApplicationProfile.CreditCard
                };
                user.ApplicationProfile = clientProfile;
                var list = Database.UserManager.Users.ToList();
                await Database.SaveAsync();

                return(new Result(true, $"User {userDto.Email} has been registered", ""));
            }
            else
            {
                return(new Result(false, $"The user with {userDto.Email} is already registered", "Email"));
            }
        }
示例#4
0
        public async Task <OperationDetails> Create(UserDTO userDto)
        {
            ApplicationUser user = await _identityUnitOfWork.UserManager.FindByEmailAsync(userDto.Email);

            if (user == null)
            {
                user = new ApplicationUser {
                    Email = userDto.Email, UserName = userDto.Email
                };
                var result = await _identityUnitOfWork.UserManager.CreateAsync(user, userDto.Password);

                if (result.Errors.Count() > 0)
                {
                    return(new OperationDetails(false, result.Errors.FirstOrDefault(), ""));
                }

                await _identityUnitOfWork.UserManager.AddToRoleAsync(user.Id, userDto.Role);

                Profile clientProfile = new Profile {
                    Id = user.Id
                };
                _identityUnitOfWork.ProfileManager.Create(clientProfile);
                await _identityUnitOfWork.SaveAsync();

                return(new OperationDetails(true, "Регистрация успешно пройдена", ""));
            }
            else
            {
                return(new OperationDetails(false, "Пользователь с таким логином уже существует", "Email"));
            }
        }
示例#5
0
 /// <summary>
 /// Creates a user, if it does not exist.
 /// </summary>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="UsersManagementException"></exception>
 public async Task CreateAsync(UserDTO userDto)
 {
     if (userDto == null)
         throw new ArgumentNullException("User provided was null value");
     AuctionUser user = await db.UserManager.FindByEmailAsync(userDto.Email);
     if (user != null)
         throw new UsersManagementException("User with provided login already exists");
     user = new AuctionUser { Email = userDto.Email, UserName = userDto.Email, Nickname = userDto.Nickname, CreditCardNumber = userDto.CreditCardNumber };
     var result = await db.UserManager.CreateAsync(user, userDto.Password);
     if (result.Errors.Count() > 0)
         throw new UsersManagementException(result.Errors.FirstOrDefault());
     foreach (var role in userDto.Roles)
     {
         await db.UserManager.AddToRoleAsync(user.Id, role);
     }
     await db.SaveAsync();