예제 #1
0
        public async Task <ShoppingCartResponse> AddLaptopToCartAsync(ShoppingCart shoppingCart)
        {
            DC.ShoppingCartResponse _shoppingCartResponse = new DC.ShoppingCartResponse();
            try
            {
                Model.ShoppingCartResponse shoppingCartResponse = await _laptopDAL.AddLaptopToCartAsync(_mapper.Map <Model.ShoppingCart>(shoppingCart));

                _shoppingCartResponse = _mapper.Map <DC.ShoppingCartResponse>(shoppingCartResponse);
            }
            catch (Exception)
            {
            }
            return(_shoppingCartResponse);
        }
예제 #2
0
        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));
        }
예제 #3
0
        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));
        }
예제 #4
0
        public async Task <ShoppingCartResponse> GetCartItemsAsync()
        {
            Model.ShoppingCartResponse shoppingCart = await _laptopDAL.GetCartItemsAsync();

            return(_mapper.Map <DC.ShoppingCartResponse>(shoppingCart));
        }