|
Last change
on this file since 9a57e89 was 9a57e89, checked in by imbrsk <boris696boris@…>, 11 months ago |
|
Refactor user management: update models, repositories, and services; remove obsolete files
|
-
Property mode
set to
100644
|
|
File size:
980 bytes
|
| Line | |
|---|
| 1 | using Microsoft.EntityFrameworkCore;
|
|---|
| 2 | using iknow_api.Core.Models;
|
|---|
| 3 | using iknow_api.Repository.Interfaces;
|
|---|
| 4 | // ...existing code...
|
|---|
| 5 |
|
|---|
| 6 | namespace iknow_api.Core.Services
|
|---|
| 7 | {
|
|---|
| 8 | public class UserService
|
|---|
| 9 | {
|
|---|
| 10 | private readonly IUserRepository _users;
|
|---|
| 11 |
|
|---|
| 12 | public UserService(IUserRepository users)
|
|---|
| 13 | {
|
|---|
| 14 | _users = users;
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | public async Task<User> AddUserAsync(User user, CancellationToken cancellationToken = default)
|
|---|
| 18 | {
|
|---|
| 19 | if (user == null) throw new ArgumentNullException(nameof(user));
|
|---|
| 20 |
|
|---|
| 21 | if (!string.IsNullOrWhiteSpace(user.Email))
|
|---|
| 22 | {
|
|---|
| 23 | user.Email = user.Email.Trim();
|
|---|
| 24 |
|
|---|
| 25 | var exists = await _users.EmailExistsAsync(user.Email, cancellationToken);
|
|---|
| 26 | if (exists)
|
|---|
| 27 | throw new InvalidOperationException("A user with this email already exists.");
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | return await _users.AddUserAsync(user, cancellationToken);
|
|---|
| 31 | }
|
|---|
| 32 | }
|
|---|
| 33 | } |
|---|
Note:
See
TracBrowser
for help on using the repository browser.