private IPageVm BuildNewAddressVm(EmployeeEntity employeeEntity, AddEmployeeAddressCommand command) => BuildeAddressesTab(employeeEntity).Link(RelTypes.Self, "New Address", AddAddressUri(new AddEmployeeAddressQuery(employeeEntity.EmployeeId))) .Link(RelTypes.Breadcrumb, "New Address", AddAddressUri(new AddEmployeeAddressQuery(employeeEntity.EmployeeId))) .Property(nameof(AddEmployeeAddressCommand.Address), "Address", command.Address) .Property(nameof(AddEmployeeAddressCommand.Zip), "ZIP", command.Zip) .Property(nameof(AddEmployeeAddressCommand.City), "City", command.City) .Property(nameof(AddEmployeeAddressCommand.Country), "Country", command.Country) .Property(nameof(AddEmployeeAddressCommand.Description), "Description", command.Description) .Build() .ToFormVm();
public async Task <CommandExecutionResult> HandleAsync(AddEmployeeAddressCommand command) { //TypeAdapterConfig<AddEmployeeAddressCommand, AddressEntity>.NewConfig() // .Map(entity => entity.SubjectId, cmd => cmd.EmployeeId); var addressEntity = command.Adapt <AddressEntity>(); await _repository.InsertAsync(addressEntity); return(CommandExecutionResult.Success); }
public async Task <IActionResult> AddAddress( AddEmployeeAddressQuery query, AddEmployeeAddressCommand command) { CommandExecutionResult cer = null; if (ModelState.IsValid == false || (cer = await _employeeService.HandleAsync(command))?.HasError == true) { _builder.Property("error", "error", cer?.ErrorMessage); var queryExecutionResult = await _employeeService.HandleAsync(query); var vm = BuildNewAddressVm(queryExecutionResult.Result, command); return(PartialView(vm)); } await _notificationService.HandleAsync(new CreateNotificationCommand(query.EmployeeId, "A new address is added to the employee address list.")); return(Redirect(AddressesUri(new SearchEmployeeAddressQuery(query.EmployeeId)))); }