예제 #1
0
        public static async Task <string[]> GetCartItems()
        {
            try
            {
                List <CartItems> cartItemsList = new List <CartItems>();

                cartItemsList = CookieManager.GetCookie();

                string[] cartItems     = new string[] { "", "0", "0€", "", "" };
                int      loyaltyPoints = 0;

                if (cartItemsList != null)
                {
                    var jsonArray = JArray.Parse(await APIRequest());
                    int count     = jsonArray.Count();

                    List <Items> itemsList = jsonArray.ToObject <List <Items> >();

                    for (int j = 0; j < cartItemsList.Count; j++)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            if (cartItemsList[j].Id == itemsList[i].Id)
                            {
                                cartItems[0] = cartItems[0] + "<li class='cart_item item_list d-flex flex-lg-row flex-column align-items-lg-center align-items-start justify-content-start'>" +
                                               "<div class='product d-flex flex-lg-row flex-column align-items-lg-center align-items-start justify-content-start'>" +
                                               "<div><div class='product_image'><img src = '../Images/" + itemsList[i].Image + "'></div></div>" +
                                               "<div class='product_name'><a href = 'Product?id=" + itemsList[i].Id + "')'>" + itemsList[i].Name + "</a></div>" +
                                               "</div>" +
                                               "<div class='product_color_" + itemsList[i].Type.ToLower() + " text-lg-center product_text'>" + itemsList[i].Type + "</div>" +
                                               "<div class='product_price text-lg-center product_text'>" + PriceCalculation.EquipmentPrice(itemsList[i].Type, 1) + "€" + "</div>" +
                                               "<div class='product_time text-lg-center product_text'>" + TimeToDate.GetDate(Convert.ToInt32(cartItemsList[j].Time)) + "</div>" +
                                               "<div class='product_total text-lg-center product_text'>" + cartItemsList[j].Price + "€" + "</div>" +
                                               "<div class='product_delete text-lg-center product_text'><i class='fa fa-close' onclick='deleteProduct(" + j + ")'></i></div>" +
                                               "</li>";

                                cartItems[3] = cartItems[3] + "<li class='d-flex flex-row align-items-center justify-content-start'>" +
                                               "<div class='cart_extra_total_title'>" + itemsList[i].Name + " | " + TimeToDate.GetDate(Convert.ToInt32(cartItemsList[j].Time)) + "</div>" +
                                               "<div class='cart_extra_total_value ml-auto'>" + cartItemsList[j].Price + "€" + "</div>" +
                                               "</li>";

                                loyaltyPoints = loyaltyPoints + LoyaltyPointsManager.GetPoints(itemsList[i].Type);
                            }
                        }
                    }
                    int totalPrice = 0;

                    for (int i = 0; i < cartItemsList.Count; i++)
                    {
                        totalPrice = totalPrice + Convert.ToInt32(cartItemsList[i].Price);
                    }

                    cartItems[1] = cartItemsList.Count.ToString();
                    cartItems[2] = totalPrice.ToString() + "€";
                    cartItems[4] = "<li class='d-flex flex-row align-items-center justify-content-start'>" +
                                   "<div class='cart_extra_total_title'>Loyalty points</div>" +
                                   "<div class='cart_extra_total_value ml-auto'>" + loyaltyPoints.ToString() + "</div>" +
                                   "</li>";

                    return(cartItems);
                }
                return(cartItems);
            }
            catch
            {
                throw new HttpException(404, "Not Found");
            }
        }
예제 #2
0
        public static async Task <List <InvoiceItems> > GetInvoiceInfo()
        {
            try
            {
                List <InvoiceItems> invoiceItems  = new List <InvoiceItems>();
                List <CartItems>    cartItemsList = new List <CartItems>();

                cartItemsList = CookieManager.GetCookie();

                if (cartItemsList != null)
                {
                    var jsonArray = JArray.Parse(await APIRequest());
                    int count     = jsonArray.Count();

                    List <Items> itemsList = jsonArray.ToObject <List <Items> >();

                    for (int j = 0; j < cartItemsList.Count; j++)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            if (cartItemsList[j].Id == itemsList[i].Id)
                            {
                                invoiceItems.Add(new InvoiceItems {
                                    Name = itemsList[i].Name, Price = cartItemsList[j].Price, Time = TimeToDate.GetDate(Convert.ToInt32(cartItemsList[j].Time)), Type = itemsList[i].Type
                                });
                            }
                        }
                    }
                    return(invoiceItems);
                }
                return(null);
            }
            catch
            {
                throw new HttpException(404, "Not Found");
            }
        }