示例#1
0
        /// <summary>
        /// 删除短网址
        /// </summary>
        /// <param name="alias">短网址别名</param>
        public void Delete(string alias)
        {
            if (string.IsNullOrEmpty(alias))
            {
                return;
            }

            ShortUrlEntity entity = shortUrlRepository.Get(alias);

            if (entity != null)
            {
                EventBus <ShortUrlEntity> .Instance().OnBefore(entity, new CommonEventArgs(EventOperationType.Instance().Delete()));

                shortUrlRepository.Delete(entity);
                EventBus <ShortUrlEntity> .Instance().OnAfter(entity, new CommonEventArgs(EventOperationType.Instance().Delete()));
            }
        }
示例#2
0
        public async Task <IActionResult> Delete(int id)
        {
            var shortUrl = await _shortUrlRepository.FindById(id);

            if (shortUrl == null)
            {
                return(BadRequest());
            }

            var success = await _shortUrlRepository.Delete(shortUrl);

            if (!success)
            {
                return(BadRequest());
            }

            return(NoContent());
        }
示例#3
0
        private async Task DeleteShortUrl(ShortUrl shortUrl, CancellationToken cancellationToken = default(CancellationToken))
        {
            var result = await _shortUrlRepository.Delete(shortUrl.Id, cancellationToken);

            Check.That <ApplicationException>(!result, "Something went wrong.");
        }