public void _01_can_save_new_customer() { IInquiryCustomer customer = _customerBusinessLogic.GetCustomer(new InquiryCriteria { CustomerId = 1, Email = "*****@*****.**" }).Result; if (customer == null) { customer = new InquiryCustomer { Id = 1, Name = "Firstname Lastname", Email = "*****@*****.**", MobileNumber = "0123456789" }; customer.Transactions.Add(CreateTransaction(1, 1234.56, "USD", TransactionStatus.Success)); customer.Transactions.Add(CreateTransaction(1, 6543.21, "GBP", TransactionStatus.Canceled)); customer.Transactions.Add(CreateTransaction(1, 1111.22, "USD", TransactionStatus.Failed)); customer.Transactions.Add(CreateTransaction(1, 2222.23, "EUR", TransactionStatus.Success)); customer.Transactions.Add(CreateTransaction(1, 3333.34, "THB", TransactionStatus.Canceled)); customer.Transactions.Add(CreateTransaction(1, 7890.12, "USD", TransactionStatus.Failed)); _customerBusinessLogic.Save(customer).Wait(); } Assert.IsNotNull(customer); Assert.IsNotNull(customer.Transactions); }
// POST api/customers public async Task <HttpResponseMessage> Post(InquiryCriteriaViewmodel inquiryCriteria) { if (inquiryCriteria.customerID <= 0 && string.IsNullOrEmpty(inquiryCriteria.email)) { return(CreateResponse(HttpStatusCode.BadRequest, "No inquiry criteria")); } else { if (!Validator.IsValidEmail(inquiryCriteria.email)) { return(CreateResponse(HttpStatusCode.BadRequest, "Invalid Email")); } if (!Validator.IsValidCustomerId(inquiryCriteria.customerID)) { return(CreateResponse(HttpStatusCode.BadRequest, "Invalid Customer ID")); } IInquiryCriteria criteria = inquiryCriteria.Convert(); IInquiryCustomer customer = await _customerBusinessLogic.GetCustomer(criteria); if (customer == null) { return(CreateResponse(HttpStatusCode.NotFound, "Not found")); } return(CreateResponse(new CustomerViewmodel(customer, criteria))); } }
public void _02_can_get_customer() { IInquiryCustomer customer = _customerBusinessLogic.GetCustomer(new InquiryCriteria { CustomerId = 1, Email = "*****@*****.**" }).Result; Assert.IsNotNull(customer.Transactions); }
public async Task<IInquiryCustomer> Save(IInquiryCustomer item) { using (var context = new CustomerInquiryContext()) { context.Customers.AddOrUpdate(item as InquiryCustomer); context.SaveChanges(); } return await Get(item.Id); }
public CustomerViewmodel(IInquiryCustomer customer, IInquiryCriteria criteria) { customerID = customer.Id; name = customer.Name; email = customer.Email; mobile = customer.MobileNumber; transactions = customer.Transactions.Select(x => new TransactionViewmodel(x)).OrderByDescending(x => x.date).Take(5).ToList(); transactions = criteria.HasAllCriteria ? transactions : criteria.HasOnlyEmail ? transactions.Take(1).ToList() : new List <TransactionViewmodel>(); }
public async Task<IInquiryCustomer> Update(IInquiryCustomer item) { return await Save(item); }
public Task <IInquiryCustomer> Update(IInquiryCustomer item) { return(_customerRepository.Update(item)); }
public Task <IInquiryCustomer> Save(IInquiryCustomer item) { return(_customerRepository.Save(item)); }
public async Task <IInquiryCustomer> GetCustomer(IInquiryCriteria criteria) { IInquiryCustomer customer = await _customerRepository.GetCustomer(criteria); return(customer); }