Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • iknow-api/Services/Implementations/UserService.cs

    r9694de9 r618be76  
    1 using Microsoft.EntityFrameworkCore;
    2 using iknow_api.Core.Models;
    3 using iknow_api.Repository.Interfaces;
    4 // ...existing code...
     1using Microsoft.AspNetCore.Mvc;
    52
    63namespace iknow_api.Core.Services
    … …  
    85    public class UserService
    96    {
    10         private readonly IUserRepository _users;
     7        private readonly AppDbContext _context;
    118
    12         public UserService(IUserRepository users)
     9        public UserService(AppDbContext context)
    1310        {
    14             _users = users;
     11            _context = context;
    1512        }
    1613
    17         public async Task<User> AddUserAsync(User user, CancellationToken cancellationToken = default)
    18         {
    19             if (user == null) throw new ArgumentNullException(nameof(user));
    2014
    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         }
    3215    }
    3316}
Note: See TracChangeset for help on using the changeset viewer.