public async Task <bool> IsNotificationReviewed(Domain.Entries.Notification.Notification notification) { var user = await _userManager.FindByEmailAsync(_httpContextAccessor.HttpContext.User.Identity.Name); var notificationReview = _context.UserNotifications.FirstOrDefault(x => x.AppUserId == user.Id && x.NotificationId == notification.Id); return(notificationReview != null); }
private static NotificationViewModel CopyToNotificationViewModel(this Domain.Entries.Notification.Notification notification, bool reviewed) { var model = new NotificationViewModel { Id = notification.Id.ToString(), Title = notification.Title, Message = notification.Message, LinkTitle = notification.LinkTitle, Link = notification.Link, Reviewed = reviewed, DateTimeCreated = notification.DateTimeCreated }; return(model); }
public async Task <NotificationResultEnum> UpdateAsync(NotificationViewModel model) { var user = await _userManager.FindByEmailAsync(_httpContextAccessor.HttpContext.User.Identity.Name); if (user is null) { return(NotificationResultEnum.Failed); } if (model.Id is null) { var newNotification = new Domain.Entries.Notification.Notification(); newNotification.Id = Guid.NewGuid(); newNotification.Title = model.Title; newNotification.Message = model.Message; newNotification.LinkTitle = model.LinkTitle; newNotification.Link = model.Link; newNotification.DateTimeCreated = DateTime.Now; _context.Add(newNotification); await _context.SaveChangesAsync(); return(NotificationResultEnum.Created); } var notification = new Domain.Entries.Notification.Notification(); notification.Title = model.Title; notification.Message = model.Message; notification.LinkTitle = model.LinkTitle; notification.Link = model.Link; _context.Add(notification); await _context.SaveChangesAsync(); return(NotificationResultEnum.Updated); }
public static NotificationViewModel CreateNotificationViewModel(this Domain.Entries.Notification.Notification notification, bool reviewed) { var model = notification.CopyToNotificationViewModel(reviewed); return(model); }