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 double CustomerBalanceOwing(string phoneNumber)
        {
            var db = new PapaBobEntities();
            var dbCustomersList    = db.Customers.ToList();
            var customerInQuestion = dbCustomersList?.Find(p => p.phone_number == phoneNumber);

            return(customerInQuestion.amount_owing);
        }
Ejemplo n.º 3
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();
        }
        public DTO.PizzaPriceTableDto GetPizzaPrices()
        {
            var db       = new PapaBobEntities();
            var dbPrices = db.PizzaPriceTables.ToList();

            dbPrices = dbPrices.OrderBy(p => p.Date).ToList();
            var latestPrice = dbPrices[dbPrices.Count - 1];

            return(PriceMapper(latestPrice));
        }
Ejemplo n.º 5
0
        public List <DTO.CustomerDto> GetCustomerList()
        {
            var db                 = new PapaBobEntities();
            var dbCustomers        = db.Customers.ToList();
            var dto_customers_list = new List <DTO.CustomerDto>();

            foreach (var customer in dbCustomers)
            {
                var new_customer = new DTO.CustomerDto();
                CustomerMapper(customer, out new_customer);
                dto_customers_list.Add(new_customer);
            }
            return(dto_customers_list);
        }
Ejemplo n.º 6
0
        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);
        }