Ejemplo n.º 1
0
        public async Task <DC.LaptopResponse> AddLaptopAsync(Laptop laptop)
        {
            DC.LaptopResponse laptopResponse1 = new DC.LaptopResponse();
            try
            {
                Model.LaptopResponse laptopResponse = await _laptopDAL.AddLaptopAsync(_mapper.Map <Model.Laptop>(laptop));

                laptopResponse1 = _mapper.Map <DC.LaptopResponse>(laptopResponse);
            }
            catch (Exception)
            {
            }
            return(laptopResponse1);
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        public async Task <DC.LaptopResponse> GetListOfLaptopAsync()
        {
            DC.LaptopResponse laptopResponse1 = new DC.LaptopResponse();
            try
            {
                Model.LaptopResponse laptopResponse = await _laptopDAL.GetListOfLaptopAsync();

                laptopResponse1 = _mapper.Map <DC.LaptopResponse>(laptopResponse);
            }
            catch (Exception)
            {
            }
            return(laptopResponse1);
        }
Ejemplo n.º 4
0
        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));
        }