public async Task<OperationDetails> Create(UserDTO userDto) { ApplicationUser user = await Database.UserManager.FindByEmailAsync(userDto.Email); if (user == null) { user = new ApplicationUser { Email = userDto.Email, UserName = userDto.Email }; await Database.UserManager.CreateAsync(user, userDto.Password); // добавляем роль await Database.UserManager.AddToRoleAsync(user.Id, userDto.Role); // создаем профиль клиента ClientProfile clientProfile = new ClientProfile { Id = user.Id, Surname = userDto.Surname, Name = userDto.Name ,Login="******"+Database.UserManager.Users.Count()}; Database.ClientManager.Create(clientProfile); await Database.SaveAsync(); return new OperationDetails(true, "Register successful", ""); } else { return new OperationDetails(false, "User with same email already exists", "Email"); } }
public async Task<OperationDetails> Create(UserDTO userDto) { ApplicationUser user = await Database.UserManager.FindByEmailAsync(userDto.Email); if (user == null) { user = new ApplicationUser { Email = userDto.Email, UserName = userDto.Email }; await Database.UserManager.CreateAsync(user, userDto.Password); // добавляем роль await Database.UserManager.AddToRoleAsync(user.Id, userDto.Role); // создаем профиль клиента ClientProfile clientProfile = new ClientProfile { Id = user.Id, UserId = userDto.UserId }; Database.ClientManager.Create(clientProfile); await Database.SaveAsync(); return new OperationDetails(true, "Регистрация успешно пройдена", ""); } else { return new OperationDetails(false, "Пользователь с таким логином уже существует", "Email"); } }
public void Create(ClientProfile item) { Database.ClientProfiles.Add(item); Database.SaveChanges(); }