public ICommandResult Handle(UpdateAddressCommand command)
        {
            command.Validate();
            AddNotifications(command);

            var student = _studentRepository.GetById(command.StudentID);
            var address = _addressRepository.GetById(command.AddressID);

            AddNotifications(new Contract()
                             .Requires()
                             .IsNotNull(student, "student", "O aluno não existe")
                             .IsNotNull(address, "student", "O endereço não existe"));

            address.UpdateAddress(
                command.ZipCode,
                command.Street,
                command.Number,
                command.Neighborhood,
                command.City,
                command.State,
                command.PhoneNumber,
                command.CellPhoneNumber);

            AddNotifications(student, address);

            if (Invalid)
            {
                return(new CommandResult(false, "Erro ao adicionar.", Notifications));
            }

            _addressRepository.Update(address);

            return(new CommandResult(true, "Dados cadastrados com sucesso", Notifications));
        }
        public async Task <ActionResult> Update(int id, UpdateAddressCommand command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }

            await Mediator.Send(command);

            return(NoContent());
        }
        public void ShouldRequireValidAddressId()
        {
            var command = new UpdateAddressCommand
            {
                Id       = 99999,
                Street   = "Łąćna",
                City     = "Poznań",
                PostCode = "66666"
            };

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().Throw <NotFoundException>();
        }
Exemple #4
0
        private static void _changeAddress(Guid aggId, ICommandDispatcher <Customer> dispatcher)
        {
            // Get the command from the API (AMQP/REST..)
            var commandId   = Guid.NewGuid();               // CLIENT genrated command id.
            var dateCreated = DateTime.Now;                 // Date/Time the client created the command
            var issuedBy    = "*****@*****.**"; // Identity, like username of user who issued the command
            var command     = new UpdateAddressCommand(commandId, dateCreated, aggId, issuedBy)
            {
                NewAddressDetails = Faker.Address.StreetAddress()
            };

            // Dispatch the command
            dispatcher.Dispatch(command);
        }
 private void BuildUpdateAdressCommand()
 {
     _updateAddressCommand                 = new UpdateAddressCommand();
     _updateAddressCommand.StudentID       = _student.Id;
     _updateAddressCommand.AddressID       = _student.Address.Id;
     _updateAddressCommand.ZipCode         = "80030001";
     _updateAddressCommand.Street          = "Av. João Gualberto 1259";
     _updateAddressCommand.Number          = 1259;
     _updateAddressCommand.Neighborhood    = "Juvevê";
     _updateAddressCommand.City            = "Curitiba";
     _updateAddressCommand.State           = "PR";
     _updateAddressCommand.PhoneNumber     = "31569151";
     _updateAddressCommand.CellPhoneNumber = "988334701";
 }
        public ActionResult UpdateAddress(UpdateAddressCommand updateAddressCommand)
        {
            if (!ModelState.IsValid)
            {
                return(this.View());
            }

            var context          = new AppDbContext();
            var customerToUpdate = context.Customers.Find(updateAddressCommand.CustomerId);

            customerToUpdate.Email = updateAddressCommand.Address;
            context.SaveChanges();
            return(RedirectToAction("UpdateAddress"));
        }
Exemple #7
0
        public async Task <ActionResult <Address> > UpdateAddress(int addressId, UpdateAddressCommand updateAddressCommand)
        {
            try
            {
                updateAddressCommand.SetAddressId(addressId);
                Address address = await this.mediator.Send(updateAddressCommand);

                return(Ok(address));
            }
            catch (Exception ex)
            {
                return(this.BadRequest(ex));
            }
        }
        public async Task <IActionResult> Update(string id, [FromBody] UpdateAddressRequest updateAddressRequest)
        {
            try
            {
                //request validation should be here
                // ...

                var command = new UpdateAddressCommand(id, updateAddressRequest.Name, updateAddressRequest.City, updateAddressRequest.Street);
                await _mediator.Send(command);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(new ErrorResponse()
                {
                    ShortInfo = e.Message, AdditionalInfo = e.StackTrace
                }));
            }
        }
        public async Task ShouldUpdateAddress()
        {
            var userId = await RunAsDefaultUserAsync();

            var employeeId = await SendAsync(new CreateEmployeeCommand
            {
                FirstName = "TestFirstName",
                LastName  = "TestUpdateLastName",
                Email     = "*****@*****.**",
                Pesel     = "12345612"
            });

            var addressId = await SendAsync(new CreateAddressCommand
            {
                EmployeeId = employeeId,
                Street     = "BeforeUpdateStreet",
                City       = "BeforeUpdateCity",
                PostCode   = "66666"
            });

            var command = new UpdateAddressCommand
            {
                Id       = addressId,
                Street   = "AfterUpdateStreet",
                City     = "AfterUpdateCity",
                PostCode = "1231231"
            };

            await SendAsync(command);

            var addr = await FindAsync <Address>(addressId);

            addr.Should().NotBeNull();
            addr.Street.Should().Be(command.Street);
            addr.City.Should().Be(command.City);
            addr.PostCode.Should().Be(command.PostCode);
            addr.LastModifiedBy.Should().NotBeNull();
            addr.LastModifiedBy.Should().Be(userId);
            addr.LastModified.Should().NotBeNull();
            addr.LastModified.Should().BeCloseTo(DateTime.Now, 1000);
        }
 public async Task <UpdateAddressCommandResponse> UpdateAddress([FromBody] UpdateAddressCommand address)
 {
     return(await _mediator.Send(address));
 }
 public async Task UpdateAddress([FromBody] UpdateAddressCommand command)
 {
     await mediator.Send(command);
 }
 public ActionResult UpdateAddress(UpdateAddressCommand updateAddressCommand)
 {
     return(this.ExecuteCommand(updateAddressCommand, () => this.RedirectToAction("UpdateAddress")));
 }
        public async Task <ActionResult> Update([FromForm] UpdateAddressCommand command)
        {
            await Mediator.Send(command);

            return(NoContent());
        }
Exemple #14
0
 public ICommandResult UpdateAdress([FromBody] UpdateAddressCommand command)
 {
     return(_handler.Handle(command));
 }