public async Task <MODEL.Laptop> GetListOfLaptopByIdAsync(int id) { MODEL.Laptop laptop = new MODEL.Laptop(); try { using (var firstConnection = new SqliteConnection(DbConnection.connectionString)) { firstConnection.Open(); var selectCommand = firstConnection.CreateCommand(); selectCommand.CommandText = @" SELECT * FROM LAPTOP where id=" + id + ""; SqliteDataReader adr = selectCommand.ExecuteReader(); while (adr.Read()) { laptop.Id = adr.GetInt32(0); laptop.Name = adr.GetString(1); laptop.Price = adr.GetString(2); } } } catch (Exception) { } return(await Task.FromResult(laptop)); }
public async Task <MODEL.LaptopResponse> AddLaptopAsync(MODEL.Laptop laptop) { MODEL.LaptopResponse laptopResponse = new MODEL.LaptopResponse(); try { List <MODEL.Laptop> list1 = new List <MODEL.Laptop>(); using (var firstConnection = new SqliteConnection(DbConnection.connectionString)) { firstConnection.Open(); var updateCommand = firstConnection.CreateCommand(); string query1 = "select * from Laptop where Name='" + laptop.Name + "'"; updateCommand.CommandText = query1; SqliteDataReader adr1 = updateCommand.ExecuteReader(); bool flag = adr1.HasRows; if (flag) { return(null); } adr1.Close(); string query = "INSERT INTO Laptop (Name,price) VALUES ('" + laptop.Name + "','" + laptop.Price + "')"; updateCommand.CommandText = query; updateCommand.ExecuteNonQuery(); updateCommand.CommandText = @" SELECT * FROM LAPTOP "; SqliteDataReader adr = updateCommand.ExecuteReader(); while (adr.Read()) { MODEL.Laptop laptopObj = new MODEL.Laptop(); laptopObj.Id = adr.GetInt32(0); laptopObj.Name = adr.GetString(1); laptopObj.Price = adr.GetString(2); list1.Add(laptopObj); } } laptopResponse.Laptops = list1; } catch (Exception ex) { } return(await Task.FromResult(laptopResponse)); }
public async Task <MODEL.LaptopResponse> GetListOfLaptopAsync() { MODEL.LaptopResponse laptopResponse = new MODEL.LaptopResponse(); try { List <MODEL.Laptop> list = new List <MODEL.Laptop>(); using (var firstConnection = new SqliteConnection(DbConnection.connectionString)) { firstConnection.Open(); var selectCommand = firstConnection.CreateCommand(); selectCommand.CommandText = @" SELECT * FROM LAPTOP "; SqliteDataReader adr = selectCommand.ExecuteReader(); while (adr.Read()) { MODEL.Laptop laptopObj = new MODEL.Laptop(); laptopObj.Id = adr.GetInt32(0); laptopObj.Name = adr.GetString(1); laptopObj.Price = adr.GetString(2); list.Add(laptopObj); } } laptopResponse.Laptops = list; } catch (Exception) { } return(await Task.FromResult(laptopResponse)); }
public async Task <Laptop> GetListOfLaptopByIdAsync(int id) { Model.Laptop laptop = await _laptopDAL.GetListOfLaptopByIdAsync(id); return(_mapper.Map <DC.Laptop>(laptop)); }