public void AddOrder(DTO.OrderDto currentOrder, DTO.CustomerDto currentCustomer) { var db = new PapaBobEntities(); var dbOrders = db.Orders; var dbCustomers = db.Customers; var newOrder = new Persistence.Order(); CreateNewOrder(currentOrder, out newOrder); var dbCustomersList = db.Customers.ToList(); var check_if_customer_exits = CustomerRepository.CustomerExists(dbCustomersList, currentCustomer); if (!check_if_customer_exits) { var newCustomer = new Customer(); newCustomer = CustomerRepository.CreateNewCustomer(currentCustomer); newOrder.customer_id = newCustomer.customer_id; var tempAmountOwing = currentOrder.payment_type != DTO.Enums.PaymentType.Cash ? currentOrder.cost : 0; newCustomer.amount_owing = double.Parse(tempAmountOwing.ToString()); newOrder.Customer = newCustomer; dbCustomers.Add(newCustomer); } else { var existingCustomer = dbCustomersList?.Find(p => p.phone_number == currentCustomer.phone_number); newOrder.customer_id = existingCustomer.customer_id; var tempAmountOwing = currentOrder.payment_type != DTO.Enums.PaymentType.Cash ? currentOrder.cost : 0; existingCustomer.amount_owing += double.Parse(tempAmountOwing.ToString()); } dbOrders.Add(newOrder); db.SaveChanges(); }
private static void CreateNewOrder(DTO.OrderDto current_order, out Persistence.Order newOrder) { newOrder = new Persistence.Order(); OrderMapper(current_order, out newOrder); var order_id = Guid.NewGuid(); newOrder.order_id = order_id; }
private static void OrderMapper(DTO.OrderDto currentOrder, out Persistence.Order newOrder) { newOrder = new Persistence.Order { completed = false, cost = currentOrder.cost, crust = (Persistence.Crust)currentOrder.crust, payment_type = (Persistence.PaymentType)currentOrder.payment_type, size = (Persistence.Size)currentOrder.size, onions = currentOrder.onions, green_peppers = currentOrder.green_peppers, sausage = currentOrder.sausage, pepperoni = currentOrder.pepperoni }; }
public List <DTO.OrderDto> GetOrdersList() { var db = new PapaBobEntities(); var dbOrders = db.Orders.ToList(); var dto_orders_list = new List <DTO.OrderDto>(); foreach (var order in dbOrders) { if (!order.completed) { var newOrder = new DTO.OrderDto(); OrderMapper(order, out newOrder); dto_orders_list.Add(newOrder); } } return(dto_orders_list); }
private static void OrderMapper(Persistence.Order currentOrder, out DTO.OrderDto newOrder) { newOrder = new DTO.OrderDto { completed = false, cost = currentOrder.cost, size = (DTO.Enums.Size)currentOrder.size, crust = (DTO.Enums.Crust)currentOrder.crust, payment_type = (DTO.Enums.PaymentType)currentOrder.payment_type, onions = currentOrder.onions, green_peppers = currentOrder.green_peppers, sausage = currentOrder.sausage, pepperoni = currentOrder.pepperoni, customer_id = currentOrder.customer_id, order_id = currentOrder.order_id }; var customer = new DTO.CustomerDto(); CustomerRepository.CustomerMapper(currentOrder.Customer, out customer); newOrder.Customer = customer; }
//calculate total cost given DTO order object return a double public double CalculateAmountOwing(DTO.OrderDto current_order) { var latestPricing = _pizzaPriceTableRepository.GetPizzaPrices(); decimal cost = 0; switch (current_order.size) { case DTO.Enums.Size.Small: cost += latestPricing.SmallSizeCost; break; case DTO.Enums.Size.Medium: cost += latestPricing.MediumSizeCost; break; case DTO.Enums.Size.Large: cost += latestPricing.LargeSizeCost; break; } switch (current_order.crust) { case DTO.Enums.Crust.Thin: cost += latestPricing.ThinCrustCost; break; case DTO.Enums.Crust.Thick: cost += latestPricing.ThickCrustCost; break; } cost += current_order.green_peppers ? latestPricing.GreenPeppersCost : 0; cost += current_order.onions ? latestPricing.OnionsCost : 0; cost += current_order.pepperoni ? latestPricing.PepperoniCost : 0; cost += current_order.sausage ? latestPricing.SausageCost : 0; return(double.Parse(cost.ToString())); }
//receive order and customer object from presentation and pass onto persistence public void AddOrder(DTO.OrderDto current_order) { _orderRepository.AddOrder(current_order, current_order.Customer); }