public bool Save(string Sender, List <string> Receivers, string Subject, string Message) { try { foreach (string Receiver in Receivers) { sw.Notification row = new sw.Notification { Sender = Sender, Receiver = Receiver, Subject = Subject, Message = Message, NotificationStatusId = 0, NotificationTypeId = 3, SentDate = DateTime.Now, ModifiedDate = DateTime.Now, ModifiedBy = Sender }; if (!Save(row)) { throw new Exception("Could not save one or all notification"); } } return(true); } catch (Exception ex) { return(false); } }
public KeyValuePair <bool, string> SendNotificationToPerson(string sender, string receiver, string subject, string message, DateTime timestamp) { KeyValuePair <bool, string> response = new KeyValuePair <bool, string>(); try { sw.Notification row = new sw.Notification { Sender = sender, Receiver = receiver, Subject = subject, Message = message, NotificationStatusId = 0, NotificationTypeId = 3, SentDate = timestamp, ModifiedDate = timestamp, ModifiedBy = sender }; swdb.Notification.Add(row); swdb.SaveChanges(); //if (Save(row)) //{ // response = new KeyValuePair<bool, string>(true, "Successfully Sent!"); //} } catch (Exception ex) { response = new KeyValuePair <bool, string>(false, ex.Message); } return(response); }
public ActionResult SendNotification(string username) { Notification model = new Notification(); if (username != null) { model.Receiver = username; } return(View(model)); }
public bool Save(sw.Notification row) { try { swdb.Notification.Add(row); swdb.SaveChanges(); Send(row.Receiver); return(true); } catch (Exception ex) { return(false); } }
public ActionResult SendNotification(Notification model) { try { if (ModelState.IsValid) { List <string> allReceivers = new List <string>(); List <string> Receivers = model.Receiver.Split(',').ToList(); foreach (string user in Receivers) { if (membershipService.GetUser(user) != null) { allReceivers.Add(user); } else { if (roleService.RoleExists(user)) { var users = roleService.GetUsersInRole(user); foreach (string u in users) { allReceivers.Add(u); } } } } Notify hub = new Notify(); if (hub.Save(User.Identity.Name, allReceivers, model.Subject, model.Message)) { TempData["message"] = "<b>" + model.Subject + "</b> was successfully sent to <b>" + model.Receiver + "</b>."; return(RedirectToAction("SendNotification")); } return(RedirectToAction("Sent")); } else // Validation error, so redisplay same view { return(View(model)); } } catch { return(View(model)); } }