public ActionResult Remove(int topicID) { Topic topicToRemove = topicRepository.TopicsRepository .Where(e => e.TitleID == topicID).FirstOrDefault(); if (topicToRemove != null) { topicRepository.Delete(topicToRemove); return(RedirectToAction("Index")); } else { return(View("Błąd", "Nie rozpoznano tematu!")); } }
/// <summary> /// Delete a topic /// </summary> public void deleteTopics() { foreach (Topic topic in TopicRepository.All()) { TopicRepository.Delete(topic); } }
public void DeleteUser(User user) { if (user == null) { throw new ArgumentNullException(); } var userToDelete = GetUserById(user.UserId); if (userToDelete == null) { throw new ArgumentException ($"User with Id = {user.UserId} does not exists"); } profileRepository.Delete(userToDelete.User_additional_info); foreach (var message in userToDelete.Messages.ToList()) { messageRepository.Delete(message); } foreach (var topic in userToDelete.Topics.ToList()) { topicRepository.Delete(topic); } foreach (var moderatingQuery in userToDelete.SectionModerators.ToList()) { sectionModeratorsRepository.Delete(moderatingQuery); } ctx.Set <User>().Remove(userToDelete); ctx.SaveChanges(); }
public void Delete(Section section) { if (section == null) { throw new ArgumentNullException(); } var sectionToDelete = GetById(section.SectionId); if (sectionToDelete == null) { throw new ArgumentException ($"Section with Id = {section.SectionId} does not exists"); } foreach (var topic in sectionToDelete.Topics.ToList()) { topicRepository.Delete(topic); } foreach (var entry in sectionToDelete.SectionModerators.ToList()) { sectionModeratorsRepository.Delete(entry); } ctx.Set <Section>().Remove(sectionToDelete); ctx.SaveChanges(); }
public IActionResult Delete(int[] topics) { /*------------------------------------------------------------------------------------------------------------------------ | Validate input \-----------------------------------------------------------------------------------------------------------------------*/ Contract.Requires(topics, nameof(topics)); /*------------------------------------------------------------------------------------------------------------------------ | Delete topics \-----------------------------------------------------------------------------------------------------------------------*/ foreach (var topicId in topics) { if (topicId < 0) { continue; } var topic = _topicRepository.Load(topicId); if (!topic.GetUniqueKey().StartsWith(_invoiceRoot, StringComparison.InvariantCultureIgnoreCase)) { continue; } _topicRepository.Delete(topic); } /*------------------------------------------------------------------------------------------------------------------------ | Return default view \-----------------------------------------------------------------------------------------------------------------------*/ return RedirectToAction(nameof(Index)); }
/// <summary> /// Delete a topic /// </summary> /// <param name="topic"></param> public void Delete(Topic topic) { topic.LastPost = null; topic.Tags.Clear(); // Delete all posts if (topic.Posts != null) { var postsToDelete = new List <Post>(); postsToDelete.AddRange(topic.Posts); foreach (var post in postsToDelete) { _postRepository.Delete(post); } } if (topic.TopicNotifications != null) { var notificationsToDelete = new List <TopicNotification>(); notificationsToDelete.AddRange(topic.TopicNotifications); foreach (var topicNotification in notificationsToDelete) { _topicNotificationService.Delete(topicNotification); } } _topicRepository.Delete(topic); }
private void removeRecursive(Section section) { if (section.ChildSections != null) { while (section.ChildSections.Any()) { removeRecursive(section.ChildSections.First()); } } if (section.Topics != null) { while (section.Topics.Any()) { var topic = section.Topics.First(); if (topic.Messages != null) { while (topic.Messages.Any()) { _messageRepository.Delete(topic.Messages.First().Id); } } _topicRepository.Delete(topic.Id); } } _sectionRepository.Delete(section.Id); }
public async Task <IActionResult> Delete(int id) { var location = GetControllerActionNames(); try { _logger.LogInfo(LogMessages.AttemptedToDelete(location, id)); if (id < 1) { _logger.LogWarn(LogMessages.BadData(location, id)); return(BadRequest()); } var isExists = await _topicRepository.IsExists(id); if (!isExists) { _logger.LogWarn(LogMessages.NotFound(location, id)); return(NotFound()); } var topic = await _topicRepository.FindById(id); var isSuccess = await _topicRepository.Delete(topic); if (!isSuccess) { return(InternalError(LogMessages.DeleteFailed(location, id))); } _logger.LogInfo(LogMessages.Success(location, id)); return(NoContent()); } catch (Exception e) { return(InternalError(LogMessages.InternalError(location, e.Message, e.InnerException))); } }
public IActionResult Delete(int id) { var topic = _topic.GetById(id); topic.Type = TopicType.Delete; _topic.Delete(topic); return(RedirectToAction("index", "user")); }
public ActionResult DeleteConfirmed(int?id) { Topic s = new Topic { TopicId = id.Value }; repository.Delete(s); return(RedirectToRoute(new { controller = "Section", Action = "Index" })); }
public void Delete(long id) { var topic = _repository.GetById(id); if (topic != null) { _repository.Delete(topic); _repository.Save(); return; } throw new KeyNotFoundException(); }
public void DeleteTopic(int id) { try { topicRepository.Delete(id); } catch (InvalidOperationException e) { logger.Warn(e.Message); throw; } }
public void Delete_Topic_Removed() { var parent = _topicRepository.Load("Root:Web:Web_1"); var topic = _topicRepository.Load("Root:Web:Web_1:Web_1_1"); var child = _topicRepository.Load("Root:Web:Web_1:Web_1_1:Web_1_1_0"); Assert.AreEqual<int>(2, parent.Children.Count); _topicRepository.Delete(topic, true); Assert.AreEqual<int>(1, parent.Children.Count); }
public async Task <IActionResult> DeleteTopic(int topicId) { var toDelete = await _topicRepository.GetById(topicId); if (!ExistsAndAllowedToUse(toDelete)) { return(NotFound()); } await _topicRepository.Delete(toDelete); return(RedirectToAction(nameof(Subject), new { subjectId = toDelete.SubjectId })); }
public ActionResult <Topic> Delete(Guid id) { var resultValidation = new TopicExistValidator().Validate(id); if (!resultValidation.IsValid) { return(BadRequest(resultValidation.Errors)); } Topic topic = topicRepository.GetById(id); return(Ok(topicRepository.Delete(topic))); }
public async Task <IActionResult> Delete(int id) { var topic = _repository.GetById(id); try { await _repository.Delete(topic); } catch { return(StatusCode(500)); } return(RedirectToAction(nameof(Index))); }
public MessageReport Delete(string _id) { var rp = new MessageReport(); try { var query = Builders <Topic> .Filter.Eq(e => e._id, _id); _ITopicRepository.Delete(query); rp.Success = true; rp.Message = "Xóa chủ đề thành công!"; } catch (Exception ex) { rp.Message = ex.Message; } return(rp); }
public void Remove(int id) { var topic = _topicRepository.FindById(id); if (topic == null) { throw new NullReferenceException(); } if (topic.Messages != null) { while (topic.Messages.Any()) { _messageRepository.Delete(topic.Messages.First().Id); } } _topicRepository.Delete(topic.Id); _provider.SaveChanges(); }
public ServiceResult <TopicServiceResultCode> DeleteTopic(Guid topicId) { if (topicId == Guid.Empty) { return(ArgumentErrorResult(TopicServiceResultCode.ArgumentError)); } try { var targetTopic = _topicRepo.Get(topicId); if (targetTopic == null) { return(DataErrorResult(TopicServiceResultCode.DataNotExist)); } _topicRepo.Delete(targetTopic); return(BuildResult(true, TopicServiceResultCode.Success)); } catch (Exception ex) { _systemErrorsRepo.AddLog(ex); return(InternalErrorResult(TopicServiceResultCode.BackendException)); } }
/// <summary> /// 删除专题 /// </summary> /// <param name="groupId">专题Id</param> public void Delete(long groupId) { //设计要点 //1、需要删除:专题成员、专题申请、Logo; TopicEntity group = groupRepository.Get(groupId); if (group == null) { return; } CategoryService categoryService = new CategoryService(); categoryService.ClearCategoriesFromItem(groupId, null, TenantTypeIds.Instance().Topic()); EventBus <TopicEntity> .Instance().OnBefore(group, new CommonEventArgs(EventOperationType.Instance().Delete())); int affectCount = groupRepository.Delete(group); if (affectCount > 0) { //删除访客记录 new VisitService(TenantTypeIds.Instance().Topic()).CleanByToObjectId(groupId); //用户的创建专题数-1 OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(group.UserId, OwnerDataKeys.Instance().CreatedTopicCount(), -1); //删除Logo LogoService logoService = new LogoService(TenantTypeIds.Instance().Topic()); logoService.DeleteLogo(groupId); //删除专题下的成员 DeleteMembersByTopicId(groupId); EventBus <TopicEntity> .Instance().OnAfter(group, new CommonEventArgs(EventOperationType.Instance().Delete())); EventBus <TopicEntity, AuditEventArgs> .Instance().OnAfter(group, new AuditEventArgs(group.AuditStatus, null)); } }
public void ScrubUsers(MembershipUser user, IUnitOfWork unitOfWork) { // PROFILE user.Website = string.Empty; user.Twitter = string.Empty; user.Facebook = string.Empty; user.Avatar = string.Empty; user.Signature = string.Empty; // User Votes if (user.Votes != null) { var votesToDelete = new List <Vote>(); votesToDelete.AddRange(user.Votes); foreach (var d in votesToDelete) { _voteService.Delete(d); } user.Votes.Clear(); } // User Badges if (user.Badges != null) { var toDelete = new List <Badge>(); toDelete.AddRange(user.Badges); foreach (var obj in toDelete) { _badgeService.Delete(obj); } user.Badges.Clear(); } // User badge time checks if (user.BadgeTypesTimeLastChecked != null) { var toDelete = new List <BadgeTypeTimeLastChecked>(); toDelete.AddRange(user.BadgeTypesTimeLastChecked); foreach (var obj in toDelete) { _badgeService.DeleteTimeLastChecked(obj); } user.BadgeTypesTimeLastChecked.Clear(); } // User category notifications if (user.CategoryNotifications != null) { var toDelete = new List <CategoryNotification>(); toDelete.AddRange(user.CategoryNotifications); foreach (var obj in toDelete) { _categoryNotificationService.Delete(obj); } user.CategoryNotifications.Clear(); } // User PM Received var pmUpdate = false; if (user.PrivateMessagesReceived != null) { pmUpdate = true; var toDelete = new List <PrivateMessage>(); toDelete.AddRange(user.PrivateMessagesReceived); foreach (var obj in toDelete) { _privateMessageService.DeleteMessage(obj); } user.PrivateMessagesReceived.Clear(); } // User PM Sent if (user.PrivateMessagesSent != null) { pmUpdate = true; var toDelete = new List <PrivateMessage>(); toDelete.AddRange(user.PrivateMessagesSent); foreach (var obj in toDelete) { _privateMessageService.DeleteMessage(obj); } user.PrivateMessagesSent.Clear(); } if (pmUpdate) { unitOfWork.SaveChanges(); } // User Favourites if (user.Favourites != null) { var toDelete = new List <Favourite>(); toDelete.AddRange(user.Favourites); foreach (var obj in toDelete) { _favouriteRepository.Delete(obj); } user.Favourites.Clear(); } if (user.TopicNotifications != null) { var notificationsToDelete = new List <TopicNotification>(); notificationsToDelete.AddRange(user.TopicNotifications); foreach (var topicNotification in notificationsToDelete) { _topicNotificationService.Delete(topicNotification); } user.TopicNotifications.Clear(); } // Also clear their points var userPoints = user.Points; if (userPoints.Any()) { var pointsList = new List <MembershipUserPoints>(); pointsList.AddRange(userPoints); foreach (var point in pointsList) { point.User = null; _membershipUserPointsService.Delete(point); } user.Points.Clear(); } // Now clear all activities for this user var usersActivities = _activityService.GetDataFieldByGuid(user.Id); _activityService.Delete(usersActivities.ToList()); // Also clear their poll votes var userPollVotes = user.PollVotes; if (userPollVotes.Any()) { var pollList = new List <PollVote>(); pollList.AddRange(userPollVotes); foreach (var vote in pollList) { vote.User = null; _pollVoteRepository.Delete(vote); } user.PollVotes.Clear(); } unitOfWork.SaveChanges(); // Also clear their polls var userPolls = user.Polls; if (userPolls.Any()) { var polls = new List <Poll>(); polls.AddRange(userPolls); foreach (var poll in polls) { //Delete the poll answers var pollAnswers = poll.PollAnswers; if (pollAnswers.Any()) { var pollAnswersList = new List <PollAnswer>(); pollAnswersList.AddRange(pollAnswers); foreach (var answer in pollAnswersList) { answer.Poll = null; _pollAnswerRepository.Delete(answer); } } poll.PollAnswers.Clear(); poll.User = null; _pollRepository.Delete(poll); } user.Polls.Clear(); } unitOfWork.SaveChanges(); // ######### POSTS TOPICS ######## // Delete all topics first var topics = user.Topics; if (topics != null && topics.Any()) { var topicList = new List <Topic>(); topicList.AddRange(topics); foreach (var topic in topicList) { topic.LastPost = null; topic.Posts.Clear(); topic.Tags.Clear(); _topicRepository.Delete(topic); } user.Topics.Clear(); unitOfWork.SaveChanges(); } // Now sorts Last Posts on topics and delete all the users posts var posts = user.Posts; if (posts != null && posts.Any()) { var postIds = posts.Select(x => x.Id).ToList(); // Get all categories var allCategories = _categoryService.GetAll(); // Need to see if any of these are last posts on Topics // If so, need to swap out last post var lastPostTopics = _topicRepository.GetTopicsByLastPost(postIds, allCategories.ToList()); foreach (var topic in lastPostTopics.Where(x => x.User.Id != user.Id)) { var lastPost = topic.Posts.Where(x => !postIds.Contains(x.Id)).OrderByDescending(x => x.DateCreated).FirstOrDefault(); topic.LastPost = lastPost; } unitOfWork.SaveChanges(); user.UploadedFiles.Clear(); // Delete all posts var postList = new List <Post>(); postList.AddRange(posts); foreach (var post in postList) { if (post.Files != null) { var files = post.Files; var filesList = new List <UploadedFile>(); filesList.AddRange(files); foreach (var file in filesList) { // store the file path as we'll need it to delete on the file system var filePath = file.FilePath; // Now delete it _uploadedFileService.Delete(file); // And finally delete from the file system System.IO.File.Delete(HostingEnvironment.MapPath(filePath)); } post.Files.Clear(); } _postRepository.Delete(post); } user.Posts.Clear(); unitOfWork.SaveChanges(); } }
public Topic Delete(long id) { return(_topRepo.Delete(id)); }
public IHttpActionResult Delete(int id) { trepo.Delete(trepo.Get(id)); return(StatusCode(HttpStatusCode.NoContent)); }
public Topic Delete(Guid id) { return(topicRepository.Delete(id)); }
public void DeleteTopic(int id) { var Topic = TopicRepository.GetById(id); TopicRepository.Delete(Topic); }
/*========================================================================================================================== | METHOD: DELETE \-------------------------------------------------------------------------------------------------------------------------*/ /// <inheritdoc /> public override void Delete(Topic topic, bool isRecursive = true) => _dataProvider.Delete(topic, isRecursive);
public bool Delete(string topicId) { return(_topicRepository.Delete(topicId)); }
public void Delete(Topic topic) { _topicRepository.Delete(topic); }