public async Task <IActionResult> Update([FromRoute] string objectId, [FromBody] UpdateObjectViewModel request) { if (request == null) { return(BadRequest()); } var objectQuery = new ObjectQuery(objectId); var current = await _objectsRepository.GetObject(objectQuery, CancellationToken.None); if (current == null) { return(NotFound()); } var currentUser = HttpContext.User; var updateCommand = new UpdateObjectCommand(objectId) { Name = request.Name, Description = request.Description, Latitude = request.Latitude, Longitude = request.Longitude, Type = request.Type }; if (request.MainPhoto != null) { updateCommand.MainPhoto = new FileInfo { FileId = request.MainPhoto.FileId, Description = request.MainPhoto.Description }; } if (request.Photos != null) { updateCommand.Photos = request.Photos.Select(x => new FileInfo { FileId = x.FileId, Description = x.Description }).ToList(); } updateCommand.SetCreator( long.Parse(currentUser.FindFirstValue(ClaimTypes.NameIdentifier)).ToString(), currentUser.FindFirstValue(ClaimTypes.Name), currentUser.FindFirstValue(ClaimTypes.Email)); await _objectsRepository.UpdateObject(updateCommand, CancellationToken.None); return(Ok()); }
public async Task GetSingleObject() { var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "1.json"); runner.Import("okn", "objects", path, true); var query = new ObjectQuery("5af2796e32522f798f822a41"); var result = await repo.GetObject(query, CancellationToken.None); Assert.NotNull(result); Assert.Equal(query.ObjectId, result.ObjectId); }
public async Task <IActionResult> GetVersion([FromRoute] string objectId, [FromRoute] long version) { var model = await _objectsRepository.GetObject(new ObjectQuery(objectId, version), CancellationToken.None); if (model == null) { return(NotFound()); } return(Ok(model)); }