public static Boolean SendNotificationToUser(NotificationUser notification, int userID) { try { using (var db = new DBContextModel()) { TblNotifications notif = new TblNotifications { Description = notification.Description, Hour = DateTime.Now, Subject = notification.Subject, Urgency = notification.Urgency, Approval = notification.Approval, UserFK = notification.SenderFK }; db.TblNotifications.Add(notif); db.SaveChanges(); TblValidations valid = new TblValidations { NotificationFK = notif.ID, ReceiverFK = notification.ReceiverFK, Accepted = false, Read = false, StudentFK = notification.StudentFK }; db.TblValidations.Add(valid); db.SaveChanges(); BAction.SetActionToUser(String.Format("enviou uma notificação ao utilizador '{0}'", db.TblUsers.Find(notification.ReceiverFK).Name), userID); return(true); } } catch (Exception) { return(false); } }
public void Handle(MoneyTransferedEvent @event) { var notification = new TblNotifications { IsDisplayed = false, Login = _loginRepository.GetById(@event.AccountId), Message = string.Format($"{@event.Amount} transfered: {@event.OccurredOn}.") }; _notificationRepository.Create(notification); }
public void Handle(UserLogoutEvent @event) { var notification = new TblNotifications { IsDisplayed = false, Login = _loginRepository.GetById(@event.UserId), Message = string.Format($"User logout: {@event.OccurredOn}.") }; _notificationRepository.Create(notification); }
public virtual async Task <int> AddAsync(TblNotifications record) { _dbContext.Notifications.Add(record); await _dbContext.SaveChangesAsync(); QueryCacheManager.ExpireTag(CacheTags.Notification); _eventPublisher.EntityInserted(record); return(record.Id); }
public virtual async Task UpdateAsync(TblNotifications record) { var oldRecord = await FindByIdAsync(record.Id); _dbContext.Notifications.AddOrUpdate(record); await _dbContext.SaveChangesAsync(); QueryCacheManager.ExpireTag(CacheTags.Notification); _eventPublisher.EntityUpdated(record, oldRecord); }
public async Task <bool> Update(TblNotifications tbl) { try { _db.Entry(tbl).State = EntityState.Modified; await _db.SaveChangesAsync(); return(true); } catch { return(false); } }
public static Boolean SendNotificationToClass(NotificationClass notification, int userID) { try { using (var db = new DBContextModel()) { TblNotifications notif = new TblNotifications { Description = notification.Description, Hour = DateTime.Now, Subject = notification.Subject, Urgency = notification.Urgency, Approval = notification.Approval, UserFK = notification.SenderFK }; db.TblNotifications.Add(notif); db.SaveChanges(); var students = BClass.GetStudentsByClass(notification.ClassFK); foreach (var student in students) { TblValidations valid = new TblValidations { ReceiverFK = BParenting.GetGuardians(student).FirstOrDefault(), StudentFK = student, Accepted = false, Read = false }; db.TblValidations.Add(valid); db.SaveChanges(); } var cla = db.TblClasses.Find(notification.ClassFK); BAction.SetActionToUser(String.Format("enviou uma notificação a turma '{0}'", cla.Year + cla.ClassDesc), userID); return(true); } } catch (Exception) { return(false); } }