public Message(ScheduledTip tip) { this.TimeStamp = DateTime.Now.ToString("yyyyMMddHHmmss"); this.Text = tip.Tip; this.Destination = tip.Destination; this.Correlator = (tip.Type == "General" ? "G" : "M") + tip.Id.ToString(); }
public static void ScheduleTipMessages() { // Insert new Scheduled Messages containing tips of the day // Each subscriber gets a different tip depending on their progress // on the list of tips using (var db = new ApplicationDbContext()) { db.Configuration.AutoDetectChangesEnabled = false; db.Configuration.ValidateOnSaveEnabled = false; var subscribers = db.Subscribers.Where(s => s.isActive).ToList(); foreach (var subscriber in subscribers) { var tip = db.Tips.Find(subscriber.NextTip); if (tip != null) { var tipMessage = new ScheduledTip() { Destination = subscriber.PhoneNumber, TipNumber = subscriber.NextTip, Tip = tip.Message, Type = "General", ServiceId = subscriber.ServiceId, DateScheduled = DateTime.Now, ExpirationDate = DateTime.Now.AddHours(23) }; db.ScheduledTips.Add(tipMessage); } } db.SaveChanges(); } }
public ActionResult DeleteConfirmed(int id) { ScheduledTip scheduledTip = db.ScheduledTips.Find(id); db.ScheduledTips.Remove(scheduledTip); db.SaveChanges(); return(RedirectToAction("Index")); }
public override void Schedule(ScheduledTip toSchedule) { var notification = BuildNotification(toSchedule); NotificationCenter.Schedule(notification); toSchedule.NotificationID = notification.ID; base.Schedule(toSchedule); }
public ActionResult Edit([Bind(Include = "Id,TipNumber,Tip,DateScheduled,Destination,ServiceId")] ScheduledTip scheduledTip) { if (ModelState.IsValid) { db.Entry(scheduledTip).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(scheduledTip)); }
public ActionResult Create([Bind(Include = "Id,TipNumber,Tip,DateScheduled,Destination,ServiceId")] ScheduledTip scheduledTip) { if (ModelState.IsValid) { db.ScheduledTips.Add(scheduledTip); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(scheduledTip)); }
// GET: ScheduledTips/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ScheduledTip scheduledTip = db.ScheduledTips.Find(id); if (scheduledTip == null) { return(HttpNotFound()); } return(View(scheduledTip)); }
Notification BuildNotification(ScheduledTip st) { var time = DateTime.Parse(st.Hour + ":" + st.Minute); if (time <= DateTime.Now) { time = time.AddDays(1); } return(new Notification { Title = "Tips tegen Dips", Body = "Er staat een nieuwe tip voor je klaar!", Open = "1", Data = TipPage.NewTip, Time = time, Repeat = TimeSpan.FromDays(1) }); }
// Schedule match specific tips to be sent public static void ScheduleMatchSpecificTip(int matchSpecificTipId) { using (var db = new ApplicationDbContext()) { db.Configuration.AutoDetectChangesEnabled = false; db.Configuration.ValidateOnSaveEnabled = false; //db.Database.ExecuteSqlCommand("UPDATE dbo.Subscribers SET NextMatchTip = @tipId WHERE NextMatchTip < @tipId", // new SqlParameter("@tipId", matchSpecificTipId)); var subscribers = db.Subscribers.Where(s => s.isActive).ToList(); foreach (var subscriber in subscribers) { int nextMatchTip = subscriber.NextMatchTip < matchSpecificTipId ? matchSpecificTipId : subscriber.NextMatchTip; var tip = db.MatchSpecificTips.Find(nextMatchTip); if (tip != null) { var tipMessage = new ScheduledTip() { Destination = subscriber.PhoneNumber, TipNumber = subscriber.NextTip, Tip = tip.Tip, Type = "Match", ServiceId = subscriber.ServiceId, DateScheduled = DateTime.Now, ExpirationDate = tip.Expiration }; subscriber.NextMatchTip = matchSpecificTipId + 1; db.ScheduledTips.Add(tipMessage); } } db.SaveChanges(); } }
/// <summary> /// Create a scheduled tip /// </summary> /// <param name="tip"></param> private void AddScheduledTip(ScheduledTip tip) { BroadcastGameTip(tip.message.text, tip.message.duration, tip.mandatory); timer.Once(tip.period, () => { AddScheduledTip(tip); }); }
public override void Cancel(ScheduledTip scheduled) { NotificationCenter.Cancel(scheduled.NotificationID); base.Cancel(scheduled); }