hanyadikhetvan-dotnethf/HanyadikHetVan/Services/UserService.cs
Torma Kristóf 10c1bb008f
All checks were successful
continuous-integration/drone/push Build is passing
final
2021-05-20 01:36:54 +02:00

37 lines
983 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(UserDTO user)
{
var newUser = new User
{
UserName = user.Email,
Email = user.Email,
EmailConfirmed = true,
};
var result = await _userManager.CreateAsync(newUser, user.Password);
if (!result.Succeeded)
{
throw new Exception("Failed to create user.");
}
return new UserDTO() { Email = user.Email };
}
}
}