/// <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())); } }
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()); }
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."); }