public async Task <IActionResult> Create(Product newProduct) { if (string.IsNullOrWhiteSpace(newProduct.Name) || string.IsNullOrWhiteSpace(newProduct.Picture)) { return(BadRequest()); } using var transaction = await this._transactionProvider.BeginTransaction(); var category = await _categoryService.GetOrCreateCategoryByName(newProduct.Category); newProduct.Category = category; var entity = await this._service.AddEntity(newProduct); var newResource = new Resource { Amount = 0, ProductName = entity.Name, ActionHistories = new List <ActionHistory>() }; await _resourceService.AddEntity(newResource); await transaction.CommitAsync(); return(CreatedAtAction(nameof(GetById), new { id = entity.Id.ToString() }, entity)); }