public async Task <ShoppingCartResponse> AddLaptopToCartAsync(MODEL.ShoppingCart shoppingCart) { MODEL.ShoppingCartResponse shoppingCartResponse = new MODEL.ShoppingCartResponse(); try { List <MODEL.ShoppingCart> ShoppingCarts = new List <MODEL.ShoppingCart>(); using (var firstConnection = new SqliteConnection(DbConnection.connectionString)) { firstConnection.Open(); var updateCommand = firstConnection.CreateCommand(); string query = "INSERT INTO ShoppingCart (Name,Ram,Hdd,Color,price) VALUES ('" + shoppingCart.Name + "','" + shoppingCart.Ram + "','" + shoppingCart.Hdd + "','" + shoppingCart.Color + "','" + shoppingCart.Price + "')"; updateCommand.CommandText = query; updateCommand.ExecuteNonQuery(); updateCommand.CommandText = @" SELECT * FROM ShoppingCart "; SqliteDataReader adr = updateCommand.ExecuteReader(); while (adr.Read()) { MODEL.ShoppingCart shoppingCartObj = new MODEL.ShoppingCart(); shoppingCartObj.Id = adr.GetInt32(0); shoppingCartObj.Name = adr.GetString(1); shoppingCartObj.Ram = adr.GetString(2); shoppingCartObj.Hdd = adr.GetString(3); shoppingCartObj.Color = adr.GetString(4); shoppingCartObj.Price = adr.GetString(5); ShoppingCarts.Add(shoppingCartObj); } } shoppingCartResponse.Laptops = ShoppingCarts; } catch (Exception) { } return(await Task.FromResult(shoppingCartResponse)); }
public async Task <ShoppingCartResponse> GetCartItemsAsync() { MODEL.ShoppingCartResponse shoppingCartResponse = new MODEL.ShoppingCartResponse(); try { List <MODEL.ShoppingCart> ShoppingCarts = new List <MODEL.ShoppingCart>(); using (var firstConnection = new SqliteConnection(DbConnection.connectionString)) { firstConnection.Open(); var updateCommand = firstConnection.CreateCommand(); updateCommand.CommandText = @" SELECT * FROM ShoppingCart "; SqliteDataReader adr = updateCommand.ExecuteReader(); while (adr.Read()) { MODEL.ShoppingCart shoppingCartObj = new MODEL.ShoppingCart(); shoppingCartObj.Id = adr.GetInt32(0); shoppingCartObj.Name = adr.GetString(1); shoppingCartObj.Ram = adr.GetString(2); shoppingCartObj.Hdd = adr.GetString(3); shoppingCartObj.Color = adr.GetString(4); shoppingCartObj.Price = adr.GetString(5); ShoppingCarts.Add(shoppingCartObj); } } shoppingCartResponse.Laptops = ShoppingCarts; } catch (Exception) { } return(await Task.FromResult(shoppingCartResponse)); }