public ProductViewModel(ProductDataService productDataService, IEventAggregator eventAggregator) { this.productDataService = productDataService; SearchProductCommand = new SearchProductCommand(this); DeleteProductCommand = new DeleteProductCommand(this); EditProductCommand = new EditProductCommand(this); }
public static RequestParamValidator[] ProductEditValidator(EditProductCommand editCommand) { return(new[] { new RequestParamValidator(() => editCommand == null, "Request has to be set"), ProductUidValidator(editCommand?.Uid) }); }
public ActionResult Edit(EditProductCommand command) { var result = _commandsBus.Send(command); this.AddToastMessage(result); return(RedirectToAction(nameof(Index))); }
public ICommandResult Handle(EditProductCommand command) { if (!productRepository.CheckProduct(command.Id)) { AddNotification("Produto", "O Produto não existe."); } //Criar Entidade var product = new Product(command.Title, command.Description, command.Image, command.Price, command.QuantityOnHand); //Validar Entidades e VOs AddNotifications(product.Notifications); //AddNotifications(email.Notifications); if (Invalid) { return(new CommandResult(false, "Não foi possível editar os dados", Notifications)); } //edita dados do usuário. productRepository.EditProduct(command.Id, command.Title, command.Description, command.Image, command.Price, command.QuantityOnHand); // //Enviar um E-mail avisando alteração. // _emailService.Send(email.Address, "*****@*****.**", "Alteração de dados", "Seus dados foram Atualizados."); return(new CommandResult(true, "Informações Editadas com Sucesso !")); }
public async Task <IHttpActionResult> Put(Guid?uid, [FromBody] EditProductCommand editProduct) { editProduct.Uid = uid.Value; return(await ProcessCommand( command : () => Mediator.Send(editProduct), paramValidators : RequestParamValidator.ProductEditValidator(editProduct))); }
public async Task <ActionResult <EditProductCommand.Result> > EditProduct( [FromRoute] int supplierId, [FromRoute] int productId, EditProductCommandDto dto) { var command = new EditProductCommand(supplierId, productId, new ProductCode(dto.ProdCode), new ProductName(dto.Name), dto.CategoryId, dto.Price.Value); return(await _mediator.Send(command)); }
public async Task <IActionResult> Edit(int id, [FromBody] EditProductDto dto) { var command = new EditProductCommand( id: id, productName: dto.ProductName); await _editHandler .HandleAsync(command); return(Ok()); }
public void Edit(ProductEditDTO productEditDTO) { EditProductCommand command = new EditProductCommand { Id = productEditDTO.Id, Name = productEditDTO.Name, Price = productEditDTO.Price }; productEdit.Handle(command); }
private void RefreshSource() { _products.Clear(); var returnedProducts = new DbService().ReadFromDb; foreach (var p in returnedProducts) { _products.Add(p); } EditProductCommand.RaiseCanExecuteChanged(); RemoveProductCommand.RaiseCanExecuteChanged(); }
public ActionResult Save(EditProductCommand command) { try { var product = _mediator.Send(command); this.Success(string.Format("Food {0} created", command.Name)); return(RedirectToAction("Show", "Product", new { product.Id })); } catch (Exception) { return(View("Edit", command)); } }
public ActionResult Save(EditProductCommand command) { try { var product = _mediator.Send(command); this.Success(string.Format("Food {0} created", command.Name)); return RedirectToAction("Show", "Product", new {product.Id}); } catch (Exception) { return View("Edit", command); } }
public async Task EditProduct_CommandHandle_UpdatesExistingProduct() { //Arrange var productCategory = new AllMarkt.Entities.ProductCategory { Name = "category", Description = "description" }; AllMarktContextIM.ProductCategories.Add(productCategory); await AllMarktContextIM.SaveChangesAsync(); var product = new AllMarkt.Entities.Product { Name = "Test Name1", Description = "Test Description1", Price = 10, ImageURI = "", State = true, ProductCategory = productCategory }; AllMarktContextIM.Products.Add(product); await AllMarktContextIM.SaveChangesAsync(); var existingProduct = AllMarktContextIM.Products.First(); var editProductCommand = new EditProductCommand { Id = existingProduct.Id, Name = "TestName_EDIT", Description = "TestDescription_EDIT", Price = 11, ImageURI = "abc", State = false, }; //Act await _editProductCommandHandler.Handle(editProductCommand, CancellationToken.None); //Assert AllMarktContextIM.Products.Should().Contain(x => x.Id == editProductCommand.Id); product.Name.Should().Be(editProductCommand.Name); product.Description.Should().Be(editProductCommand.Description); product.Price.Should().Be(editProductCommand.Price); product.ImageURI.Should().Be(editProductCommand.ImageURI); product.State.Should().Be(editProductCommand.State); }
public async Task EditProductNoIdValue() { var client = await GetAdminClientAsync(); var pet = new EditProductCommand { Name = "Name to edit", Price = 10.00M }; var content = Utilities.GetRequestContent(pet); var response = await client.PostAsync("/api/Product/Edit", content); Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); }
public async Task <IActionResult> EditProduct(EditProductCommand command) { if (ModelState.IsValid) { await Mediator.Handle(command); return(RedirectToAction(PRODUCTLIST_ACTION)); } var categories = await Mediator.Handle(new GetAllCategories()); return(View(new EditProductViewModel() { Command = command, Categories = categories })); }
public async Task EditProductExcededNameLenghtByAdminBadRequest() { var client = await GetAdminClientAsync(); var pet = new EditProductCommand { Id = 2, Name = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", Price = 10.00M }; var content = Utilities.GetRequestContent(pet); var response = await client.PostAsync("/api/Product/Edit", content); Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); }
public async Task EditProductByUserNotAuthorized() { var client = await GetUserClientAsync(); var pet = new EditProductCommand { Id = 1, Name = "panecito", Price = 20.00M }; var content = Utilities.GetRequestContent(pet); var response = await client.PostAsync("/api/Product/Edit", content); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); }
public virtual ActionResult Edit(int productId, ProductInputModel productInputs) { var userId = 1; var command = new EditProductCommand { ProductId = productInputs.ProductId, UserId = CurrentUserId(), ProductName = productInputs.ProductName, ProductNotes = productInputs.ProductNotes }; var result = mediator.Send(command); return(RedirectToAction("View", new { productId = productInputs.ProductId })); }
public async Task HandleAsync(EditProductCommand command) { var product = await _repository .GetAsync(command.Id); var productName = ProductName .Create(command.ProductName); product .Edit(productName.Value); _repository .Modify(product); await _unitOfWork .CommitAsync(); }
public void WhenBartChangesTheNameOfTo(string userName, string originalName, string newName) { var user = sessionFactory.OpenSession().Query <User>().First(u => u.UserName == userName); var product = sessionFactory.OpenSession().Query <UserProduct>().First(p => p.Name == originalName); var command = new EditProductCommand { ProductId = product.Id, UserId = user.Id, ProductName = newName, ProductNotes = product.Notes }; var handler = new EditProductCommandHandler(sessionFactory.OpenSession()); handler.Handle(command); }
public async Task <ActionResult <bool> > UpdateProductAsync([FromBody] EditProductCommand editCommand) { _logger.LogInformation( "----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", editCommand.GetGenericTypeName(), nameof(editCommand.Code), editCommand.Code, editCommand); var result = await Mediator.Send(editCommand); if (result) { return(Ok()); } return(StatusCode(500, new { error = "Product can't be updated." })); }
public ActionResult Edit(EditProductCommand command) { if (!ModelState.IsValid) { FillCategories(); return(View("Edit", command)); } var pictures = PreparePicture(command.HttpPostedFileBases, ProductPicturePath); var result = _commandBus.Send(command); if (!result.Success) { return(JsonMessage(result)); } SavePicture(pictures, ProductPicturePath); return(JsonMessage(result)); }
public void CanCreateCommand_From_ProductDTO() { var productDTO = new ProductDTO() { Id = 1, Name = "Test", Description = "TestDescr", CategoryId = 12, Price = 142m }; var actual = EditProductCommand.FromProduct(productDTO); Assert.AreEqual(productDTO.Id, actual.Id); Assert.AreEqual(productDTO.Name, actual.Name); Assert.AreEqual(productDTO.Price, actual.Price); Assert.AreEqual(productDTO.Description, actual.Description); Assert.AreEqual(productDTO.CategoryId, actual.CategoryId); }
public async Task EditSucessful() { var client = await GetAdminClientAsync(); var pet = new EditProductCommand { Id = 1, Name = "newPathName", Price = 100.00M }; var content = Utilities.GetRequestContent(pet); var response = await client.PostAsync("/api/Product/Edit", content); response.EnsureSuccessStatusCode(); var result = await Utilities.GetResponseContent <EditProductResponse>(response); Assert.IsType <EditProductResponse>(result); }
public async Task <IActionResult> EditProduct(int id) { var product = await Mediator.Handle(new GetProductByIdQuery() { ProductId = id }); if (product is null) { return(NotFound()); } var categories = await Mediator.Handle(new GetAllCategories()); var model = new EditProductViewModel() { Command = EditProductCommand.FromProduct(product), Categories = categories }; return(View(model)); }
public async Task EditProduct_NotExist_NotFound() { // Arrange var header = await GetDefaultHeaderDataAsync(); var id = Guid.NewGuid(); var updateRequest = new EditProductCommand { Id = id, Description = "New desc 2", UnitPrice = 140, }; // Act var updateHttpResponse = await Fixture.Api.Products.EditProductAsync(updateRequest, header); // Assert updateHttpResponse.StatusCode.Should().Be(HttpStatusCode.NotFound); }
public ActionResult Edit(EditProductCommand input) { return(TryPush(input)); }
public async Task <ActionResult <EditProductResponse> > Edit([FromBody] EditProductCommand command) { return(Ok(await Mediator.Send(command))); }
public async Task EditProduct_Valid_OK() { // Arrange var header = await GetDefaultHeaderDataAsync(); var createRequests = new List <CreateProductCommand> { new CreateProductCommand { Code = "APP", Description = "Apple", UnitPrice = 10.50m, }, new CreateProductCommand { Code = "BAN", Description = "Banana", UnitPrice = 30.99m, }, new CreateProductCommand { Code = "ONG", Description = "Orange", UnitPrice = 35.99m, }, new CreateProductCommand { Code = "STR", Description = "Strawberry", UnitPrice = 40.00m, }, }; var createHttpResponses = await CreateProductsAsync(createRequests); var someCreateHttpResponse = createHttpResponses[2]; var someCreateResponse = someCreateHttpResponse.Data; var id = someCreateResponse.Id; var updateRequest = new EditProductCommand { Id = id, Description = "New desc", UnitPrice = 130, }; // Act var updateHttpResponse = await Fixture.Api.Products.EditProductAsync(updateRequest, header); // Assert updateHttpResponse.StatusCode.Should().Be(HttpStatusCode.OK); var updateResponse = updateHttpResponse.Data; updateResponse.Should().BeEquivalentTo(updateRequest); }
public async Task EditProduct_Invalid_UnprocessableEntity() { // Arrange var header = await GetDefaultHeaderDataAsync(); var createRequests = new List <CreateProductCommand> { new CreateProductCommand { Code = "APP", Description = "Apple", UnitPrice = 10.50m, }, new CreateProductCommand { Code = "BAN", Description = "Banana", UnitPrice = 30.99m, }, new CreateProductCommand { Code = "ONG", Description = "Orange", UnitPrice = 35.99m, }, new CreateProductCommand { Code = "STR", Description = "Strawberry", UnitPrice = 40.00m, }, }; var createHttpResponses = await CreateProductsAsync(createRequests); var someCreateHttpResponse = createHttpResponses[2]; var someCreateResponse = someCreateHttpResponse.Data; var id = someCreateResponse.Id; var updateRequest = new EditProductCommand { Id = id, Description = "New desc 3", UnitPrice = -2, }; // Act var updateResponse = await Fixture.Api.Products.EditProductAsync(updateRequest, header); // Assert updateResponse.StatusCode.Should().Be(HttpStatusCode.UnprocessableEntity); var problemDetails = updateResponse.ProblemDetails; problemDetails.Status.Should().Be((int)HttpStatusCode.UnprocessableEntity); }
public async Task <ActionResult <EditProductCommandResponse> > EditProductAsync(Guid id, EditProductCommand request) { if (id != request.Id) { return(BadRequest("Mismatching id in route and request")); } var response = await _messageBus.SendAsync(request); return(Ok(response)); }
public ICommandResult Put([FromBody] EditProductCommand command) => handler.Handle(command);