You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CustomerRepository.cs 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Diligent.WebAPI.Business.Interfaces;
  2. using Diligent.WebAPI.Data.Entities;
  3. using Microsoft.AspNetCore.Identity;
  4. using System.Diagnostics.CodeAnalysis;
  5. namespace Diligent.WebAPI.Business.Services
  6. {
  7. [ExcludeFromCodeCoverage]
  8. public class CustomerRepository : ICustomerRepository
  9. {
  10. private readonly UserManager<Customer> _customerManager;
  11. public CustomerRepository(UserManager<Customer> customerManager)
  12. {
  13. _customerManager = customerManager;
  14. }
  15. public async Task<Customer> GetCustomer(string username)
  16. {
  17. var customer = await _customerManager.FindByNameAsync(username);
  18. return customer;
  19. }
  20. public async Task<Customer> GetCustomerById(string id)
  21. {
  22. var customer = await _customerManager.FindByIdAsync(id);
  23. return customer;
  24. }
  25. public async Task AddNotification(Customer receiver)
  26. {
  27. await _customerManager.UpdateAsync(receiver);
  28. }
  29. public async Task<List<Notification>> ReadNotifications(string userId)
  30. {
  31. var user = await _customerManager.FindByIdAsync(userId);
  32. return user.Notifications;
  33. }
  34. public async Task DeleteNotification(Customer user, Notification notification)
  35. {
  36. user.Notifications.Remove(notification);
  37. await _customerManager.UpdateAsync(user);
  38. }
  39. }
  40. }