private void attach_Devices(Device entity) { this.SendPropertyChanging(); entity.City = this; }
private void detach_Devices(Device entity) { this.SendPropertyChanging(); entity.City = null; }
public ActionResult RegisterDevice(string platform, string token,long cityId = 1) { var rep = Locator.GetService<IDeviceRepository>(); var device = rep.Find(d => d.Token == token); if (device == null) { device = new Device() { DateRegistred = DateTime.Now, Platform = (short) PlatformUtils.Parse(platform), Token = token, CityId = cityId }; rep.Add(device); rep.SubmitChanges(); } else { if (device.CityId != cityId) { device.City.Devices.Remove(device); Locator.GetService<ICitiesRepository>().Load(cityId).Devices.Add(device); rep.SubmitChanges(); } } return Json(new {content = "OK"}); }