public async Task <DeviceAssociationResult> EditDeviceWithUserAssociation(UserDeviceAssociation userDevice) { int userId = 0; bool isDeviceAssociationSuccess = false; var deviceId = await _devicerepo.IsDeviceTagExist(userDevice.TagName); if (deviceId > 0) { userId = await _devicerepo.GetUserIdbyDeviceId(deviceId); if (userId == 0) { var userdeviceDto = new UserDeviceDTO() { UserId = userDevice.UserId, DeviceId = deviceId }; await _devicerepo.EditDevice(userdeviceDto, userDevice.DeviceName); isDeviceAssociationSuccess = true; } } return(DeriveDeviceAssociationResult(deviceId, userId, userDevice, isDeviceAssociationSuccess)); }
private DeviceAssociationResult DeriveDeviceAssociationResult(int deviceId, int userId, UserDeviceAssociation userDevice, bool isSuccess) { if (isSuccess) { return new DeviceAssociationResult() { IsDeviceUserAssociationSucceded = true, Message = sucessMessage } } ; bool isSameUser = (userId > 0 && userId == userDevice.UserId) ? true : false; if (deviceId == 0) { return new DeviceAssociationResult() { IsDeviceUserAssociationSucceded = false, Message = invalidDeviceTag } } ; else if (!isSameUser) { return new DeviceAssociationResult() { IsDeviceUserAssociationSucceded = false, Message = deviceTagAssociatedOtherUser } } ; else { return new DeviceAssociationResult() { IsDeviceUserAssociationSucceded = false, Message = deviceTagAlreadyAssociated } }; } } }