using Back.Data.Contracts; using Back.Data.Models; using Microsoft.EntityFrameworkCore; namespace Back.Services { public class servNotification { private readonly IAsyncRepository _NotificationRepo; private readonly IAsyncRepository _UserNotfiRepo; public servNotification(IAsyncRepository NotificationRepo, IAsyncRepository userNotfiRepo) { _NotificationRepo = NotificationRepo; _UserNotfiRepo = userNotfiRepo; } public async Task ReadNotification(int UserID,int ntID) { if (!await _UserNotfiRepo.Get(w => w.UserID == UserID && w.NotificationID == ntID).AnyAsync()) return await _UserNotfiRepo.AddBoolResultAsync(new UserNotfi { NotificationID = ntID, UserID = UserID, }); else return true; } public async Task> GetNotifications(int UserID) { var readmsg=await _UserNotfiRepo.Get(w => w.UserID == UserID).Select(s=>s.NotificationID).ToListAsync(); return await _NotificationRepo.Get(w=>(string.IsNullOrEmpty(w.ForUser) || w.ForUser.Contains("/"+UserID.ToString()+"/"))&& !readmsg.Contains(w.ID)).ToListAsync(); } } }