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 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); } }