Exemplo n.º 1
0
        public int CreateStock(Stocks stock)
        {
            int _newStockid = 0;

            try
            {
                ReadStock           createdData   = new ReadStock();
                ESGetDetail         createdESData = new ESGetDetail();
                ElasticSearchClient createES      = new ElasticSearchClient();
                createdData = _dataAccessLayer.CreateDbStock(stock);
                string cacheKey = CreateKey(createdData.ID);
                using (MemcachedClient client = new MemcachedClient("memcached"))
                {
                    client.Store(StoreMode.Add, cacheKey, createdData, DateTime.Now.AddMinutes(15));
                }
                createdESData = ConvertCachetoESData(createdData);
                //getCreatedData = Mapper.Map<ReadStock, ESGetDetail>(getCreatedData);
                createES.CreateESStock(createdESData);
                _newStockid = createdESData.ID;
            }
            catch (Exception)
            {
                throw;
            }
            return(_newStockid);
        }
Exemplo n.º 2
0
        public ReadStock CreateDbStock(Stocks stock)
        {
            ReadStock stockDetail = new ReadStock();

            try
            {
                using (IDbConnection conn = new MySqlConnection(_connString))
                {
                    stockDetail = conn.Query <ReadStock>("sp_UsedCarsCreate", stock, commandType: CommandType.StoredProcedure).FirstOrDefault();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(stockDetail);
        }
Exemplo n.º 3
0
        private ESGetDetail ConvertCachetoESData(ReadStock getUpdatedData)
        {
            ESGetDetail convertedData = new ESGetDetail();

            if (getUpdatedData != null)
            {
                convertedData.CarCompany = getUpdatedData.CarCompany;
                convertedData.ID         = getUpdatedData.ID;
                convertedData.Price      = getUpdatedData.Price;
                convertedData.Year       = getUpdatedData.Year;
                convertedData.Kilometers = getUpdatedData.Kilometers;
                convertedData.FuelType   = getUpdatedData.FuelType;
                convertedData.City       = getUpdatedData.City;
                convertedData.ModelName  = getUpdatedData.ModelName;
                convertedData.CarVersion = getUpdatedData.CarVersion;
            }
            return(convertedData);
        }
Exemplo n.º 4
0
        public ReadStock ReadDbStock(int stockId)
        {
            ReadStock stockDetail = new ReadStock();

            try
            {
                var param = new DynamicParameters();
                param.Add("stockId", stockId, direction: ParameterDirection.Input);
                using (IDbConnection conn = new MySqlConnection(_connString))
                {
                    stockDetail = conn.Query <ReadStock>("sp_UsedCarsGetData", param, commandType: CommandType.StoredProcedure).AsList()[0];
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(stockDetail);
        }
Exemplo n.º 5
0
        public void UpdateStock(int stockId, Stocks stock)
        {
            string              cacheKey      = CreateKey(stockId);
            ReadStock           updatedData   = new ReadStock();
            ElasticSearchClient updateES      = new ElasticSearchClient();
            ESGetDetail         updatedESData = new ESGetDetail();

            try
            {
                updatedData = _dataAccessLayer.EditDbStock(stockId, stock);
                using (MemcachedClient client = new MemcachedClient("memcached"))
                {
                    client.Store(StoreMode.Set, cacheKey, updatedData, DateTime.Now.AddMinutes(60));
                }
                updatedESData = ConvertCachetoESData(updatedData);
                //getCreatedData = Mapper.Map<ReadStock, ESGetDetail>(getCreatedData);
                updateES.UpdateESStock(stockId, updatedESData);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="stockId"></param>
        /// <returns></returns>
        public ReadStock GetStock(int stockId)
        {
            ReadStock carDetails = null;

            try
            {
                string cacheKey = CreateKey(stockId);
                using (MemcachedClient _client = new MemcachedClient("memcached"))
                {
                    carDetails = (ReadStock)_client.Get(cacheKey);
                    if (carDetails == null)
                    {
                        carDetails = _dataAccessLayer.ReadDbStock(stockId);
                        _client.Store(StoreMode.Add, cacheKey, carDetails, DateTime.Now.AddMinutes(60));
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return(carDetails);
        }