Esempio n. 1
0
        public static void AddOrder(DTO.Order current_order, DTO.Customer current_customer)
        {
            PapaBobEntities db = new PapaBobEntities();

            System.Data.Entity.DbSet <Order> dbOrders = db.Orders;
            var dbCustomers = db.Customers;

            var new_order = new Persistence.Order();

            CreateNewOrder(current_order, out new_order);

            var  dbCustomersList         = db.Customers.ToList();
            bool check_if_customer_exits = CustomerRepository.CustomerExists(dbCustomersList, current_customer);

            if (!check_if_customer_exits)
            {
                var new_customer = new Customer();
                CustomerRepository.CreateNewCustomer(current_customer, out new_customer);
                new_order.customer_id     = new_customer.customer_id;
                new_customer.amount_owing = current_order.payment_type != DTO.Payment.Cash ? current_order.cost : 0;
                new_order.Customer        = new_customer;
                dbCustomers.Add(new_customer);
            }
            else
            {
                var existing_customer = dbCustomersList?.Find(p => p.phone_number == current_customer.phone_number);
                new_order.customer_id           = existing_customer.customer_id;
                existing_customer.amount_owing += current_order.payment_type != DTO.Payment.Cash ? current_order.cost : 0;
            }

            dbOrders.Add(new_order);
            db.SaveChanges();
        }
Esempio n. 2
0
        public static void UpdateOrder(string current_order_id)
        {
            PapaBobEntities db             = new PapaBobEntities();
            var             dbOrders       = db.Orders.ToList();
            var             existing_order = dbOrders?.Find(p => p.order_id == new Guid(current_order_id));

            existing_order.completed = true;
            db.SaveChanges();
        }
Esempio n. 3
0
        public static DTO.PizzaPriceTable GetPrices()
        {
            PapaBobEntities db       = new PapaBobEntities();
            var             dbPrices = db.PizzaPriceTables.ToList();

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

            return(PriceMapper(latestPrice));
        }
Esempio n. 4
0
        public static List <DTO.Customer> GetCustomerList()
        {
            PapaBobEntities     db                 = new PapaBobEntities();
            var                 dbCustomers        = db.Customers.ToList();
            List <DTO.Customer> dto_customers_list = new List <DTO.Customer>();

            foreach (var customer in dbCustomers)
            {
                DTO.Customer new_customer = new DTO.Customer();
                CustomerMapper(customer, out new_customer);
                dto_customers_list.Add(new_customer);
            }
            return(dto_customers_list);
        }
Esempio n. 5
0
        public static List <DTO.Order> GetOrdersList()
        {
            PapaBobEntities  db              = new PapaBobEntities();
            var              dbOrders        = db.Orders.ToList();
            List <DTO.Order> dto_orders_list = new List <DTO.Order>();

            foreach (var order in dbOrders)
            {
                if (!order.completed)
                {
                    DTO.Order new_order = new DTO.Order();
                    OrderMapper(order, out new_order);
                    dto_orders_list.Add(new_order);
                }
            }
            return(dto_orders_list);
        }