/// <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"); } }