Пример #1
0
        public ResultInfo.Result Add(string title)
        {
            Alert alrt = new Alert();
            try
            {
                alrt.Title = title;
                alrt.Message = "Alert from [Thing], reported [EndpointType]: [Value] [Measurement] @[TimeStamp]";
                alrt.IsActive = false;
                alrt.Sunday = false;
                alrt.Monday = false;
                alrt.Tuesday = false;
                alrt.Wednesday = false;
                alrt.Thursday = false;
                alrt.Friday = false;
                alrt.Saturday = false;
                alrt.StartTime = new TimeSpan(0, 0, 0);
                alrt.EndTime = new TimeSpan(23, 59, 59);

                db.Alerts.Add(alrt);
                db.SaveChanges();
                return ResultInfo.GenerateOKResult("Saved", alrt.ID);
            }
            catch
            {
                return ResultInfo.GetResultByID(1);
            }
        }
Пример #2
0
 public Alert Find(long id)
 {
     Alert alrt = new Alert();
     List<Alert> alrts = db.Alerts.Where(l => l.ID == id).ToList();
     if (alrts.Count == 1)
     {
         alrt = alrts[0];
     }
     else
     {
         throw new Exception("Not Found");
     }
     return alrt;
 }