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