public Beacon StoreBeacon(Beacon beacon) { using (var db = new Context()) { var oldBeacon = db.Beacons.Find(beacon.UUID, beacon.Major, beacon.Minor); if (oldBeacon != null) { ((IObjectContextAdapter)db).ObjectContext.Detach(oldBeacon); db.Beacons.Attach(beacon); db.Entry(beacon).State = System.Data.Entity.EntityState.Modified; } else { db.Beacons.Add(beacon); } db.SaveChanges(); return oldBeacon; } }
private void insertBeacon(Beacon beacon) { }
public Beacon StoreBeacon(Beacon beacon) { loadBeacons(); if (!beacons.ContainsKey(beacon.UUID)) beacons[beacon.UUID] = new Dictionary<int, Dictionary<int, Beacon>>(); if (!beacons[beacon.UUID].ContainsKey(beacon.Major)) beacons[beacon.UUID][beacon.Major] = new Dictionary<int, Beacon>(); Beacon ret = null; if (beacons[beacon.UUID][beacon.Major].ContainsKey(beacon.Minor)) { ret = beacons[beacon.UUID][beacon.Major][beacon.Minor]; } beacons[beacon.UUID][beacon.Major][beacon.Minor] = beacon; return ret; }
private void deleteBeacon(Beacon beacon) { beacons[beacon.UUID][beacon.Major].Remove(beacon.Minor); if (beacons[beacon.UUID][beacon.Major].Count == 0) { beacons[beacon.UUID].Remove(beacon.Major); if (beacons[beacon.UUID].Count == 0) { beacons.Remove(beacon.UUID); } } }
public void SaveBeacon(Beacon beacon) { var oldBeacon = beaconProvider.FindExactBeacon(beacon.UUID, beacon.Major, beacon.Minor); if (oldBeacon != null) { if (!string.IsNullOrEmpty(oldBeacon.Image) && oldBeacon.Image != beacon.Image) { File.Delete(HttpContext.Current.Server.MapPath("~" + oldBeacon.Image)); } if (!string.IsNullOrEmpty(oldBeacon.Video) && oldBeacon.Video != beacon.Video) { File.Delete(HttpContext.Current.Server.MapPath("~" + oldBeacon.Video)); } } beaconProvider.StoreBeacon(beacon); beaconProvider.Persist(); }