public async Task <InvokeResult> AddNoteAsync(string deviceid, [FromBody] DeviceNote deviceNote) { var repo = await GetDeviceRepositoryWithSecretsAsync(); return(await _deviceManager.AddNoteAsync(repo, deviceid, deviceNote, OrgEntityHeader, UserEntityHeader)); }
public async Task <InvokeResult> AddNoteAsync(DeviceRepository deviceRepo, string id, DeviceNote note, EntityHeader org, EntityHeader user) { var device = await GetDeviceByIdAsync(deviceRepo, id, org, user); if (device == null) { return(InvokeResult.FromErrors(Resources.ErrorCodes.CouldNotFindDeviceWithId.ToErrorMessage())); } await AuthorizeAsync(device, AuthorizeActions.Update, user, org); if (string.IsNullOrEmpty(note.CreationDate)) { note.CreationDate = device.CreationDate; } if (string.IsNullOrEmpty(note.LastUpdatedDate)) { note.LastUpdatedDate = device.LastUpdatedDate; } if (EntityHeader.IsNullOrEmpty(note.LastUpdatedBy)) { note.LastUpdatedBy = user; } if (EntityHeader.IsNullOrEmpty(note.CreatedBy)) { note.CreatedBy = user; } if (String.IsNullOrEmpty(note.Id)) { note.Id = Guid.NewGuid().ToId(); } ValidationCheck(note, Actions.Create); device.Notes.Add(note); var repo = GetRepo(deviceRepo); await repo.UpdateDeviceAsync(deviceRepo, device); return(InvokeResult.Success); }
public async Task <InvokeResult> AddNoteAsync(DeviceRepository deviceRepo, string id, DeviceNote note, EntityHeader org, EntityHeader user) { var device = await GetDeviceByIdAsync(deviceRepo, id, org, user); if (device == null) { return(InvokeResult.FromErrors(Resources.ErrorCodes.CouldNotFindDeviceWithId.ToErrorMessage())); } await AuthorizeAsync(device, AuthorizeActions.Update, user, org); if (deviceRepo.RepositoryType.Value == RepositoryTypes.AzureIoTHub) { var setRepoResult = await SetDeviceRepoAccessKeyAsync(deviceRepo, org, user); if (!setRepoResult.Successful) { return(setRepoResult); } } device.LastUpdatedBy = user; device.LastUpdatedDate = DateTime.UtcNow.ToJSONString(); if (String.IsNullOrEmpty(note.CreationDate)) { note.CreationDate = device.CreationDate; } if (String.IsNullOrEmpty(note.LastUpdatedDate)) { note.LastUpdatedDate = device.LastUpdatedDate; } if (EntityHeader.IsNullOrEmpty(note.LastUpdatedBy)) { note.LastUpdatedBy = user; } if (EntityHeader.IsNullOrEmpty(note.CreatedBy)) { note.CreatedBy = user; } device.Notes.Add(note); if (deviceRepo.RepositoryType.Value == RepositoryTypes.Local) { await _deviceConnectorService.UpdateDeviceAsync(deviceRepo.Instance.Id, device, org, user); } else { await _deviceRepo.UpdateDeviceAsync(deviceRepo, device); } deviceRepo.AccessKey = null; return(InvokeResult.Success); }
public async Task <InvokeResult> AddNoteAsync(string devicerepoid, string id, [FromBody] DeviceNote deviceNote) { var repo = await _repoManager.GetDeviceRepositoryAsync(devicerepoid, OrgEntityHeader, UserEntityHeader); return(await _deviceManager.AddNoteAsync(repo, id, deviceNote, OrgEntityHeader, UserEntityHeader)); }