public async Task <IActionResult> AddAssets([FromBody] AddAssetRequest request) { var createServiceCommand = new CreateAssetCommand(request); var result = await mediator.Send(createServiceCommand); return(StatusCode((int)result.Code, result.Value)); }
public async Task <IActionResult> CreateGroup([FromBody] CreateAssetCommand command) { command.IsGroup = true; var newValue = await _assetService.Create(command); foreach (var item in command.Assets) { _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.AssetGroup, FromId = newValue.Id, ToType = ObjectType.Asset, ToId = item }); } if (command.ContainerRootId.HasValue) { _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Container, FromId = command.ContainerRootId.Value, ToType = ObjectType.AssetGroup, ToId = newValue.Id }); } _auditTrailService.LogAction(AuditTrailAction.CreateAssetGroup, newValue.Id, new AuditTrailPayloadModel() { Data = JsonConvert.SerializeObject(command) }); return(Ok(newValue)); }
public Asset Create(CreateAssetCommand command) { var newValue = _assetService.Create(command).Result; if (command.ContainerRootId.HasValue) { _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Container, FromId = command.ContainerRootId.Value, ToType = ObjectType.Asset, ToId = newValue.Id, CreateByUserId = command.CreateByUserId, Payload = JsonConvert.SerializeObject(new AssetPayloadModel() { X = command.PayloadData?.X, Y = command.PayloadData?.Y }) }); } _auditTrailService.LogAction(AuditTrailAction.CreateAsset, newValue.Id, new AuditTrailPayloadModel() { Data = JsonConvert.SerializeObject(command) }); return(newValue); }
protected async Task <int> AddAsset(CreateAssetCommand createAssetKeyValid, HttpClient _client) { var stringContentsDictionary = ObjectAttributesToDicionary(createAssetKeyValid); HttpRequestMessage requestMessage = HttpRequestHelper.PrepareMultipartFormWithFile(HttpMethod.Post, "api/v1/asset", stringContentsDictionary, _imgAssetValidPath); var response = await _client.SendAsync(requestMessage); string responseJson = await response.Content.ReadAsStringAsync(); return(JsonSerializer.Deserialize <Identifier>(responseJson).id); }
public CreateAssetCommandsTests() { _assetList = new List <Asset>(); _createAssetCommand = new CreateAssetCommand { FileURI = "webURI", Name = "moq", Image = new Mock <IFormFile>().Object, CategoriesIds = new List <int> { 2, 4 } }; _context = new Mock <IApplicationDbContext>(); _mapper = new Mock <IMapper>(); _fileService = new Mock <IFileService>(); _fileServiceFactory = new Mock <IFileServiceFactory>(); }
public Setup() { _createAssetKeyValid = new CreateAssetCommand { Name = Guid.NewGuid().ToString(), FileURI = "key.fbx", CategoriesIds = new List <int> { 2, 4 } }; _createAssetKeyInvalid = new CreateAssetCommand { Name = "", FileURI = "" }; _updateAssetKeyValid = new UpdateAssetComamnd { Name = Guid.NewGuid().ToString(), FileURI = "key.fbx", CategoriesIds = new List <int> { 2 } }; _updateAssetKeyInvalid = new UpdateAssetComamnd { Name = "", FileURI = "" }; _deletAssetKey = new DeleteAssetCommand(); _validManagerUser = new ApplicationUser { Username = "******", Password = "******" }; _validOperatorUser = new ApplicationUser { Username = "******", Password = "******" }; _invalidUser = new ApplicationUser { Username = "******", Password = "******" }; _erroFormatUser = new ApplicationUser { Username = "", Password = "******" }; var baseTestProjectDirectory = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "../../../../")); _imgAssetValidPath = $"{baseTestProjectDirectory}TestFiles/helmet.jpg"; _imgAssetValidPath2 = $"{baseTestProjectDirectory}TestFiles/gloves2.jpg"; _imgAssetValidPath3PNG = $"{baseTestProjectDirectory}TestFiles/helmet.png"; _imgAssetInvalidFileTXT = $"{baseTestProjectDirectory}TestFiles/texto.txt"; }
public async Task <ActionResult> Insert([FromForm] CreateAssetCommand command) { try { var id = await _mediator.Send(command); return(new OkObjectResult(new { id })); } catch (ValidationException ve) { return(new BadRequestObjectResult(new { errorMessage = ve.Message, errorList = ve.Errors })); } catch (Exception e) { return(new StatusCodeResult(500)); } }
public async Task ShouldCreateAssetAsync() { var command = new CreateAssetCommand { Name = "test", Value = 100 }; var id = await Fixture.SendAsync(command); var asset = await Fixture.FindAsync <Asset>(id); asset.Should().NotBeNull(); asset.Name.Should().Be(command.Name); asset.Value.Should().Be(command.Value); asset.Created.Should().BeCloseTo(DateTime.Now, 10000); }
public async Task <IActionResult> CreateAsset(Guid id, [FromBody] CreateAssetCommand command) { try { command.SchemaId = id; Asset asset = await this._mediator.Send(command); return(Ok(asset)); } catch (SchemaDomainException exception) { this._logger.LogError(0, exception, exception.Message); return(BadRequest(exception.Message)); } catch (Exception exception) { this._logger.LogError(0, exception, exception.Message); return(BadRequest()); } }
public async Task <ActionResult <AssetModel> > PostAsset(AssetInputModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var command = new CreateAssetCommand { Input = model }; var result = await Mediator.Send(command, HttpContext.RequestAborted) .ConfigureAwait(false); if (result.IsFailure) { return(result.AsActionResult()); } return(CreatedAtAction(nameof(GetAsset), new { id = result.Value.Id }, result.Value)); }
[RequestFormLimits(MultipartBodyLengthLimit = 1 << 30)] // 1 GiB public async Task <IActionResult> PostAssets(string id, [FromForm(Name = "file")] IFormFile file, [FromForm(Name = "tag")] string tag, CancellationToken cancellationToken) { if (file == null || file.Length == 0) { return(BadRequest()); } using var stream = file.OpenReadStream(); var command = new CreateAssetCommand { ReleaseId = id, FileName = file.FileName, FileStream = stream, Tag = tag }; var result = await _mediator.Send(command, cancellationToken); var resource = await _mediator.Send(new GetAssetQuery { Id = result.Id }); return(CreatedAtAction("Get", _assetControllerName, new { id = resource.Id }, resource)); }
public new IActionResult Create([FromBody] CreateAssetCommand command) => Ok(base.Create(command));
public async Task <IActionResult> Post([FromBody] CreateAssetCommand command) { var assetId = await _mediator.Send(command); return(CreatedAtAction(nameof(Get), new { id = assetId }, assetId)); }
public async Task <Asset> Create(CreateAssetCommand command) => await _mediator.Send(command);
public async Task <ActionResult <int> > create(CreateAssetCommand command) { return(await Mediator.Send(command)); }