Exemplo n.º 1
0
        /// <summary>
        /// Sends verification code to logged-in user's phone number.
        /// <para><b> IMPORTANT INFORMATION : The message sending service has not yet been integrated.
        ///                                   So this method will not send message to the user's gsm number.
        ///                                   Instead of returns verification code for testing. </b></para>
        /// </summary>
        /// <returns></returns>
        public async Task <string> SendPhoneNumberVerificationMessageAsync()
        {
            CheckLoginStatus();

            var user = await _userRepository.GetFirstOrDefaultAsync(a => a.UserName == _userName).ConfigureAwait(false);

            if (string.IsNullOrWhiteSpace(user?.PhoneNumber))
            {
                throw new MilvaUserFriendlyException("IdentityInvalidPhoneNumber");
            }

            var verificationCode = GenerateVerificationCode();

            if (!_redisCacheService.IsConnected())
            {
                try
                {
                    await _redisCacheService.ConnectAsync().ConfigureAwait(false);
                }
                catch (Exception)
                {
                    _ = _milvaLogger.LogFatalAsync("Redis is not available!!", MailSubject.ShutDown);
                    throw new MilvaUserFriendlyException("CannotSendMessageNow");
                }
            }

            await _redisCacheService.SetAsync($"pvc_{_userName}", verificationCode, TimeSpan.FromMinutes(3)).ConfigureAwait(false);

            //Doğrulama kodunu mesaj olarak gönderme entegrasyonu buraya eklenecek.
            //O yüzden şimdilik geriye dönüyoruz bu kodu.

            return(verificationCode);
        }
Exemplo n.º 2
0
        public async Task <BaseResponse <object> > GetAll()
        {
            //BaseResponse<IEnumerable<CityDto>> baseResponse = new BaseResponse<IEnumerable<CityDto>>();
            string key       = RedisConsts.City + DateTime.Now.ToString("yyyyMMdd_hh");
            var    keyExists = await _redisCacheService.Contains(key);

            if (keyExists)
            {
                var recordsInCache = _redisCacheService.Get <IEnumerable <CityDto> >(key);
                _response.IsSuccess = true;
                _response.TimeStamp = DateTime.Now;
                _response.Result    = recordsInCache;
            }
            else
            {
                var result = await _cityRepository.GetAll();

                var mappedResult = _mapper.Map <IEnumerable <CityDto> >(result);
                _response.IsSuccess = true;
                _response.TimeStamp = DateTime.Now;
                _response.Result    = mappedResult;
                _redisCacheService.SetAsync <IEnumerable <CityDto> >(key, mappedResult);
            }
            return(_response);
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        public async Task <IActionResult> Index()
        {
            if (!_redisCacheService.TryGetValue(key: CacheKeyTemplate.PostsCacheKey, result: out IEnumerable <PostOutput> posts))
            {
                posts = await _postService.SearchAsync(page : 0, recordsPerPage : recordsPerPage, term : "", taxonomyId : null, taxonomyType : null, publishStatus : PublishStatus.Publish, sortOrder : SortOrder.Desc);

                await _redisCacheService.SetAsync(key : CacheKeyTemplate.PostsCacheKey, data : posts, cacheTimeInMinutes : 60);
            }

            return(View(posts));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Articles(string taxonomyId = null, TaxonomyType?taxonomyType = null, string taxonomyName = "")
        {
            var cacheKey = string.Format(CacheKeyTemplate.PostsSearchCacheKey, 0, recordsPerPage, taxonomyId, taxonomyType);

            if (!_redisCacheService.TryGetValue(key: cacheKey, result: out IEnumerable <PostOutput> posts))
            {
                posts = await _postService.SearchAsync(page : 0, recordsPerPage : recordsPerPage, term : "", taxonomyId : taxonomyId, taxonomyType : taxonomyType, publishStatus : PublishStatus.Publish, sortOrder : SortOrder.Desc);

                await _redisCacheService.SetAsync(key : cacheKey, data : posts, cacheTimeInMinutes : 60);
            }

            #region ViewBags

            ViewBag.TaxonomyName = taxonomyName;
            ViewBag.TaxonomyId   = taxonomyId;
            ViewBag.TaxonomyType = taxonomyType;

            #endregion

            return(View(posts));
        }
Exemplo n.º 5
0
    /// <summary>
    /// Sets a tenant with a given identifier.
    /// </summary>
    /// <param name="identifier"></param>
    /// <param name="tenant"></param>
    /// <returns></returns>
    public async Task <bool> SetTenantAsync(TKey identifier, TTenant tenant)
    {
        await _redisCacheService.CheckClientAndConnectIfNotAsync();

        if (_redisCacheService.IsConnected())
        {
            return(await _redisCacheService.SetAsync(identifier.ToString(), tenant).ConfigureAwait(false));
        }
        else
        {
            return(false);
        }
    }
Exemplo n.º 6
0
        public async Task <string> GetAllUser()
        {
            try
            {
                throw new Exception("测试错误!");
            }
            catch (Exception ex)
            {
                log.Error("GetAllUser方法错误", ex);
            }

            bool b = await _redisCache.SetAsync <string>("test", "测试");

            var users = await _userRepository.GetAllListAsync();

            var dtos = AutoMapper.Mapper.Map <IEnumerable <UserDto> >(users);

            return(Common.JsonHelper.SerializeObject(dtos));
        }
            /// <summary>
            ///  In memory check
            /// </summary>
            /// <param name="authId"></param>
            /// <param name="companyId"></param>
            /// <returns></returns>
            private async Task <bool> SpInMemoryCallToCheck(Guid authId, Guid companyId)
            {
                // "AuthIdAsKey" -> authId
                if (!_redisCacheService.TryGetValue(authId.ToString(), out IEnumerable <AuthCompanyDto> values)) //try get auth companies
                {
                    values = await _efCoreService.FetchCompanies(authId);

                    //cache it for 60 sec
                    await _redisCacheService.SetAsync(authId.ToString(), values, 60);


                    var authCachedRecord =
                        await _redisCacheService.GetAsync <IEnumerable <AuthCompanyDto> >(authId.ToString());

                    authCachedRecord = authCachedRecord.Where(x => x.Id == companyId);

                    if (!authCachedRecord.Any())
                    {
                        return(false);
                    }

                    return(true);
                }
                else
                {
                    var authCachedRecord =
                        await _redisCacheService.GetAsync <IEnumerable <AuthCompanyDto> >(authId.ToString());

                    authCachedRecord = authCachedRecord.Where(x => x.Id == companyId);

                    if (!authCachedRecord.Any())
                    {
                        return(false);
                    }

                    return(true);
                }
            }