public void processPaymentWith1Item() { var orderCore = new OrderCore(); orderCore.processOrder(new OrderItem[] { new OrderItem("Chicken Wings 6pcs.", 1, 120) }); Assert.AreEqual(true, orderCore.processPayment(new CashPayment(120))); }
public async Task <IHttpActionResult> Create([FromBody] Order order) { try { var result = await OrderCore.CreateAsync(order).ConfigureAwait(false); return(Ok(result)); } catch (Exception e) { LogHelper.LogException <OrderController>(e); return(Ok(ResponseFactory <Order> .CreateResponse(false, ResponseCode.Error))); } }
public void WhenAnOrderArrives(Table table) { OrderCore core = new OrderCore(sessionManager); List <Order> order = new List <Order>(); foreach (var row in table.Rows) { order.Add( new Order { User = row["User"], Product = row["Products"], Quantity = Convert.ToDecimal(row["Quantity"]), }); } result = core.AcceptOrder(order); }
public async Task <IHttpActionResult> Get() { try { var productsResponse = await ProductCore.GetAllAsync().ConfigureAwait(false); var ordersResponse = await OrderCore.GetAllAsync().ConfigureAwait(false); var orderItemsResponse = await OrderItemCore.GetAllAsync().ConfigureAwait(false); var clientsResponse = await ClientCore.GetAllAsync().ConfigureAwait(false); var paymentsResponse = await PayrollCore.GetAllAsync().ConfigureAwait(false); if (!productsResponse.Success || !orderItemsResponse.Success || !orderItemsResponse.Success || !clientsResponse.Success || !paymentsResponse.Success) { return(Ok(ResponseFactory.CreateResponse(false, ResponseCode.Error))); } var totalIncomeValue = paymentsResponse.Data.Sum(payment => payment.Value); var totalOrdersValue = orderItemsResponse.Data.Sum(orderItem => orderItem.Price * orderItem.Quantity); var model = new SummaryModel { NumberOfClients = clientsResponse.Data.Count, NumberOfOrders = ordersResponse.Data.Count, NumberOfPayments = paymentsResponse.Data.Count, NumberOfProducts = productsResponse.Data.Count, TotalIncomeValue = totalIncomeValue, TotalOrdersValue = totalOrdersValue }; return(Ok(ResponseFactory <SummaryModel> .CreateResponse(true, ResponseCode.Success, model))); } catch (Exception e) { LogHelper.LogException <SummaryController>(e); return(Ok(ResponseFactory <SummaryModel> .CreateResponse(false, ResponseCode.Error))); } }
public async Task <IHttpActionResult> GetAllForUser(Guid userId, string orderBy = "", bool orderAscending = true) { try { var result = await OrderCore.GetAllForUserAsync(userId, orderBy, orderAscending, new[] { nameof(Order.Client), nameof(Order.OrderItems), nameof(Order.Payrolls), nameof(Order.Currency) }).ConfigureAwait(false); return(Ok(result)); } catch (Exception e) { LogHelper.LogException <OrderController>(e); return(Ok(ResponseFactory <IList <Order> > .CreateResponse(false, ResponseCode.Error))); } }
public async Task <IHttpActionResult> GetAll(string orderBy = "", bool orderAscending = true) { try { var response = await OrderCore.GetAllAsync(orderBy, orderAscending, new[] { nameof(Order.Client), nameof(Order.OrderItems), $"{nameof(Order.OrderItems)}.{nameof(OrderItem.Product)}", $"{nameof(Order.OrderItems)}.{nameof(OrderItem.Product)}.{nameof(Product.ValueAddedTax)}", nameof(Order.Payrolls), nameof(Order.Currency) }).ConfigureAwait(false); return(Ok(response)); } catch (Exception e) { LogHelper.LogException <OrderController>(e); return(Ok(ResponseFactory <IList <Order> > .CreateResponse(false, ResponseCode.Error))); } }
public void InitializeMockData() { try { Task.Run(async() => { var existingProducts = await ProductCore.GetAllAsync().ConfigureAwait(false); if (existingProducts.Data != null && existingProducts.Data.Count != 0) { return; } var products = await ProductCore.CreateAsync(mProducts, true).ConfigureAwait(false); var existingClients = await ClientCore.GetAllAsync().ConfigureAwait(false); if (existingClients.Data != null && existingClients.Data.Count != 0) { return; } var currencies = await CurrencyCore.GetAllAsync().ConfigureAwait(false); if (!currencies.Success || currencies.Data == null || currencies.Data.Count == 0) { return; } var currency = currencies.Data.FirstOrDefault(c => c.Name == "RON"); if (currency == null) { return; } foreach (var client in mClients) { client.CurrencyId = currency.Id; } var clients = await ClientCore.CreateAsync(mClients, true).ConfigureAwait(false); var existingOrders = await OrderCore.GetAllAsync().ConfigureAwait(false); if (existingOrders.Data != null && existingOrders.Data.Count != 0) { return; } int nr = 0; List <Order> newOrders = new List <Order>(); foreach (var client in clients.Data) { if (products.Data.Count >= 6) { for (int i = 0; i < 2; i++) { nr++; var o = new Order() { Id = Guid.NewGuid(), CurrencyId = currency.Id, ClientId = client.Id, SaleType = i, Status = 0, Date = DateTime.Now.AddDays(-nr).AddHours(-nr), OrderItems = new List <OrderItem>() }; for (int k = i + nr / 2; k < 6; k += 1) { o.OrderItems.Add(new OrderItem() { Id = Guid.NewGuid(), OrderId = o.Id, ProductId = products.Data.ElementAt(k).Id, Price = products.Data.ElementAt(k).Price, Quantity = k + 1 }); } newOrders.Add(o); } } } var orders = await OrderCore.CreateAsync(newOrders, true, new[] { nameof(Order.OrderItems) }).ConfigureAwait(false); var payrolls = new List <Payroll>(); if (orders.Data.Count > 3) { for (int i = 0; i < 3; i++) { var payroll = new Payroll() { Id = Guid.NewGuid(), ClientId = clients.Data.ElementAt(i).Id, OrderId = orders.Data.ElementAt(i).Id, Date = DateTime.Now.AddDays(-i), Value = orders.Data.ElementAt(i).OrderItems.Sum(p => p.Price * p.Quantity), }; payrolls.Add(payroll); } } await PayrollCore.CreateAsync(payrolls, true).ConfigureAwait(false); }).ConfigureAwait(false).GetAwaiter().GetResult(); } catch (Exception ex) { // ignored } }
public void processPaymentWith0Item() { var orderCore = new OrderCore(); Assert.Throws <Exception>(() => orderCore.processPayment(new CashPayment(120))); }
public void orderTotal2ItemWithQuantity() { var orderCore = new OrderCore(); Assert.AreEqual(310, orderCore.processOrder(new OrderItem[] { new OrderItem("Chicken Wings 6pcs.", 2, 120), new OrderItem("Fries and Wings 3pcs.", 1, 70) })); }
public void orderTotal1Item() { var orderCore = new OrderCore(); Assert.AreEqual(120, orderCore.processOrder(new OrderItem[] { new OrderItem("Chicken Wings 6pcs.", 1, 120) })); }