public ActionResult MarkAsRead(NotificationSelectionVM model) { if (!System.Web.HttpContext.Current.User.Identity.IsAuthenticated) { return(Redirect("/Home/Index")); } // get the ids of the items selected: var selectedIds = model.GetSelectedIds(); // Use the ids to retrieve the records for the selected notification // from the database: Collaborator coll = dal.GetCollaborator(System.Web.HttpContext.Current.User.Identity.Name); var selectedNotification = from x in dal.GetNotifications(coll) where selectedIds.Contains(x.Id) select x; // Process foreach (Notification notif in selectedNotification) { notif.NotifStatus = NotificationStatus.READ; } dal.SaveChanges(); // Redirect the results: return(RedirectToAction("Index")); }
// GET: Notification public ActionResult Index() { if (!System.Web.HttpContext.Current.User.Identity.IsAuthenticated) { return(Redirect("/Home/Index")); } Collaborator coll = dal.GetCollaborator(System.Web.HttpContext.Current.User.Identity.Name); NotificationSelectionVM model = new NotificationSelectionVM(); foreach (Notification n in dal.GetNotifications(coll)) { SelectNotificationEditorVM notifVM = new SelectNotificationEditorVM() { Id = n.Id, NotifType = n.NotifType, NotifStatus = (n.NotifStatus == NotificationStatus.UNREAD ? "unread" : "read"), NotifResult = n.NotifResult.ToString(), NotifContent = n.NotifContent, Selected = false }; model.Notifications.Insert(0, notifVM); } return(View(model)); }