public ActionResult <ReaderDevicesUpdateResponse> AddDevicesToReaders(ReaderDevicesUpdate request) { try { List <GXDeviceToReader> list = new List <GXDeviceToReader>(); for (int pos = 0; pos != request.Readers.Length; ++pos) { GXDeviceToReader it = new GXDeviceToReader(); it.ReaderId = request.Readers[pos]; it.DeviceId = request.Devices[pos]; if (it.ReaderId == 0) { return(BadRequest(Gurux.DLMS.AMI.Properties.Resources.ReaderIdIsZero)); } if (it.DeviceId == 0) { return(BadRequest(Gurux.DLMS.AMI.Properties.Resources.DeviceIdIsZero)); } list.Add(it); } host.Connection.Insert(GXInsertArgs.InsertRange(list)); host.SetChange(TargetType.Readers | TargetType.Device, DateTime.Now); return(new ReaderDevicesUpdateResponse()); } catch (Exception ex) { return(BadRequest(ex)); } }
public ActionResult <ReaderDevicesUpdateResponse> RemoveDevicesFromReaders(ReaderDevicesUpdate request) { List <GXDeviceToReader> list = new List <GXDeviceToReader>(); for (int pos = 0; pos != request.Readers.Length; ++pos) { GXDeviceToReader it = new GXDeviceToReader(); it.ReaderId = request.Readers[pos]; it.DeviceId = request.Devices[pos]; list.Add(it); } host.Connection.Delete(GXDeleteArgs.DeleteRange(list)); host.SetChange(TargetType.Readers | TargetType.Device, DateTime.Now); return(new ReaderDevicesUpdateResponse()); }