public static void AddRecords(List <Record> records)
 {
     using (var context = new TimerContext())
     {
         context.Records.AddRange(records);
         context.SaveChanges();
     }
 }
 public static void AddGroup(Group group)
 {
     using (var context = new TimerContext())
     {
         context.Users.Attach(group.User);
         context.Groups.Add(group);
         context.SaveChanges();
         context.Entry(group).State = System.Data.Entity.EntityState.Unchanged;
     }
 }
 public static void DeleteRecords(List <Guid> record_ids)
 {
     using (var context = new TimerContext())
     {
         var toDelete = context.Records.Where(r => record_ids.Contains(r.Id)).ToList();
         foreach (Record record in toDelete)
         {
             context.Records.Remove(record);
         }
         context.SaveChanges();
     }
 }
        public static void AddRecord(Record record)
        {
            using (var context = new TimerContext())
            {
                context.Users.Attach(record.User);

                if (record.Group != null)
                {
                    context.Groups.Attach(record.Group);
                }

                context.Records.Add(record);
                context.SaveChanges();
            }
        }
        public static void UpdateRecord(Record record, string[] update_fields)
        {
            using (var context = new TimerContext())
            {
                context.Users.Attach(record.User);
                if (record.Group != null)
                {
                    context.Groups.Attach(record.Group);
                }
                Record nRecord = context.Records.FirstOrDefault(r => r.Id == record.Id);
                if (nRecord == null)
                {
                    context.Records.Add(record);
                }
                else
                {
                    foreach (string p in update_fields)
                    {
                        switch (p)
                        {
                        case "StartTime":
                            nRecord.StartTime = record.StartTime;
                            break;

                        case "Duration":
                            nRecord.Duration = record.Duration;
                            break;

                        case "EndTime":
                            nRecord.EndTime = record.EndTime;
                            break;

                        case "Comment":
                            nRecord.Comment = record.Comment;
                            break;

                        case "Group":
                            nRecord.Group   = record.Group;
                            nRecord.GroupId = record.GroupId;
                            break;
                        }
                    }
                }
                context.SaveChanges();
            }
        }