public async Task DeleteAsync(DeleteForum command) { var forum = await _dbContext.Forums .FirstOrDefaultAsync(x => x.Category.SiteId == command.SiteId && x.Id == command.Id && x.Status != ForumStatusType.Deleted); if (forum == null) { throw new DataException($"Forum with Id {command.Id} not found."); } forum.Delete(); _dbContext.Events.Add(new Event(command.SiteId, command.UserId, EventType.Deleted, typeof(Forum), forum.Id)); await ReorderForumsInCategory(forum.CategoryId, command.Id, command.SiteId, command.UserId); await _dbContext.SaveChangesAsync(); _cacheManager.Remove(CacheKeys.Forum(forum.Id)); _cacheManager.Remove(CacheKeys.Categories(command.SiteId)); _cacheManager.Remove(CacheKeys.CurrentForums(command.SiteId)); }
public async Task <ActionResult> Delete(Guid id) { var site = await _contextService.CurrentSiteAsync(); var user = await _contextService.CurrentUserAsync(); var command = new DeleteForum { Id = id, SiteId = site.Id, UserId = user.Id }; await _forumService.DeleteAsync(command); return(Ok()); }