public static void Add(string definition, string projectName, string userName, int bakeryID, int type, string tags = null, string tables = null)
        {
            NotificationDataContext db           = new NotificationDataContext(); // Prepare Database context
            Notification            notification = new Notification();

            notification.ProjectName = projectName;
            notification.PlcID       = 1; // for this moment static
            notification.Owner       = userName;
            notification.BakeryID    = bakeryID;
            notification.Type        = type; //1 - for alarm type notification
            if (tables != null)
            {
                notification.Tables = tables;
            }
            if (tags != null)
            {
                notification.Tags = tags;
            }
            notification.Definition       = definition;
            notification.Active           = true;
            notification.TimestampCreated = DateTime.Now;

            //Add new notification to database
            db.Notifications.InsertOnSubmit(notification);

            //Save changes to Database.
            db.SubmitChanges();
        }
        public RedirectToRouteResult Delete(int id)
        {
            NotificationDataContext db           = new NotificationDataContext();
            Notification            notification = db.Notifications.Single(p => p.Id == id && p.Owner.Contains(User.Identity.Name));

            db.Notifications.DeleteOnSubmit(notification);
            db.SubmitChanges();
            Session["success"] = "Notification with id " + id + " has been successfully deleted";
            return(RedirectToAction("Index", "Notification"));
        }
        public RedirectToRouteResult Edit(Notification model)
        {
            NotificationDataContext db        = new NotificationDataContext();
            Notification            editNotif = db.Notifications.Single(p => p.Id == model.Id);

            db.Notifications.DeleteOnSubmit(editNotif);
            db.Notifications.InsertOnSubmit(model);
            db.SubmitChanges();
            Session["success"] = "Notification with id " + model.Id + " has been successfully Edited";
            return(RedirectToAction("Index", "Notification"));
        }
        public RedirectToRouteResult turnOff(int id)
        {
            NotificationDataContext db           = new NotificationDataContext();
            Notification            notification = db.Notifications.Single(p => p.Id == id && p.Owner.Contains(User.Identity.Name));

            notification.Occurred         = null;
            notification.Tables           = null;
            notification.Tags             = null;
            notification.Detail           = null;
            notification.Status           = 2;
            notification.TimestampCreated = DateTime.Now;
            db.SubmitChanges();
            return(RedirectToAction("Index", "Home"));
        }