Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

CustomerService.cs 1.5KB

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