public bool PlaceBeacon(Beacon beacon) { var success = false; using (var context = new BeaconContext()) { try { var oldBeacon = GetBeaconByUserId(beacon.UserId); context.Beacons.Remove(oldBeacon); context.Entry(oldBeacon).State = EntityState.Deleted; var buddies = context.Buddies.Where(b => b.BeaconId == oldBeacon.BeaconId); context.Buddies.RemoveRange(buddies); context.Beacons.Add(beacon); context.Entry(beacon).State = EntityState.Added; context.SaveChanges(); success = GetBeacon(beacon.BeaconId) != null && GetBeacon(oldBeacon.BeaconId) == null; } catch { throw; } } return(success); }
public void UpdateFriends(User user, List <int> friends) { using (var context = new BeaconContext()) { try { foreach (var friend in friends) { var userToAdd = context.Users.Where(u => u.FaceBookId == friend).FirstOrDefault(); if (userToAdd != null && !user.Friends.ToList().Contains(userToAdd)) { user.Friends.ToList().Add(userToAdd); } else if (userToAdd == null && user.Friends.ToList().Contains(userToAdd)) { user.Friends.ToList().Remove(userToAdd); } } context.Entry(user).State = EntityState.Modified; context.SaveChanges(); } catch { throw; } } }
public void PostLogEntry(LogEntry entry) { using (var context = new BeaconContext()) { context.LogEntries.Add(entry); context.Entry(entry).State = EntityState.Added; context.SaveChanges(); } }
public void DeleteByBeaconId(int id) { using (var context = new BeaconContext()) { try { var buddies = context.Buddies.Where(x => x.BeaconId == id); buddies.ToList().ForEach(x => context.Entry(x).State = EntityState.Deleted); context.RemoveRange(buddies); context.SaveChanges(); } catch { throw; } } }
public bool SaveUser(User user) { var result = false; using (var context = new BeaconContext()) { try { context.Users.Add(user); context.Entry(user).State = EntityState.Added; context.SaveChanges(); result = GetUser(user.UserId) != null; } catch { throw; } } return(result); }
public bool PutBuddy(Buddy buddy) { var result = false; using (var context = new BeaconContext()) { try { context.Buddies.Attach(buddy); context.Entry(buddy).State = EntityState.Modified; context.SaveChanges(); result = true; } catch { throw; } return(result); } }
public bool PostBuddy(Buddy buddy) { var result = false; using (var context = new BeaconContext()) { try { context.Buddies.Add(buddy); context.Entry(buddy).State = EntityState.Added; context.SaveChanges(); result = context.Buddies.Find(buddy.BuddyId) != null; } catch { throw; } return(result); } }
public bool DeleteUser(int id) { var result = false; using (var context = new BeaconContext()) { try { var user = context.Users.Find(id); context.Users.Remove(user); context.Entry(user).State = EntityState.Deleted; context.SaveChanges(); result = GetUser(id) == null; } catch { throw; } } return(result); }
public bool DeleteBeacon(int id) { var success = false; using (var context = new BeaconContext()) { try { var beacon = context.Beacons.Find(id); context.Beacons.Remove(beacon); context.Entry(beacon).State = EntityState.Deleted; context.SaveChanges(); success = GetBeacon(beacon.BeaconId) == null; } catch { throw; } } return(success); }
public bool PutBeacon(int id, int drinks) { var success = false; using (var context = new BeaconContext()) { try { var beacon = context.Beacons.Find(id); context.Beacons.Attach(beacon); beacon.DrinkCounter = drinks; context.Entry(beacon).State = EntityState.Modified; context.SaveChanges(); success = context.Beacons.Find(id).DrinkCounter == drinks; } catch { throw; } } return(success); }