public static void SendNotification(EnumNotification notificationType, string url)
        {
            int    projectID   = (int)HttpContext.Current.Session["projectID"];
            int    userID      = (int)HttpContext.Current.Session["userID"];
            string projectName = (string)HttpContext.Current.Session["projectName"];
            string message     = "";

            using (SDTEntities db = new SDTEntities())
            {
                User sender = db.Users.Find(userID);
                List <ProjectUser> receivers = db.ProjectUsers.Where(p => p.ID_Project == projectID && p.ID_User != userID).ToList();
                message = CreateMessage(notificationType, sender, projectName);

                foreach (ProjectUser projectUser in receivers)
                {
                    Notification notification = new Notification();
                    notification.Avatar           = sender.Avatar;
                    notification.ID_User          = projectUser.ID_User;
                    notification.Message          = message;
                    notification.URL              = url;
                    notification.ID_Project       = projectID;
                    notification.DateNotification = DateTime.Now;
                    db.Notifications.Add(notification);
                    db.SaveChanges();
                }
            }
        }
Exemple #2
0
 public List <Notification> GetNotifications(int userID)
 {
     using (SDTEntities db = new SDTEntities())
     {
         return(db.Notifications.Where(n => n.ID_User == userID).OrderByDescending(i => i.ID).ToList());
     }
 }