Пример #1
0
        /// <summary>
        /// Generateurls the specified URL.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <returns>IActionResult.</returns>
        public IActionResult generateurl(PageURL url)
        {
            ModelState.Clear();

            var _allKeys = _localCache.Get <AllPageUrls>("AllKeys");

            if (_allKeys == null)
            {
                _allKeys = new AllPageUrls()
                {
                    Id = Guid.NewGuid(), AllUrls = new List <PageURL>()
                };
            }
            else if (_allKeys.AllUrls == null)
            {
                _allKeys.AllUrls = new List <PageURL>();
            }

            var rtn = new PageURL()
            {
                Id = Guid.NewGuid(), FullURL = url.FullURL, ShortURL = Shortener.GetHash(url.FullURL)
            };

            _localCache.Set(rtn.ShortURL.ToString(), url.FullURL, TimeSpan.FromHours(24));

            _allKeys.AllUrls.Add(rtn);


            _localCache.Set("AllKeys", _allKeys, TimeSpan.FromHours(24));

            PersistentStore.Store(_localCache, _persistentStore, _allrepository, _repository);

            return(View("ShortenURL", rtn));
        }