37 lines
979 B
C#
37 lines
979 B
C#
|
using HanyadikHetVan.Data.Entities;
|
|||
|
using HanyadikHetVan.DTO;
|
|||
|
using Microsoft.AspNetCore.Identity;
|
|||
|
using System;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace HanyadikHetVan.Services
|
|||
|
{
|
|||
|
public class UserService
|
|||
|
{
|
|||
|
private readonly UserManager<User> _userManager;
|
|||
|
|
|||
|
public UserService(UserManager<User> userManager)
|
|||
|
{
|
|||
|
_userManager = userManager ?? throw new ArgumentNullException(nameof(userManager));
|
|||
|
}
|
|||
|
public async Task<UserDTO> CreateUser(string email, string password)
|
|||
|
{
|
|||
|
var newUser = new User
|
|||
|
{
|
|||
|
UserName = email,
|
|||
|
Email = email,
|
|||
|
EmailConfirmed = true,
|
|||
|
|
|||
|
};
|
|||
|
|
|||
|
var result = await _userManager.CreateAsync(newUser,password);
|
|||
|
if (!result.Succeeded)
|
|||
|
{
|
|||
|
throw new Exception("Failed to create user.");
|
|||
|
}
|
|||
|
|
|||
|
return new UserDTO() { Email = email };
|
|||
|
}
|
|||
|
}
|
|||
|
}
|