public virtual async Task <IActionResult> Delete(int id) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageTopics)) { return(AccessDeniedView()); } //try to get a topic with the specified id var topic = await _topicService.GetTopicByIdAsync(id); if (topic == null) { return(RedirectToAction("List")); } await _topicService.DeleteTopicAsync(topic); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.ContentManagement.Topics.Deleted")); //activity log await _customerActivityService.InsertActivityAsync("DeleteTopic", string.Format(await _localizationService.GetResourceAsync("ActivityLog.DeleteTopic"), topic.Title ?? topic.SystemName), topic); return(RedirectToAction("List")); }
public async Task <ActionResult <ResponseTopicDto> > DeleteTopicAsync(Guid boardId, Guid topicId, [FromHeader(Name = "Accept")] string mediaType) { if (!MediaTypeHeaderValue.TryParse(mediaType, out MediaTypeHeaderValue parsedMediaType)) { return(BadRequest()); } if (!await _topicService.TopicExistsAsync(topicId)) { return(NotFound()); } var topicDto = await _topicService.GetTopicAsync(boardId, topicId); if (topicDto == null) { return(NoContent()); } var deletedTopicDto = await _topicService.DeleteTopicAsync(boardId, topicDto); var includeLinks = parsedMediaType.SubTypeWithoutSuffix.EndsWith("hateoas", StringComparison.InvariantCultureIgnoreCase); if (includeLinks) { IEnumerable <LinkDto> links = new List <LinkDto>(); links = CreateTopicLinks(deletedTopicDto.BoardId, deletedTopicDto.Id); var topicWithLinks = _mapper.Map <ResponseTopicLinksDto>(deletedTopicDto); topicWithLinks.Links = links; return(Ok(topicWithLinks)); } return(Ok(deletedTopicDto)); }
private async Task DeleteTopicAsync() { try { Console.Write("Enter topic name: "); var topicName = Console.ReadLine(); await _topicService.DeleteTopicAsync(topicName); Console.WriteLine($"Deleted topic '{topicName}' successfully."); } catch (Exception e) { Console.ForegroundColor = ErrorForegroundColor; Console.WriteLine(e); Console.ForegroundColor = ForegroundColor; } }
public async Task <IActionResult> DeleteTopic(int id) { if (id <= 0) { return(Error(HttpStatusCode.BadRequest, "id", "invalid id")); } var topicToDelete = await _topicService.GetTopicByIdAsync(id); if (topicToDelete == null) { return(Error(HttpStatusCode.NotFound, "topic", "not found")); } await _topicService.DeleteTopicAsync(topicToDelete); //activity log await CustomerActivityService.InsertActivityAsync("DeleteTopic", await LocalizationService.GetResourceAsync("ActivityLog.DeleteTopic"), topicToDelete); return(Json(new { status = "ok" })); }