/// <summary> /// Function to check if device is assigned to an event. /// </summary> /// <param name="dId"></param> /// <param name="eId"></param> /// <returns>True if device is assigned, false otherwise.</returns> public Boolean DeviceAssigned(DevicesInEvent d) { var r = (from x in _repo.GetDevicesInEvents() where x.DeviceId == d.DeviceId & x.EventId == d.EventId select x).Any(); return(r); }
public bool RemoveDeviceInEvent(DevicesInEvent d) { var result = false; if (_db.DevicesInEvents.Remove(d) != null) { result = true; } _db.SaveChanges(); return(result); }
public bool AddDeviceToEvent(DevicesInEvent d) { var result = false; if (_db.DevicesInEvents.Add(d) != null) { result = true; } _db.SaveChanges(); return(result); }
public async Task <bool> RemoveDeviceInEventAsync(DevicesInEvent d) { var result = false; if (_db.DevicesInEvents.Remove(d) != null) { result = true; } await _db.SaveChangesAsync(); return(result); }
public async Task <bool> AddDeviceToEventAsync(DevicesInEvent d) { var result = false; if (await _db.DevicesInEvents.AddAsync(d) != null) { result = true; } await _db.SaveChangesAsync(); return(result); }
/// <summary> /// Function to assign device to an event. /// </summary> /// <param name="dId"></param> /// <param name="eId"></param> /// <returns>Returns instance of the assignment.</returns> public async Task <DevicesInEvent> AddDeviceInEventAsync(int dId, int eId) { var d = new DevicesInEvent { DeviceId = dId, EventId = eId }; if (DeviceAssigned(d) == false) { await _repo.AddDeviceToEventAsync(d); return(d); } else { var n = await GetDeviceByIdAsync(dId); throw new Exception(n.Name + " is already assigned to this event"); } }
/// <summary> /// Function to unassign device from event. /// </summary> /// <param name="d"></param> /// <returns>True if success, false otherwise.</returns> public async Task <Boolean> RemoveDeviceInEventAsync(DevicesInEvent d) { return(await _repo.RemoveDeviceInEventAsync(d)); }