public static List <Products> GetProducts(Guests g) { var list = new List <Products>(); foreach (Products p in products) { if (GetBookers(p).Contains(g.ID)) { list.Add(p); } } return(list); }
public static async Task <HttpResponseMessage> EditUser(Guests g) { //if (string.IsNullOrEmpty(g.Cart)) //{ // g.Cart = null; //} var json = JsonConvert.SerializeObject(g); var content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient client = new HttpClient(); var responce = await client.PutAsync(LINK + USERS + "/" + g.ID, content); return(responce); }
public static List <int> GetQuantities(Guests user) { var list = new List <int>(); if (!string.IsNullOrEmpty(user.Cart)) { var cart = user.Cart.Split(';'); for (int x = 0; x < cart.Length; x++) { list.Add(int.Parse(cart[x].Split(',')[1])); } } return(list); }
public static List <int> getCart(Guests g) { List <int> ints = new List <int>(); if (!string.IsNullOrEmpty(g.Cart)) { string[] s = g.Cart.Split(';'); foreach (string a in s) { string[] d = a.Split(','); ints.Add(int.Parse(d[0])); } } return(ints); }
public static int GetQuantity(Guests user, Products product) { if (hasBooked(user, product)) { var str = user.Cart.Split(';'); foreach (var a in str) { var b = a.Split(','); if (int.Parse(b[0]) == product.ID) { return(int.Parse(b[1])); } } } return(0); }
public static async Task Unbook(Guests user, Products product, bool restore) { if (hasBooked(user, product)) { var cart = user.Cart.Split(';'); var newCart = ""; int quantity = 0; int S = 0; for (int x = 0; x < cart.Length; x++) { var f = cart[x].Split(','); int a = int.Parse(f[0]); if (a != product.ID) { if (S > 0) { newCart += ";"; } newCart += cart[x]; S++; } else { quantity = int.Parse(f[1]); } } if (string.IsNullOrEmpty(newCart)) { newCart = null; } user.Cart = newCart; await FullyEditUser(user); if (restore) { product.Quantity += quantity; await FullyEditProduct(product); } } }
public static async Task FullyEditUser(Guests user) { await EditUser(user); await LoadUsers(); }
public static bool hasBooked(Guests user, Products product) { return(getCart(user).Contains(product.ID)); }