public async Task <IActionResult> Create(CancellationToken cancellationToken, [FromBody] CustomerAddCommand command) { await this.mediator.Send(command, cancellationToken); return(this.NoContent()); }
public void Add(CustomerAddCommand command) { Id = Common.Common.GenerateGuid(); Code = command.Code; string passwordHash = EncryptionExtensions.Encryption(Code, command.Password, out string salt); Email = command.Email ?? string.Empty; EmailToRevalidate = string.Empty; EmailConfirmed = false; AdminComment = command.AdminComment ?? string.Empty; IsTaxExempt = command.IsTaxExempt; LastIpAddress = command.LastIpAddress; BillingAddressId = command.BillingAddressId ?? string.Empty; ShippingAddressId = command.ShippingAddressId ?? string.Empty; Password = passwordHash; PasswordSalt = salt; PhoneNumber = command.PhoneNumber ?? string.Empty; PhoneNumberConfirmed = false; TwoFactorEnabled = command.TwoFactorEnabled; FullName = command.FullName ?? string.Empty; Gender = command.Gender; Birthday = command.Birthday; Type = command.Type; Status = command.Status; CreatedDateUtc = command.CreatedDateUtc; LanguageId = command.LanguageId ?? string.Empty; UpdatedDateUtc = command.CreatedDateUtc; CreatedUid = command.CreatedUid ?? string.Empty; UpdatedUid = command.CreatedUid ?? string.Empty; Version = command.Version; }
public async void CustomerFindTest() { var name = Guid.NewGuid().ToString(); var add = new CustomerAddCommand(); var result = add.CustomerAdd(new CustomerAdd() { EntityId = _entityView.EntityId, Name = name }).Result; result.Name.Should().Be(name); result.CustomerId.Should().BeGreaterThan(0); result.EntityId.Should().Be(_entityView.EntityId); var find = new GetCustomerRequest(); var result2 = await find.GetCustomer(new GetCustomer() { CustomerId = result.CustomerId }); result2.Name.Should().Be(name); result2.CustomerId.Should().Be(result.CustomerId); result2.EntityId.Should().Be(_entityView.EntityId); }
public InvoiceTests() { var entityName = Guid.NewGuid().ToString(); var entityAddCommand = new EntityAddCommand(); IEntityView _entityView; _entityView = entityAddCommand.EntityAdd(new EntityAdd() { Name = entityName, SMTPEmailFromAddress = Config.Config.EmailSettings.SMTPEmailFromAddress, SMTPHost = Config.Config.EmailSettings.SMTPHost, SMTPEmailDisplayName = Config.Config.EmailSettings.SMTPEmailDisplayName, SMTPPassword = Config.Config.EmailSettings.SMTPPassword, SMTPUserName = Config.Config.EmailSettings.SMTPUserName, Address = new AddressView() { AddressLine1 = "4490 Patterson Street", City = "Houston", StateCounty = "State", PostZipCode = "77063" } }).Result; var name = Guid.NewGuid().ToString(); var customerAddCommand = new CustomerAddCommand(); customerView = customerAddCommand.CustomerAdd(new CustomerAdd() { EntityId = _entityView.EntityId, Name = name, EmalAddress = Config.Config.EmailSettings.TestEmailSendAddress }).Result; }
public void TestTestValidCustomer_SuccessfullyAddsCustomer() { var customerAddCommand = new CustomerAddCommand { Firstname = "Kez", Surname = "Nwichi", CompanyId = 1234, DateOfBirth = DateTime.Now.AddYears(-30), EmailAddress = "*****@*****.**", Id = 1 }; _customerService.AddCustomer(customerAddCommand); _dataAccessWrapperMock.Verify(p => p.AddCustomer(It.IsAny <Customer>())); }
public void TestBelow21Customer_RejectsCustomer() { var customerAddCommand = new CustomerAddCommand { Firstname = "Kez", Surname = "Nwichi", CompanyId = 1234, DateOfBirth = DateTime.Now.AddYears(-20), EmailAddress = "*****@*****.**", Id = 1 }; _customerService.AddCustomer(customerAddCommand); _dataAccessWrapperMock.Setup(p => p.AddCustomer(It.IsAny <Customer>())).Throws(new Exception("Should not be called")); }
public async Task Handler(CustomerAddCommand command) { try { await _rCustomer.AddCustomerAsync(new Customer().ParseAdd(command)); } catch (Exception ex) { throw ex; } }
public static async Task Main(string[] _) { var ctx = new CancellationToken(); var ctxs = CancellationTokenSource.CreateLinkedTokenSource(ctx); Console.CancelKeyPress += (x, y) => { y.Cancel = true; ctxs.Cancel(false); }; var builder = new ContainerBuilder(); builder.RegisterMediatR(typeof(CustomerLoadQuery).Assembly); builder.RegisterType <CustomersRepository>() .As <ICustomersRepository>() .SingleInstance(); var container = builder.Build(); var lifetimeScope = container.Resolve <ILifetimeScope>(); var googleCustomerAddCommand = new CustomerAddCommand(Guid.NewGuid(), "google"); await using (var scope = lifetimeScope.BeginLifetimeScope()) { var mediator = scope.Resolve <IMediator>(); await mediator.Send(googleCustomerAddCommand, ctx); } await using (var scope = lifetimeScope.BeginLifetimeScope()) { var mediator = scope.Resolve <IMediator>(); var customer = await mediator.Send(new CustomerLoadQuery(googleCustomerAddCommand.Id), ctx); Console.WriteLine(googleCustomerAddCommand.Name == customer.Name); try { await mediator.Send(new CustomerLoadQuery(Guid.Empty), ctx); } catch (CustomerNotFoundException) { Console.WriteLine("Expected that the customer could not be found bc we didn't add him b4."); } } Console.ReadKey(); }
public async Task <IActionResult> Post([FromBody] CustomerRequest customer) { var customerAddCommand = new CustomerAddCommand(customer.Id, customer.FirstName, customer.LastName, customer.BirthDay, customer.CustomerFrom, customer.Active, true); var added = await _mediator.Send(customerAddCommand); var accountAdded = await AccountSendIfExists(customer.Id, customer.BankAccount, true); return(Ok(added && accountAdded)); }
public void CustomerAddTest() { var name = Guid.NewGuid().ToString(); var add = new CustomerAddCommand(); var result = add.CustomerAdd(new CustomerAdd() { EntityId = _entityView.EntityId, Name = name }).Result; result.Name.Should().Be(name); result.CustomerId.Should().BeGreaterThan(0); result.EntityId.Should().Be(_entityView.EntityId); }
public async Task <IActionResult> CreateCustomer([FromBody] Application.Models.NewCustomer customer) { if (customer == null) { throw new ArgumentNullException(nameof(customer)); } var command = new CustomerAddCommand(customer); var result = await this._mediator.Send(command); if (result != null) { return(new OkObjectResult(result.Result)); } return(new BadRequestResult()); }
public AddressTests() { var entityName = Guid.NewGuid().ToString(); var entityAddCommand = new EntityAddCommand(); IEntityView _entityView; _entityView = entityAddCommand.EntityAdd(new EntityAdd() { Name = entityName }).Result; var name = Guid.NewGuid().ToString(); var customerAddCommand = new CustomerAddCommand(); customerView = customerAddCommand.CustomerAdd(new CustomerAdd() { EntityId = _entityView.EntityId, Name = name }).Result; }
public async Task <ICommandResult> Handle(CustomerAddCommand mesage) { try { Customer customer = new Customer(mesage.Version); customer.Add(mesage); await _customerService.AddToDb(customer); ICommandResult result = new CommandResult() { Message = "", ObjectId = customer.Id, Status = CommandResult.StatusEnum.Sucess }; return(result); } catch (MessageException e) { e.Data["Param"] = mesage; ICommandResult result = new CommandResult() { Message = e.Message, Status = CommandResult.StatusEnum.Fail, ResourceName = e.ResourceName }; return(result); } catch (Exception e) { e.Data["Param"] = mesage; ICommandResult result = new CommandResult() { Message = e.Message, Status = CommandResult.StatusEnum.Fail }; return(result); } }
public async Task Post(CustomerAddCommand command) { await _customerHanlder.Handler(command); }
public Customer ParseAdd(CustomerAddCommand command) { return(Parse(command)); }
public async Task <CommandResult> SendCommand(CustomerAddCommand command) { CommandResult commandResult = await _commandService.SendAndReceiveResult <CommandResult>(command); return(commandResult); }
private void RaiseCustomerAddEditDeleteCommandsCanExecute() { CustomerAddCommand.RaiseCanExecuteChanged(); CustomerEditCommand.RaiseCanExecuteChanged(); CustomerDeleteCommand.RaiseCanExecuteChanged(); }