Exemplo n.º 1
0
    public string InsertCart(Cart cart)
    {
        try
        {
            YWC_StorageEntities db = new YWC_StorageEntities();
            db.Carts.Add(cart);
            db.SaveChanges();

            return(cart.DatePurchased + " was successfully inserted");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
Exemplo n.º 2
0
 public Product GetProduct(int id)
 {
     try
     {
         using (YWC_StorageEntities db = new YWC_StorageEntities())
         {
             Product product = db.Products.Find(id);
             return(product);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
Exemplo n.º 3
0
    public string InsertProduct(Product product)
    {
        try
        {
            YWC_StorageEntities db = new YWC_StorageEntities();
            db.Products.Add(product);
            db.SaveChanges();

            return(product.Name + " was successfully inserted");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
Exemplo n.º 4
0
    public Product FindProduct(int id)
    {
        YWC_StorageEntities db      = new YWC_StorageEntities();
        ProductModel        model   = new ProductModel();
        Product             product = new Product();

        foreach (Cart cart in db.Carts)
        {
            if (cart.ProductID == id)
            {
                return(cart.Product);
            }
        }

        return(product);
    }
 public List <ProductType> GetAllProductTypes()
 {
     try
     {
         using (YWC_StorageEntities db = new YWC_StorageEntities())
         {
             List <ProductType> products = (from x in db.ProductTypes
                                            select x).ToList();
             return(products);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
Exemplo n.º 6
0
    public void MarkOrdersAsPaid(List <Cart> carts)
    {
        YWC_StorageEntities db = new YWC_StorageEntities();

        if (carts != null)
        {
            foreach (Cart cart in carts)
            {
                Cart oldcart = db.Carts.Find(cart.ID);
                oldcart.DatePurchased = DateTime.Now;
                oldcart.IsInCart      = false;
            }

            db.SaveChanges();
        }
    }
Exemplo n.º 7
0
 public List <PurchasedProduct> GetAllPurchasedProducts()
 {
     try
     {
         using (YWC_StorageEntities db = new YWC_StorageEntities())
         {
             List <PurchasedProduct> purchasedProducts = (from x in db.PurchasedProducts
                                                          select x).ToList();
             return(purchasedProducts);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
 public string[] GetAllProductNames()
 {
     try
     {
         using (YWC_StorageEntities db = new YWC_StorageEntities())
         {
             string[] products = (from x in db.ProductTypes
                                  select x.Name).ToArray();
             return(products);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
Exemplo n.º 9
0
 public List <Product> GetAllProductsByType(int typeId)
 {
     try
     {
         using (YWC_StorageEntities db = new YWC_StorageEntities())
         {
             List <Product> products = (from x in db.Products
                                        where x.TypeId == typeId
                                        select x).ToList();
             return(products);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
Exemplo n.º 10
0
    public int GetAmountOfOrders(string userId)
    {
        try
        {
            YWC_StorageEntities db = new YWC_StorageEntities();
            int amount             = (from x in db.Carts
                                      where x.ClientID == userId &&
                                      x.IsInCart
                                      select x.Amount).Sum();

            return(amount);
        }
        catch
        {
            return(0);
        }
    }
Exemplo n.º 11
0
    public string DeleteCart(int id)
    {
        try
        {
            YWC_StorageEntities db = new YWC_StorageEntities();
            Cart cart = db.Carts.Find(id);

            db.Carts.Attach(cart);
            db.Carts.Remove(cart);
            db.SaveChanges();

            return(cart.DatePurchased + " was successfully deleted");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
Exemplo n.º 12
0
    public string DeletePurchasedProduct(int id)
    {
        try
        {
            YWC_StorageEntities db = new YWC_StorageEntities();
            PurchasedProduct    purchasedProduct = db.PurchasedProducts.Find(id);

            db.PurchasedProducts.Attach(purchasedProduct);
            db.PurchasedProducts.Remove(purchasedProduct);
            db.SaveChanges();

            return(purchasedProduct.Name + " was successfully deleted");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
Exemplo n.º 13
0
    public string DeleteProductType(int id)
    {
        try
        {
            YWC_StorageEntities db          = new YWC_StorageEntities();
            ProductType         productType = db.ProductTypes.Find(id);

            db.ProductTypes.Attach(productType);
            db.ProductTypes.Remove(productType);
            db.SaveChanges();

            return(productType.Name + " was successfully deleted");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
Exemplo n.º 14
0
    public string DeleteOrder(int id)
    {
        try
        {
            YWC_StorageEntities db    = new YWC_StorageEntities();
            OrderDetail         order = db.OrderDetails.Find(id);

            db.OrderDetails.Attach(order);
            db.OrderDetails.Remove(order);
            db.SaveChanges();

            return(order.DatePurchased + " was successfully deleted");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
Exemplo n.º 15
0
    public string UpdateProductType(int id, ProductType productType)
    {
        try
        {
            YWC_StorageEntities db = new YWC_StorageEntities();

            //Fetch an object from db
            ProductType p = db.ProductTypes.Find(id);

            //Replace the data in db
            p.Name = productType.Name;

            db.SaveChanges();

            return(productType.Name + " was successfully updated");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
Exemplo n.º 16
0
    public PageContent GetPageContent()
    {
        YWC_StorageEntities db = new YWC_StorageEntities();

        return(db.PageContents.Find(0));
    }
Exemplo n.º 17
0
    private void GetAllOrders()
    {
        YWC_StorageEntities db         = new YWC_StorageEntities();
        OrderModel          orderModel = new OrderModel();
        CartModel           cartModel  = new CartModel();

        List <PurchasedProduct> purchasedList = new List <PurchasedProduct>();
        List <Cart>             cartList      = new List <Cart>();

        if (!String.IsNullOrWhiteSpace(Request.QueryString["id"]))
        {
            int         id    = Convert.ToInt32(Request.QueryString["id"]);
            OrderDetail order = orderModel.GetOrder(id);

            foreach (PurchasedProduct purchasedProduct in db.PurchasedProducts)
            {
                if (purchasedProduct.ClientID == order.ClientID && order.DatePurchased == purchasedProduct.DatePurchased)
                {
                    purchasedList.Add(purchasedProduct);

                    Cart cart = new Cart();

                    cart.DatePurchased = purchasedProduct.DatePurchased;
                    cart.ClientID      = purchasedProduct.ClientID;
                    cart.IsInCart      = true;
                    cart.ProductID     = purchasedProduct.TypeId;
                    cart.Amount        = purchasedProduct.Amount;

                    cartList.Add(cart);
                }
            }


            double subTotal = 0;
            CreateOrderTable(cartList, out subTotal);

            //Add totals to webpage
            double vat         = subTotal * tax / 100;
            double totalAmount = subTotal + vat;

            litTotal.Text       = "$" + subTotal;
            litVat.Text         = vat.ToString("C", new CultureInfo("en-US"));
            litTotalAmount.Text = totalAmount.ToString("C", new CultureInfo("en-US"));

            litClientName.Text    = order.ClientName.ToString();
            litClientEmail.Text   = order.ClientEmail;
            litClientAddress.Text = order.ClientAddress;
            litPurchaseDate.Text  = order.DatePurchased.ToString();

            if (order.Status == "PENDING")
            {
                lblOrderStatus.Text     = "Order Pending";
                lblOrderStatusDesc.Text = "Order not yet completed. Please press this button once the food has been made or delivered.";
                lnkDeleteOrder.Visible  = false;
                lnkDeleteOrder.Enabled  = false;
                buttonSend.Visible      = true;
                textBoxTracking.Visible = false;
            }
            else
            {
                lblOrderStatus.Text     = "Order Completed";
                lblOrderStatusDesc.Text = "Order is completed. No further action is required.";
                lnkDeleteOrder.Visible  = true;
                lnkDeleteOrder.Enabled  = true;
                buttonSend.Visible      = false;
                textBoxTracking.Visible = false;
            }
        }
    }
Exemplo n.º 18
0
    private void GetAllOrders()
    {
        YWC_StorageEntities db         = new YWC_StorageEntities();
        OrderModel          orderModel = new OrderModel();
        CartModel           cartModel  = new CartModel();

        List <Cart> cartList = new List <Cart>();

        if (!String.IsNullOrWhiteSpace(Request.QueryString["id"]))
        {
            int         id       = Convert.ToInt32(Request.QueryString["id"]);
            OrderDetail order    = orderModel.GetOrder(id);
            string      cartDate = "";

            foreach (Cart cart in db.Carts)
            {
                cartDate = cart.DatePurchased.ToString();

                if (cart.ClientID == order.ClientID && order.DatePurchased.ToString() == cartDate)
                {
                    cartList.Add(cart);
                }
            }


            double subTotal = 0;
            CreateOrderTable(cartList, out subTotal);

            //Add totals to webpage
            double vat         = subTotal * tax / 100;
            double totalAmount = subTotal + shipping + vat;

            litTotal.Text       = "$ " + subTotal;
            litVat.Text         = "$ " + vat;
            litTotalAmount.Text = "$ " + totalAmount;
            litShipping.Text    = "$ " + shipping;

            litClientName.Text    = order.ClientName.ToString();
            litClientEmail.Text   = order.ClientEmail;
            litClientAddress.Text = order.ClientAddress;
            litPurchaseDate.Text  = order.DatePurchased.ToString();

            if (order.Status == "PENDING")
            {
                lblOrderStatus.Text     = "Confirmation Pending";
                lblOrderStatusDesc.Text = "Order not yet confirmerd. Please enter the tracking ID number provided by the post office to send delivery confirmation to client.";
                lnkDeleteOrder.Visible  = false;
                lnkDeleteOrder.Enabled  = false;
                textBoxTracking.Visible = true;
                buttonSend.Visible      = true;
            }
            else
            {
                lblOrderStatus.Text     = "Order Confirmed";
                lblOrderStatusDesc.Text = "Order is confirmed. No further action is required.";
                lnkDeleteOrder.Visible  = true;
                lnkDeleteOrder.Enabled  = true;
                textBoxTracking.Visible = false;
                buttonSend.Visible      = false;
            }
        }
    }
Exemplo n.º 19
0
    public TaxShipping GetTaxShipping()
    {
        YWC_StorageEntities db = new YWC_StorageEntities();

        return(db.TaxShippings.Find(0));
    }