private CustomerIdNameReadModel GetIdNameResult(CustomerRecord customerRecord) { var id = new CustomerIdentity(customerRecord.Id); var name = $"{customerRecord.FirstName} {customerRecord.LastName}"; return(new CustomerIdNameReadModel(id, name)); }
public CustomerHeaderReadModel(CustomerIdentity customerId, string firstName, string lastName, int openOrders) { CustomerId = customerId; FirstName = firstName; LastName = lastName; OpenOrders = openOrders; }
public Order CreateNewOrder(CustomerIdentity customerId, IEnumerable <OrderItem> orderDetails) { var id = _orderIdentityGenerator.Next(); var orderDate = _timeService.Now; return(new Order(id, customerId, orderDate, OrderStatus.New, orderDetails)); }
private static void PopulateIdentityInformation(Entity contact, CustomerIdentity identity, ITracingService trace) { trace.Trace("Contact populate identity - start"); if (identity == null) { return; } contact[Attributes.Contact.FirstName] = (!string.IsNullOrWhiteSpace(identity.FirstName)) ? identity.FirstName : string.Empty; contact[Attributes.Contact.MiddleName] = (!string.IsNullOrWhiteSpace(identity.MiddleName)) ? identity.MiddleName : string.Empty; contact[Attributes.Contact.LastName] = (!string.IsNullOrWhiteSpace(identity.LastName)) ? identity.LastName : string.Empty; contact[Attributes.Contact.AcademicTitle] = (!string.IsNullOrWhiteSpace(identity.AcademicTitle)) ? identity.AcademicTitle : string.Empty; contact[Attributes.Contact.Language] = CommonXrm.GetLanguage(identity.Language); contact[Attributes.Contact.Gender] = CommonXrm.GetGender(identity.Gender); if (!string.IsNullOrWhiteSpace(identity.Salutation)) { contact[Attributes.Contact.Salutation] = CommonXrm.GetSalutation(identity.Salutation); } DateTime?dateOfBirth = null; if (!string.IsNullOrWhiteSpace(identity.Birthdate)) { dateOfBirth = Convert.ToDateTime(identity.Birthdate); } contact[Attributes.Contact.Birthdate] = dateOfBirth; trace.Trace("Contact populate identity - end"); }
public async Task HandleAsync_Valid() { var customerRepositoryMock = new Mock <ICustomerRepository>(); var id = Guid.Parse("926a4480-61f5-416a-a16f-5c722d8463f7"); var command = new DeleteCustomerCommand { Id = id, }; var customerId = new CustomerIdentity(id); var expectedResponse = new DeleteCustomerCommandResponse(); customerRepositoryMock .Setup(e => e.ExistsAsync(customerId)) .ReturnsAsync(true); customerRepositoryMock .Setup(e => e.RemoveAsync(customerId)); var handler = new DeleteCustomerCommandHandler(customerRepositoryMock.Object); var response = await handler.HandleAsync(command); customerRepositoryMock.Verify(e => e.RemoveAsync(customerId), Times.Once()); response.Should().BeEquivalentTo(expectedResponse); }
private CustomerDetailReadModel GetCustomerDetailReadModel(CustomerRecord customerRecord) { var id = new CustomerIdentity(customerRecord.Id); var firstName = customerRecord.FirstName; var lastName = customerRecord.LastName; var openOrders = customerRecord.Orders .Where(e => e.OrderStatusId != OrderStatus.Closed) .Count(); var lastOrderDate = customerRecord.Orders .Max(e => (DateTime?)e.OrderDate); var totalOrders = customerRecord.Orders .Count; var totalOrderValue = customerRecord.Orders .SelectMany(e => e.OrderItems) .Select(e => e.UnitPrice * e.Quantity) .Sum(e => (decimal?)e) .GetValueOrDefault(); var topProducts = customerRecord.Orders .SelectMany(e => e.OrderItems) .GroupBy(e => e.Product) .OrderByDescending(e => e.Count()) .Select(e => e.Key.ProductName) .ToList(); return(new CustomerDetailReadModel(id, firstName, lastName, openOrders, lastOrderDate, totalOrders, totalOrderValue, topProducts)); }
public Task <bool> ExistsAsync(CustomerIdentity customerId) { var customerRecordId = customerId.Value; return(Context.Customers.AsNoTracking() .AnyAsync(e => e.Id == customerRecordId)); }
private async Task <Order> GetOrderAsync(CreateOrderRequest request) { var customerId = new CustomerIdentity(request.CustomerId); var customer = await _customerReadRepository.FindAsync(customerId); if (customer == null) { throw new InvalidRequestException($"Customer {request.CustomerId} does not exist"); } var orderDetails = new List <OrderItem>(); for (int i = 0; i < request.OrderItems.Count; i++) { var requestOrderDetail = request.OrderItems[i]; try { var orderDetail = await GetOrderItem(requestOrderDetail); orderDetails.Add(orderDetail); } catch (InvalidRequestException ex) { var position = i + 1; throw new InvalidRequestException($"Order detail at position {position} is invalid", ex); } } return(_orderFactory.CreateNewOrder(customerId, orderDetails)); }
public CustomerIdentity GetSoapPurifiedCustomer() { var customer = new CustomerIdentity { CoAddress = CustomerId.CoAddress, CompanyIdentity = (CustomerId.CountryCode != null && ( CustomerId.CountryCode != "DE" && CustomerId.CountryCode != "NL")) ? null : CustomerId.CompanyIdentity, CountryCode = CustomerId.CountryCode, CustomerType = CustomerId.CustomerType, Email = CustomerId.Email, FullName = CustomerId.FullName, HouseNumber = CustomerId.HouseNumber, IndividualIdentity = (CustomerId.CountryCode != null && ( CustomerId.CountryCode != "DE" && CustomerId.CountryCode != "NL")) ? null : CustomerId.IndividualIdentity, IpAddress = CustomerId.IpAddress, Locality = CustomerId.Locality, NationalIdNumber = CustomerId.NationalIdNumber, PhoneNumber = CustomerId.PhoneNumber, Street = CustomerId.Street, ZipCode = CustomerId.ZipCode }; return(customer); }
public Order(OrderIdentity id, CustomerIdentity customerId, OrderStatus status, ReadOnlyCollection <OrderDetail> orderDetails) : base(id) { CustomerId = customerId; Status = status; OrderDetails = orderDetails; }
private static void PopulateIdentityInformation(CustomerIdentity identity, ITracingService trace, FieldService fieldService) { trace.Trace("Contact populate identity - start"); if (fieldService == null) { return; } if (identity == null) { return; } fieldService.PopulateField(Attributes.Contact.FirstName, identity.FirstName); fieldService.PopulateField(Attributes.Contact.LastName, identity.LastName); fieldService.PopulateField(Attributes.Contact.MiddleName, identity.MiddleName); fieldService.PopulateField(Attributes.Contact.AcademicTitle, identity.AcademicTitle); fieldService.PopulateField(Attributes.Contact.Language, CommonXrm.GetLanguage(identity.Language)); var salutation = CommonXrm.GetSalutation(identity.Salutation); if (salutation != null) { fieldService.PopulateField(Attributes.Contact.Salutation, CommonXrm.GetSalutation(identity.Salutation)); } fieldService.PopulateField(Attributes.Contact.Gender, CommonXrm.GetGender(identity.Gender)); DateTime?dateOfBirth = null; if (!string.IsNullOrWhiteSpace(identity.Birthdate)) { dateOfBirth = Convert.ToDateTime(identity.Birthdate); } fieldService.PopulateField(Attributes.Contact.Birthdate, dateOfBirth); trace.Trace("Contact populate identity - end"); }
public void CanConstructValidOrder() { // Arrange var id = new OrderIdentity(Guid.NewGuid()); var customerId = new CustomerIdentity(Guid.NewGuid()); var orderDate = new DateTime(2020, 4, 3); var status = OrderStatus.Draft; var orderItems = new List <IReadonlyOrderItem> { new OrderItem(new OrderItemIdentity(Guid.NewGuid()), new ProductIdentity(Guid.NewGuid()), 40.56m, 20, OrderItemStatus.Pending), new OrderItem(new OrderItemIdentity(Guid.NewGuid()), new ProductIdentity(Guid.NewGuid()), 57.12m, 30, OrderItemStatus.Allocated), }; // Act var order = new Order(id, customerId, orderDate, status, orderItems); // Assert order.Id.Should().Be(id); order.CustomerId.Should().Be(customerId); order.OrderDate.Should().Be(orderDate); order.Status.Should().Be(status); order.OrderItems.Should().BeEquivalentTo(orderItems); }
public async Task RemoveAsync(CustomerIdentity customerId) { var customerRecord = await Context.Customers .FirstOrDefaultAsync(e => e.Id == customerId); Context.Remove(customerRecord); await Context.SaveChangesAsync(); }
private Customer GetCustomer(CustomerRecord customerRecord) { var identity = new CustomerIdentity(customerRecord.Id); var firstName = customerRecord.FirstName; var lastName = customerRecord.LastName; return(new Customer(identity, firstName, lastName)); }
public Order(OrderIdentity id, CustomerIdentity customerId, DateTime orderDate, OrderStatus status, IEnumerable <IReadonlyOrderItem> orderItems) : base(id) { CustomerId = customerId; OrderDate = orderDate; Status = status; OrderItems = orderItems.ToList().AsReadOnly(); }
public OrderHeaderReadModel(OrderIdentity orderId, CustomerIdentity customerId, DateTime orderDate, OrderStatus status, decimal totalPrice) { OrderId = orderId; CustomerId = customerId; OrderDate = orderDate; Status = status; TotalPrice = totalPrice; }
public CreateOrderBuilder AddCustomerDetails(CustomerIdentity customerIdentity) { CustomerId = customerIdentity; if (_hasSetCountryCode) { CustomerId.CountryCode = _countryCode.ToString().ToUpper(); } return(this); }
private CustomerRecord GetCustomerRecord(CustomerIdentity customerId) { var id = customerId.Value; return(new CustomerRecord { Id = id, }); }
private Customer GetCustomer(CustomerRecord customerRecord) { var id = new CustomerIdentity(customerRecord.Id); var referenceNumber = CustomerReferenceNumber.Parse(customerRecord.ReferenceNumber); var firstName = customerRecord.FirstName; var lastName = customerRecord.LastName; return(new Customer(id, referenceNumber, firstName, lastName)); }
private Order GetOrder(OrderRecord record) { var id = new OrderIdentity(record.Id); var customerId = new CustomerIdentity(record.CustomerId); var status = record.OrderStatusId; var orderDetails = record.OrderItems.Select(GetOrderItem).ToList().AsReadOnly(); return(new Order(id, customerId, DateTime.Now, status, orderDetails)); }
private void AddNewItem() { CustomerIdentity newIdentity = new CustomerIdentity(); EditCustomerIdentityForm form = new EditCustomerIdentityForm(newIdentity); if (form.ShowDialog() == DialogResult.OK) { AddSenderIdentity(newIdentity); } }
private OrderHeaderReadModel GetOrderHeaderReadModel(OrderRecord record) { var orderId = new OrderIdentity(record.Id); var customerId = new CustomerIdentity(record.CustomerId); var orderDate = record.OrderDate; var status = (OrderStatus)record.OrderStatusId; var totalPrice = record.OrderItems.Sum(e => e.UnitPrice * e.Quantity); return(new OrderHeaderReadModel(orderId, customerId, orderDate, status, totalPrice)); }
private Order GetOrder(OrderRecord record) { var id = new OrderIdentity(record.Id); var customerId = new CustomerIdentity(record.CustomerId); OrderStatus status = (OrderStatus)record.OrderStatusId; // TODO: VC var orderDetails = record.OrderItems.Select(GetOrderItem).ToList().AsReadOnly(); // TODO: VC: OrderDetails is empty list, need to Include it in EF so that it loads... return(new Order(id, customerId, DateTime.Now, status, orderDetails)); }
private void AddSenderIdentity(CustomerIdentity identity) { string[] subItems = new string[2]; subItems[0] = CustomerIdentity.IdentityTypeToElbaString(identity.IdentityType); subItems[1] = identity.Value; ObjectListViewItem item = new ObjectListViewItem(identity, subItems); SenderIdentityListView.Items.Add(item); _identities.Add(identity); }
public async Task <Customer> FindAsync(CustomerIdentity customerId) { var customerRecord = await Context.Customers.AsNoTracking() .FirstOrDefaultAsync(e => e.Id == customerId); if (customerRecord == null) { return(null); } return(GetCustomer(customerRecord)); }
private CustomerHeaderReadModel GetCustomerHeaderReadModel(CustomerRecord customerRecord) { var id = new CustomerIdentity(customerRecord.Id); var firstName = customerRecord.FirstName; var lastName = customerRecord.LastName; var openOrders = customerRecord.Orders .Where(e => e.OrderStatusId != OrderStatus.Closed) .Count(); return(new CustomerHeaderReadModel(id, firstName, lastName, openOrders)); }
public async Task <FindCustomerResponse> HandleAsync(FindCustomerRequest request) { var customerId = new CustomerIdentity(request.Id); var customerDetail = await _customerReadRepository.GetDetailAsync(customerId); if (customerDetail == null) { throw new NotFoundRequestException(); } return(_mapper.Map <CustomerDetailReadModel, FindCustomerResponse>(customerDetail)); }
private async Task <CustomerIdentity> GetCustomerIdAsync(CreateOrderCommand request) { var customerId = new CustomerIdentity(request.CustomerId); var existsCustomer = await _customerReadonlyRepository.ExistsAsync(customerId); if (!existsCustomer) { throw new ValidationException($"Customer {customerId} does not exist"); } return(customerId); }
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 IActionResult Index([Bind] CustomerIdentity cusIden) { int res = dbObj.checkLogin(cusIden); if (res == 1) { TempData["msg"] = "Welcome to my page"; return(RedirectToAction("Index", "Products")); } else { TempData["msg"] = "UserID or Password is wrong.!"; return(RedirectToAction("Index")); } }
public string GetSilentLoginRedirect(CustomerIdentity identity) { if (identity.CustomerTypeID == CustomerTypes.BrandPartner) { var token = Security.Encrypt(new { CustomerID = identity.CustomerID, ExpirationDate = DateTime.Now.AddHours(1) }); return GlobalSettings.Backoffices.SilentLogins.DistributorBackofficeUrl.FormatWith(token); } return string.Empty; }