public CommandResult Update(ProductUpdateCommand command) { var product = _repository.GetById(command.Id); if (product == null) { return(new CommandResult(false, "Produto não encontrado na base de dados. ", null)); } var exist = _repository.ExistsUpdate(command.Name, command.Id); if (exist) { return(new CommandResult(false, "Já existe outro Produto cadatrado com esse Nome. ", null)); } product.Update(command.Name, command.Price); AddNotifications(product); if (Invalid) { return(new CommandResult(false, GroupNotifications.Group(Notifications), null)); } _repository.Update(product); return(new CommandResult(true, "Produto atualizado com sucesso!. ", product)); }
public async Task <IActionResult> Put(ProductUpdateCommand command) { if (!ModelState.IsValid) { return(BadRequest()); } return(Ok(await mediator.Send(command))); }
public static ProductUpdateCommand ProductCommandToUpdate() { ProductUpdateCommand product = new ProductUpdateCommand(); product.Code = "ABY-Y7ASA"; product.Description = "Bolacha Maria"; product.UnitaryValue = 10.00; return(product); }
public CommandResult Update(string id, ProductUpdateCommand command) { if (id != command.Id) { return(new CommandResult(false, "Id inválido. ", null)); } var result = _handler.Handle(command); return(result); }
public IHttpActionResult Update(ProductUpdateCommand command) { var validator = command.Validate(); if (!validator.IsValid) { return(HandleValidationFailure(validator.Errors)); } return(HandleCallback(_productService.Update(command))); }
public bool Update(ProductUpdateCommand command) { var product = _productRepository.GetById(command.Id); if (product == null) { throw new NotFoundException(); } Mapper.Map(command, product); return(_productRepository.Update(product)); }
public bool Update(ProductUpdateCommand productCmd) { var product = _repositoryProduct.GetById(productCmd.Id); if (product == null) { throw new NotFoundException(); } // Mapeia para o objeto do banco que está tracking pelo EF Mapper.Map(productCmd, product); return(_repositoryProduct.Update(product)); }
public void UpdateProductHandler_Null_Name_Invalid() { var repository = new FakeProductRepository(); var handler = new ProductHandler(repository); var command = new ProductUpdateCommand(); command.Id = repository.GetAll().FirstOrDefault().Id; command.Name = null; command.Price = 5.5m; var result = handler.Update(command); Assert.False(result.Success, result.Message); }
public async Task <string> Handle(ProductUpdateCommand request, CancellationToken cancellationToken) { var product = mapper.Map <ProductEntity>(request); await repository.Update(product); await mediator.Publish(new ProductActionNotification { Action = ActionNotification.Modified, Id = product.Id, Name = product.Name, Price = product.Price }); return(await Task.FromResult("Produto atualizado com sucesso.")); }
public void UpdateProductHandler_valid() { var repository = new FakeProductRepository(); var handler = new ProductHandler(repository); var command = new ProductUpdateCommand(); command.Id = repository.GetAll().FirstOrDefault().Id; command.Name = "Product X"; command.Price = 9.5m; var result = handler.Handle(command); Assert.True(result.Success, result.Message); }
public async Task <ICommandResult> Handle(ProductUpdateCommand command) { //FFV command.Validate(); if (command.Invalid) { return(new GenericCommandResult( false, HttpStatusCode.BadRequest, command.Notifications)); } var _verify = await _productRepository.FindById(command.Id); if (_verify == null) { return(new GenericCommandResult(false, HttpStatusCode.NotFound, "Não localizado na base")); } var product = new Product { Id = command.Id, CategoryId = command.CategoryId, Description = command.Description, ManufacturerId = command.ManufacturerId, YearOfManufacture = command.YearOfManufacture, Model = command.Model, CharacteristicDescriptions = command.CharacteristicDescriptions }; var _result = await _productRepository.Update(product); //retorna o resultado if (!_result) { return(new GenericCommandResult(false, HttpStatusCode.BadRequest, _result)); } return(new GenericCommandResult(true, HttpStatusCode.OK, _result)); }
public CommandResult Update(ProductUpdateCommand productUpdate, List <WarehouseCreateCommand> warehouseCommandList) { if (productUpdate.IsValid() == false) { return(CommandResult.Error(productUpdate.ValidationResult.ToString())); } if (_productRepository.Exists(productUpdate.Sku) == false) { return(CommandResult.Error("Sku do produto não existe.")); } foreach (var item in warehouseCommandList) { if (item.IsValid() == false) { return(CommandResult.Error(item.ValidationResult.ToString())); } } var product = new Product(sku: productUpdate.Sku, name: productUpdate.Name); var warehouseList = warehouseCommandList .Select(x => new Warehouse( sku: product.Sku, locality: x.Locality, quantity: x.Quantity, type: x.Type )); _productRepository.Update(product); _warehouseRepository.Delete(product.Sku); foreach (var warehouse in warehouseList) { _warehouseRepository.Create(warehouse); } return(CommandResult.Ok()); }
public async Task <IActionResult> Update(ProductUpdateCommand productUpdateCommand) { return(StatusCode(200, await _mediator.Send(productUpdateCommand))); }
public async Task <GenericCommandResult> UpdateProduct( [FromBody] ProductUpdateCommand command, [FromServices] IHandler <ProductUpdateCommand> handler) { return((GenericCommandResult)await handler.Handle(command)); }
/// <summary> /// Yapıcı metod. Her yeni Ürün ViewModel nesnesi oluşturulduğunda çalışır. /// </summary> public ProductViewModel() { _product = new ProductModel(1, "Macbook Pro", "i5 işlemcili Macbook Pro", 3400); UpdateCommand = new ProductUpdateCommand(this); DeleteCommand = new ProductDeleteCommand(this); }
public async Task UpdateAsync(ProductDTO productDTO) { ProductUpdateCommand productUpdateCommand = _mapper.Map <ProductUpdateCommand>(productDTO); await _mediator.Send(productUpdateCommand); }
public async Task <ActionResult> Update(ProductUpdateCommand command) { await MediatorService.ExecuteHandler(command); return(NoContent()); }