Exemple #1
0
        public bool SaveYachtBookingtoRedis(RedisCachesModel yachtBookingModel)
        {
            var requestModel = new BaseRequest <RedisCachesModel>(yachtBookingModel);
            var apiResult    = _apiExcute.PostData <object, RedisCachesModel>("http://localhost:220/api/RedisCache/RedisCache/SimpleKey/Model/Set", requestModel, _token).Result;

            if (apiResult.IsSuccessStatusCode)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
        BaseResponse <string> IRedisCacheService.SetSimpleKeyModel(RedisCachesModel entireData)
        {
            try
            {
                if (entireData != null)
                {
                    string key   = entireData.Key;
                    string value = "";
                    if (entireData.CartStorage.Count > 0)
                    {
                        value = JsonConvert.SerializeObject(entireData.CartStorage);
                    }
                    _distributedCache.SetString(key, value);
                }

                return(BaseResponse <string> .Success("1"));
            }
            catch (Exception ex)
            {
                return(BaseResponse <string> .InternalServerError("-1", message : ex.Message, fullMsg : ex.StackTrace));
            }
        }
        public IActionResult SetSimpleKeyModel(RedisCachesModel entireData)
        {
            var result = _redisCacheService.SetSimpleKeyModel(entireData);

            return(Ok(result));
        }
        public IActionResult CopyLocalStorageToRedisCache(RedisCachesModel requestModel)
        {
            var result = _redisCacheService.CopyLocalStorageToRedisCache(requestModel);

            return(Ok(result));
        }
Exemple #5
0
        public BaseResponse <ResponseModel> CopyLocalStorageToRedisCache(RedisCachesModel requestModel)
        {
            ResponseModel resultModel = new ResponseModel();

            resultModel.Id        = "";
            resultModel.CodeError = "";

            try
            {
                var value = _distributedCache.GetString(requestModel.Key);
                if (requestModel != null)
                {
                    if (value != null)// Haskey Have been existing Value
                    {
                        var lstRedisStorage = JsonConvert.DeserializeObject <List <RedisStorage> >(value);
                        //requestModel.HashKey ==> Dining or Yacht or other...
                        var RedisStorageModel = lstRedisStorage.FirstOrDefault(k => k.Domain == requestModel.HashKey);
                        #region DOMAIN
                        if (RedisStorageModel != null)// DOMAIN IS  EXIST
                        {
                            var result = RedisStorageModel.PackageStorage;

                            if (requestModel.CartStorage != null)
                            {
                                if (result.Count > 0)//if RedisCache have some Yacht Infomation
                                {
                                    foreach (YachtPackageServiceModel cartItem in requestModel.CartStorage as List <YachtPackageServiceModel> )
                                    {
                                        //get Redis Cache Yacht infomation by Id
                                        var yachtStoraged = result.FirstOrDefault(x => x.YachtId.Trim() == cartItem.YachtId.Trim());

                                        if (yachtStoraged != null)// Yacht was existing
                                        {
                                            yachtStoraged.CheckIn        = cartItem.CheckIn;
                                            yachtStoraged.CheckOut       = cartItem.CheckOut;
                                            yachtStoraged.Passenger      = cartItem.Passenger;
                                            yachtStoraged.ProductPackage = cartItem.ProductPackage;
                                            //    if (yachtStoraged.ProductPackage != null && cartItem.ProductPackage != null)//checking package
                                            //    {
                                            //        if (yachtStoraged.ProductPackage.Count > 0 )//Some Existing package in Yacht
                                            //        {
                                            //            foreach (MerchantProductInventoriesModel packageItem in cartItem.ProductPackage)
                                            //            {
                                            //                var packageStorage = yachtStoraged.ProductPackage.FirstOrDefault(x => x.productInventoryFId.Trim() == packageItem.productInventoryFId.Trim());
                                            //                #region if Package of Yacht have be Existing , just Sum the quatility Field and else add entire
                                            //                if (packageStorage != null)//Update Package in Existing Yacht
                                            //                {
                                            //                    int newQuality = packageStorage.quantity + packageItem.quantity;
                                            //                    packageStorage.quantity = newQuality;
                                            //                }
                                            //                else //add new Pakage in Yacht
                                            //                {
                                            //                    yachtStoraged.ProductPackage.Add(packageItem);
                                            //                }
                                            //                #endregion
                                            //            }
                                            //        }
                                            //    }
                                            //    else// change Existing Package was Storaged in Redist of Yacht through new package was NULL
                                            //    {
                                            //        yachtStoraged.ProductPackage = cartItem.ProductPackage;
                                            // }
                                        }
                                        else //yacht is unvaliable in list
                                        {
                                            result.Add(cartItem);
                                        }
                                    }
                                }
                                else
                                {
                                    result.AddRange(requestModel.CartStorage);
                                }
                                string strSave = JsonConvert.SerializeObject(lstRedisStorage);
                                _distributedCache.SetString(requestModel.Key, strSave);
                            }
                        }
                        else // DOMAIN IS NOT EXIST
                        {
                            if (requestModel.CartStorage != null)
                            {
                                List <RedisStorage> saveCartStorage = new List <RedisStorage>()
                                {
                                    new RedisStorage()
                                    {
                                        Domain         = requestModel.HashKey,
                                        PackageStorage = requestModel.CartStorage
                                    }
                                };

                                string strSave = JsonConvert.SerializeObject(saveCartStorage);
                                _distributedCache.SetString(requestModel.Key, strSave);
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        if (requestModel.CartStorage != null)
                        {
                            List <RedisStorage> saveCartStorage = new List <RedisStorage>()
                            {
                                new RedisStorage()
                                {
                                    Domain         = requestModel.HashKey,
                                    PackageStorage = requestModel.CartStorage
                                }
                            };

                            string strSave = JsonConvert.SerializeObject(saveCartStorage);
                            _distributedCache.SetString(requestModel.Key, strSave);
                        }
                    }
                }

                return(BaseResponse <ResponseModel> .Success(resultModel));
            }
            catch (Exception ex)
            {
                return(BaseResponse <ResponseModel> .InternalServerError(resultModel, message : ex.Message, fullMsg : ex.StackTrace));
            }
        }