public ICommandResult Handle(EditCustomerCommand command) { if (!customerRepository.CheckCustomer(command.Id)) { AddNotification("Cliente", "O Cliente não existe."); } //Criar os VOs var name = new Name(command.FirstName, command.LastName); var document = new Document(command.Document); var email = new Email(command.Email); //Criar Entidade var customer = new Customer(name, document, email, command.Phone); //Validar Entidades e VOs AddNotifications(command.Notifications); AddNotifications(name.Notifications); AddNotifications(document.Notifications); //AddNotifications(email.Notifications); if (Invalid) { return(new CommandResult(false, "Não foi possível editar os dados", Notifications)); } //edita dados do usuário. customerRepository.EditCustomer(command.Id, command.Document, command.FirstName, command.LastName, command.Email); // //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 EditCustomer_CommandHandle_UpdatesExistingCustomer() { //Arrange var customer = new AllMarkt.Entities.Customer { Address = "address", PhoneNumber = "0123654789" }; AllMarktContextIM.Customers.Add(customer); await AllMarktContextIM.SaveChangesAsync(); var existingCustomer = AllMarktContextIM.Customers.First(); var editCustomerCommand = new EditCustomerCommand { Id = existingCustomer.Id, Address = "editedAddress", PhoneNumber = "0147852369" }; //Act await _editCustomerCommandHandler.Handle(editCustomerCommand, CancellationToken.None); //Assert AllMarktContextIM.Customers.Should().Contain(x => x.Id == editCustomerCommand.Id); customer.Address.Should().Be(editCustomerCommand.Address); customer.PhoneNumber.Should().Be(editCustomerCommand.PhoneNumber); }
public async Task <IActionResult> EditCustomer(int?id, CustomerDto customerDto) { if (id != customerDto.Id) { return(NotFound()); } var request = new EditCustomerCommand(id, customerDto); var response = await _mediator.Send(request); return(RedirectToAction(nameof(Index))); }
public CustomerViewModel(CustomerDataService CustomerDataService) { _customerDataService = CustomerDataService; Customers = new BindableCollection <Customers>(); addCustomerCommand = new AddCustomerCommand(this); deleteCustomerCommand = new DeleteCustomerCommand(this); EditCustomerCommand = new EditCustomerCommand(this); CustomerConverter = new CustomerConverter(); Load(); }
public ActionResult edit([FromBody] EditCustomerCommand command) { var result = _editCustomerCommandHandler.Handle(command); if (_editCustomerCommandHandler.Notifications.Any()) { return(BadRequest(new CustomErrorResult(_editCustomerCommandHandler.Notifications))); } return(Ok(new CustomSuccessResult(result))); }
public Task EditCustomerAsync(CustomerViewModel customerViewModel) { var editCustomerCommand = new EditCustomerCommand { Id = customerViewModel.Id, PhoneNumber = customerViewModel.PhoneNumber, Address = customerViewModel.Address }; return(_mediator.Send(editCustomerCommand, default(CancellationToken))); }
public void EditCustomerTest_InvalidId_ThrowsCustomerNotFoundException() { var mediator = TestMediatorFactory.BuildMediator(_dbContext); var command = new EditCustomerCommand { Id = new Guid("55000000-0000-0000-0000-000000000000"), FirstName = "John edited", LastName = "Doe edited", DateOfBirth = new DateTime(2000, 1, 2) }; Assert.Throws <CustomerNotFoundException>(() => mediator.Send(command).GetAwaiter().GetResult()); }
public async Task HandleAsync_Valid() { var customerRepositoryMock = new Mock <ICustomerRepository>(); var mapperMock = new Mock <IMapper>(); var id = Guid.Parse("926a4480-61f5-416a-a16f-5c722d8463f7"); var command = new EditCustomerCommand { Id = id, FirstName = "Mary 2", LastName = "Smith 2", }; var customerId = new CustomerIdentity(id); var referenceNumber = new CustomerReferenceNumber(DateTime.Now, "ABC12"); var customer = new Customer(customerId, referenceNumber, "Mary", "Smith"); var updatedCustomer = new Customer(customerId, referenceNumber, "Mary 2", "Smith 2"); var expectedResponse = new EditCustomerCommandResponse { Id = id, FirstName = "Mary 2", LastName = "Smith 2", }; customerRepositoryMock .Setup(e => e.FindAsync(customerId)) .ReturnsAsync(customer); customerRepositoryMock .Setup(e => e.UpdateAsync(updatedCustomer)); mapperMock .Setup(e => e.Map <Customer, EditCustomerCommandResponse>(updatedCustomer)) .Returns(expectedResponse); var handler = new EditCustomerCommandHandler(customerRepositoryMock.Object, mapperMock.Object); var response = await handler.HandleAsync(command); customerRepositoryMock.Verify(e => e.FindAsync(customerId), Times.Once()); customerRepositoryMock.Verify(e => e.UpdateAsync(updatedCustomer), Times.Once()); mapperMock.Verify(e => e.Map <Customer, EditCustomerCommandResponse>(customer), Times.Once()); response.Should().BeEquivalentTo(expectedResponse); }
public async Task <IActionResult> Update(Guid id, EditCustomerCommand command) { command.Id = id; try { await _mediator.Send(command); } catch (CustomerNotFoundException) { return(NotFound()); } return(NoContent()); }
public void EditCustomerTest_FieldsShouldBeEdited() { var mediator = TestMediatorFactory.BuildMediator(_dbContext); var command = new EditCustomerCommand { Id = new Guid("20000000-0000-0000-0000-000000000000"), FirstName = "John edited", LastName = "Doe edited", DateOfBirth = new DateTime(2000, 1, 2) }; mediator.Send(command).GetAwaiter().GetResult(); var johnEdited = _dbContext.Customers.First(x => x.Id == new Guid("20000000-0000-0000-0000-000000000000")); Assert.Equal("John edited", johnEdited.FirstName); Assert.Equal("Doe edited", johnEdited.LastName); Assert.Equal(new DateTime(2000, 1, 2), johnEdited.DateOfBirth); }
public async Task <IActionResult> PutCustomer([FromBody] dynamic body) { try { var cmd = new EditCustomerCommand { DateBirthday = (DateTime)body.dateBirthday, Document = (string)body.document, CustomerId = (Guid)body.customerId, Gender = (bool)body.gender, Phone = (string)body.phone, }; var result = _service.EditeCustomer(cmd); return(await CreateResponse(result)); } catch (Exception ex) { return(await ServerErroApp(ex)); } }
public ObjectRequest EditeCustomer(EditCustomerCommand cmd) { var customer = _repCustomer.GetEntity(cmd.CustomerId); if (customer == null) { return(new ObjectRequest() .CreateObjectRequest($"Cliente {cmd.Document} não registrado no Sistema ! ", false)); } customer.Edit(cmd.Document, cmd.DateBirthday, cmd.Phone, cmd.Gender); _repCustomer.EditEntity(customer); if (Commit(customer)) { return(new ObjectRequest().CreateObjectRequest($"Dados do Cliente {cmd.Document} foram alterados com sucesso !", true)); } return(new ObjectRequest().CreateErrorNotification(customer.ListErrors())); }
public async Task <IActionResult> EditCustomer(EditCustomerCommand query, [FromServices] IMapper mapper) { if (!ModelState.IsValid) { var customer = new Customer(); return(View(mapper.Map(query, customer))); } else { try { await _mediator.Send(query); TempData["successMessage"] = "Customer updated"; return(RedirectToAction("index", new { customerId = query.CustomerId })); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(View(mapper.Map(query, new Customer()))); } } }
public IActionResult Edit(EditCustomerCommand command) { return(GetResponse(() => _handler.Handle(command))); }
public async Task <ActionResult <EditCustomerCommandResponse> > EditCustomerAsync(Guid id, EditCustomerCommand request) { if (id != request.Id) { return(BadRequest("Mismatching id in route and request")); } var response = await _messageBus.SendAsync(request); return(Ok(response)); }
public object Handle(EditCustomerCommand command) { //TODO - IMPLEMENTAR TODO O FLUXO DA ENTIDADE ANTES DE EDITAR return(null); }
public async Task <ActionResult <int> > EditCustomer(EditCustomerCommand command) { return(await Mediator.Send(command)); }
public ICommandResult Put([FromBody] EditCustomerCommand command) => handler.Handle(command);
public Task <ObjectClientResponse <EditCustomerCommandResponse> > EditCustomerAsync(EditCustomerCommand request, HeaderData header) { return(Client.PutByIdAsync <Guid, EditCustomerCommand, EditCustomerCommandResponse>(request.Id, request, GetHeaders(header))); }
public ActionResult Edit(CustomerViewModel customerViewModel) { if (ModelState.IsValid) { var editCustomerCommand = new EditCustomerCommand(); Mapper.CreateMap<CustomerViewModel, EditCustomerCommand>(); Mapper.Map(customerViewModel, editCustomerCommand); CommandProcessor.Process<EditCustomerCommand, CommandResult>(editCustomerCommand, ModelState); if (!ModelState.IsValid) return View(); return this.RedirectToAction(c => c.Index(null, null)); } return View(); }