Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        public void UpdateOrder(string currentOrderId)
        {
            var db            = new PapaBobEntities();
            var dbOrders      = db.Orders.ToList();
            var existingOrder = dbOrders?.Find(p => p.order_id == new Guid(currentOrderId));

            existingOrder.completed = true;
            db.SaveChanges();
        }