Example #1
0
 public int AddEvent(JsonEvent e)
 {
     var inserted = db.Events.Add(ToDbEvent(e));
     db.SaveChanges();
     e.Id = inserted.Id;
     e.Time = inserted.Time;
     return inserted.Id;
 }
Example #2
0
        public void UpdateEvent(JsonEvent jevent)
        {
            var ev = db.Events.Find(jevent.Id);
            var nev = ToDbEvent(jevent);

            ev.Comments = nev.Comments;
            ev.Contact = nev.Contact;
            ev.SourceReliability = nev.SourceReliability;
            ev.Text = nev.Text;
            ev.Time = nev.Time;
            ev.Topic = nev.Topic;
            ev.User = nev.User;

            db.SaveChanges();
        }
Example #3
0
 private Event ToDbEvent(JsonEvent e)
 {
     return new Event
     {
         Text = e.Event,
         Comments = e.Comments,
         Contact = e.Contact,
         Time = e.Time.HasValue ? e.Time.Value : DateTime.Now,
         SourceReliability = e.SourceReliability != null ? db
             .SourceReliability
             .SingleOrDefault(sr => sr.Text == e.SourceReliability)
             ?? new SourceReliability { Text = e.SourceReliability } : null,
         Topic = e.Topic,
         User = e.User != null ? db
             .User
             .SingleOrDefault(u => u.Name == e.User)
             ?? new User { Name = e.User } : null
     };
 }