Esempio n. 1
0
        public Object SelectCatProductToppingByName(string name)
        {
            int count = new CoffeeDAO().SelectAllCategory().Count();
            List <CatProductTopping> listCatProduct = new List <CatProductTopping>();

            for (int i = 1; i <= count; i++)
            {
                Category cat = new CoffeeDAO().SelectCatByIdCat(i);
                List <ProductTopping> products   = new CoffeeDAO().SearchProToppingByNameIdCat(name, i);
                CatProductTopping     catProduct = new CatProductTopping(products, cat);
                if (products.Count() > 0)
                {
                    listCatProduct.Add(catProduct);
                }
            }
            return((Object)listCatProduct);
        }
Esempio n. 2
0
        public bool AddProductToBill(AddProductToBill addProductToBill)
        {
            IFirebaseConfig config = new FirebaseConfig
            {
                AuthSecret = "dHDi653cpD0hHaOOrAwgtlTahn7FC9ZBhYoDjeWV",
                BasePath   = "https://cafe-4b7dd.firebaseio.com/"
            };

            IFirebaseClient client = new FirebaseClient(config);

            if (client == null)
            {
                return(false);
            }
            else
            {
                int idBill = new CoffeeDAO().SelectIdBill(addProductToBill.IdTable);
                if (idBill == -1)
                {
                    bool result1 = new CoffeeDAO().AddBill(addProductToBill.IdTable, addProductToBill.IdAccount, addProductToBill.Note);
                    if (result1)
                    {
                        bool result2 = new CoffeeDAO().UpdateStatusTable(addProductToBill.IdTable, "Có người");
                        if (result2)
                        {
                            for (int i = 0; i < addProductToBill.Product.Count(); i++)
                            {
                                int  id      = new CoffeeDAO().SelectIdBillLast();
                                bool result3 = new CoffeeDAO().AddDetailBill(id, addProductToBill.Product[i].IdProduct, addProductToBill.Product[i].Quantity, addProductToBill.Product[i].PriceProduct, addProductToBill.Product[i].toppingAdds);
                                if (result3 == false)
                                {
                                    return(false);
                                }
                            }
                            _ = EditStatusTableFirebase(addProductToBill.IdTable, addProductToBill.NameTable, "Có người", client);
                            _ = EditNoteTableFirebase(client, addProductToBill.IdTable, addProductToBill.Note);
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                //Bill đã tồn tại
                else
                {
                    //Xóa hết
                    List <int> idDetailBills = new CoffeeDAO().SelectIdDetailBill(idBill);
                    if (idDetailBills.Count > 0)
                    {
                        for (int i = 0; i < idDetailBills.Count(); i++)
                        {
                            List <int> idDetailTopping = new CoffeeDAO().SelectIdDetailTopping(idDetailBills[i]);
                            if (idDetailTopping.Count > 0)
                            {
                                for (int j = 0; j < idDetailTopping.Count; j++)
                                {
                                    bool result0 = new CoffeeDAO().DeleteDetailTopping(idDetailTopping[j]);
                                    if (result0 == false)
                                    {
                                        return(false);
                                    }
                                }
                            }
                            bool result = new CoffeeDAO().DeleteDetailBill(idDetailBills[i]);
                            if (result == false)
                            {
                                return(false);
                            }
                        }
                    }
                    _ = EditStatusTableFirebase(addProductToBill.IdTable, addProductToBill.NameTable, "Trống", client);
                    bool result11 = new CoffeeDAO().XoaBill(idBill);
                    if (result11)
                    //Add lại
                    {
                        bool result1 = new CoffeeDAO().AddBill(addProductToBill.IdTable, addProductToBill.IdAccount, addProductToBill.Note);
                        if (result1)
                        {
                            bool result2 = new CoffeeDAO().UpdateStatusTable(addProductToBill.IdTable, "Có người");
                            if (result2)
                            {
                                for (int i = 0; i < addProductToBill.Product.Count(); i++)
                                {
                                    int  id      = new CoffeeDAO().SelectIdBillLast();
                                    bool result3 = new CoffeeDAO().AddDetailBill(id, addProductToBill.Product[i].IdProduct, addProductToBill.Product[i].Quantity, addProductToBill.Product[i].PriceProduct, addProductToBill.Product[i].toppingAdds);
                                    if (result3 == false)
                                    {
                                        return(false);
                                    }
                                }
                                _ = EditStatusTableFirebase(addProductToBill.IdTable, addProductToBill.NameTable, "Có người", client);
                                _ = EditNoteTableFirebase(client, addProductToBill.IdTable, addProductToBill.Note);
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
        }