Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ModelFactory.cs 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using SecureSharing.Business.Interfaces;
  2. using SecureSharing.Models;
  3. namespace SecureSharing.Infrastructure;
  4. public sealed class ModelFactory : IModelFactory
  5. {
  6. private readonly IMessageService _messageService;
  7. public ModelFactory(IMessageService messageService)
  8. {
  9. _messageService = messageService;
  10. }
  11. public async Task<LinkModel> PrepareLinkVM(Guid code, bool? share)
  12. {
  13. //share is true when the link is created
  14. LinkModel model = null;
  15. try
  16. {
  17. var message = await _messageService.GetByCode(code);
  18. model = new LinkModel
  19. {
  20. MessageModel = new MessageModel { Code = code, Text = message.Text }, Share = share,
  21. IsValid = message.IsValid
  22. };
  23. if (model.IsValid)
  24. {
  25. if (message.ExpiryDate != null)
  26. {
  27. model.TimeLeft = message.ExpiryDate - DateTime.UtcNow;
  28. if (message.ExpiryDate <= DateTime.UtcNow)
  29. {
  30. await _messageService.InvalidateMessage(message.Id);
  31. model.IsValid = false;
  32. }
  33. }
  34. else
  35. {
  36. //ONE_TIME sharing: make the message invalid now so that it can't be accessed next time
  37. if (share is null or false) await _messageService.InvalidateMessage(message.Id);
  38. }
  39. }
  40. }
  41. catch (Exception _)
  42. {
  43. model = new LinkModel { IsValid = false };
  44. }
  45. return model;
  46. }
  47. //public MessageModel PrepareMessageVM(MessageDto message)
  48. //{
  49. // throw new System.NotImplementedException();
  50. //}
  51. }