Esempio n. 1
0
 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);
     }
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public ActionResult SendNotification(string username)
        {
            Notification model = new Notification();

            if (username != null)
            {
                model.Receiver = username;
            }
            return(View(model));
        }
Esempio n. 4
0
        public bool Save(sw.Notification row)
        {
            try
            {
                swdb.Notification.Add(row);
                swdb.SaveChanges();

                Send(row.Receiver);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Esempio n. 5
0
        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));
            }
        }