public static async Task <string> MakeInvoice(string name, string last_name, string country, string address, string zipcode, string city, string province, string phone, string email, string currentPath) { try { List <InvoiceItems> invoiceItems = new List <InvoiceItems>(); invoiceItems = await ApiRequests.GetInvoiceInfo(); string path = currentPath.Substring(0, currentPath.Length - 16) + "invoice.txt"; if (invoiceItems != null) { int totalPrice = 0; int loyaltyPoints = 0; if (!File.Exists(path)) { // Create a file to write to. using (StreamWriter sw = File.CreateText(path)) { sw.WriteLine("----------------------------INVOICE-------------------------------\n"); sw.WriteLine("Test OÜ"); sw.WriteLine("Paldiski maantee 203, 13517 Tallinn, Estonia"); sw.WriteLine("+372 5854 8945"); sw.WriteLine("*****@*****.**"); sw.WriteLine("\n----------------------------INVOICE TO----------------------------\n"); sw.WriteLine(name + " " + last_name); sw.WriteLine(address + ", " + zipcode + " " + city + ", " + province + ", " + country); sw.WriteLine(email); sw.WriteLine(phone); sw.WriteLine("\n----------------------------PRODUCTS------------------------------\n"); for (int i = 0; i < invoiceItems.Count; i++) { sw.WriteLine("Product: " + invoiceItems[i].Name); sw.WriteLine("Price (1 Day): " + PriceCalculation.EquipmentPrice(invoiceItems[i].Type, 1) + "€"); sw.WriteLine("Type: " + invoiceItems[i].Type); sw.WriteLine("Time: " + invoiceItems[i].Time); sw.WriteLine("Total: " + invoiceItems[i].Price + "€" + "\n"); loyaltyPoints = loyaltyPoints + LoyaltyPointsManager.GetPoints(invoiceItems[i].Type); totalPrice = totalPrice + Convert.ToInt32(invoiceItems[i].Price); } sw.WriteLine("----------------------------TOTAL---------------------------------\n"); sw.WriteLine("Total: " + totalPrice + "€"); sw.WriteLine("Loyalty points received: " + loyaltyPoints + "\n\n"); sw.WriteLine("Thank you for your purchase!"); } } } return("Thank you for your purchase!"); } catch { return("For some reason we can't make an invoice!"); } }
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"); } }