public Request(ProductSearchValidationResult result, Customer addedCustomer, int?productId, DateTime dateTimeServed) { this.ValidationResult = (int)result; this.CustomerId = addedCustomer.Id; this.ProductId = productId; this.RequestServed = dateTimeServed; this.UniqueId = Guid.NewGuid(); }
private async Task <IEnumerable <Product> > GetProductsForCustomer(ProductSearchValidationResult result, Customer addedCustomer) { IEnumerable <Product> productResults = new List <Product>(); if (result == ProductSearchValidationResult.Valid) { // do a product search IReadOnlyList <Product> products = await _productRepo.ListAllAsync(); productResults = _productResultsValidator.ValidateProductsForCustomer(addedCustomer, products); } return(productResults); }
private string GetErrorMessage(ProductSearchValidationResult validationResult) { switch (validationResult) { case ProductSearchValidationResult.UnderEighteen: { return(ProductSearchStringResources.UnderAgeValidationError); } default: { return(ProductSearchStringResources.DefaultValidationError); } } }
public async Task <ProductSearchResponse> GetProductsForCustomer(Customer customerToAdd) { customerToAdd = _customerDetailsFormatter.Format(customerToAdd); Customer addedCustomer = await _customerRepo.AddAsync(customerToAdd); ProductSearchValidationResult result = _customerValidator.Validate(addedCustomer); IEnumerable <Product> productResults = await GetProductsForCustomer(result, addedCustomer); Request request = await RecordSearch(result, addedCustomer, productResults); ProductSearchResponse response = new ProductSearchResponse(result, request.UniqueId); return(response); }
private async Task <Request> RecordSearch(ProductSearchValidationResult result, Customer addedCustomer, IEnumerable <Product> productResults) { // if multiple products were being returned and I wanted to record each // I would need another table for returned products that would be stored // against the requestId var product = productResults.FirstOrDefault(); int?productId = null; if (product != null) { productId = product.Id;; } var request = new Request(result, addedCustomer, productId, DateTime.Now); request = await _requestRepo.AddAsync(request); return(request); }
public ProductSearchResponse(ProductSearchValidationResult result, Guid resultsId) { this.ValidationResult = result; this.ResultsId = resultsId; }