public async Task DeleteOrderItemsByOrderId(int orderId) { var items = this.GetOrderItemsByOrderId(orderId); foreach (var item in items) { var orderItem = GetOrderItemById(item.Id); orderItemRepository.Delete(orderItem); } await orderItemRepository.SaveChangesAsync(); }
public async Task EditAsync(ParentModifyInputModel modifiedModel) { var parent = _parentsRepository.All().FirstOrDefault(p => p.Id == modifiedModel.Id); if (parent != null) { var studentIds = modifiedModel.Parent.StudentIds.Select(int.Parse).ToList(); if (!studentIds.Any()) // Make sure parent has student children { throw new ArgumentException($"Sorry, it's mandatory for a parent user to have at least 1 student"); } if (HasDifferentStudentIds(parent, studentIds) && studentIds.Any()) { var students = _studentsRepository.All().Where(s => studentIds.Contains(s.Id)); // Remove all pairs that are no longer valid foreach (var studentParent in parent.StudentParents.Where(sp => !studentIds.Contains(sp.StudentId))) { _studentParentsMappingRepository.Delete(studentParent); } foreach (var studentId in studentIds.Where(sid => !parent.StudentParents.Select(sp => sp.StudentId).Contains(sid))) { var student = _studentsRepository.All().FirstOrDefault(s => s.Id == studentId); if (student != null) { var studentParentPair = new StudentParent { Student = student, Parent = parent }; await _studentParentsMappingRepository.AddAsync(studentParentPair); } } await _studentParentsMappingRepository.SaveChangesAsync(); } parent.FirstName = modifiedModel.Parent.FirstName; parent.LastName = modifiedModel.Parent.LastName; parent.PhoneNumber = modifiedModel.Parent.PhoneNumber; _parentsRepository.Update(parent); await _parentsRepository.SaveChangesAsync(); } }
public bool DeleteById(int id) { var entity = sportCentersDb.All().FirstOrDefault(x => x.Id == id); var categories = this.categoriesDb.All(); if (entity == null) { return(false); } foreach (var category in categories) { if (category.SportCenters.Any(x => x.Id == entity.Id)) { var itemToRemove = category.SportCenters.FirstOrDefault(x => x.Id == entity.Id); category.SportCenters.Remove(itemToRemove); } } sportCentersDb.Delete(id); sportCentersDb.SaveChanges(); return(true); }
public async Task <bool> DeleteByIdAsync(string id) { var video = await videoRepository.All() .Include(v => v.Comments) .Include(v => v.Ratings) .SingleOrDefaultAsync(v => v.Id == id); if (video == null) { return(false); } foreach (var rate in video.Ratings) { await rateService.DeleteByIdAsync(rate.Id); } foreach (var comment in video.Comments) { await commentSerivce.DeleteByIdAsync(comment.Id); } videoRepository.Delete(video); var result = await videoRepository.SaveChangesAsync(); return(result > 0); }
public async Task DeleteAsync(int id) { var product = await productRepository.All().FirstAsync(x => x.Id == id); productRepository.Delete(product); await productRepository.SaveChangesAsync(); }
public async Task <bool> BanByUsernameAsync(string username) { var user = await userRepository.All() .Include(u => u.Uploads) .Include(u => u.Ratings) .Include(u => u.Comments) .SingleOrDefaultAsync(u => u.UserName == username); if (user == null) { return(false); } foreach (var rate in user.Ratings) { await rateService.DeleteByIdAsync(rate.Id); } foreach (var comment in user.Comments) { await commentSerivce.DeleteByIdAsync(comment.Id); } foreach (var video in user.Uploads) { await videoService.DeleteByIdAsync(video.Id); } userRepository.Delete(user); await userRepository.SaveChangesAsync(); return(true); }
public async Task DeleteAsync(int id) { var student = _studentsRepository.All().FirstOrDefault(s => s.Id == id); if (student != null) { var parentIds = student.StudentParents.Select(sp => sp.ParentId).ToList(); foreach (var parentId in parentIds) { var parent = _parentRepository.All().FirstOrDefault(p => p.Id == parentId); var parentStudentsCount = parent?.StudentParents.Count; if (parentStudentsCount == 1) // delete parent if current student is their only child with active account { _parentRepository.Delete(parent); await _parentRepository.SaveChangesAsync(); } var mapping = _studentParentsMappingRepository.All() .FirstOrDefault(sp => sp.StudentId == id && sp.ParentId == parentId); _studentParentsMappingRepository.Delete(mapping); } await _studentParentsMappingRepository.SaveChangesAsync(); // ToDo: Decide if StudentSubject should be handled here as well _studentsRepository.Delete(student); await _studentsRepository.SaveChangesAsync(); } }
public async Task DeleteAsync(int id) { var absence = _absencesRepository.All().FirstOrDefault(a => a.Id == id); if (absence != null) { _absencesRepository.Delete(absence); await _absencesRepository.SaveChangesAsync(); } }
public async Task DeleteAsync(int id) { var comment = _commentsRepository.All().FirstOrDefault(c => c.Id == id); if (comment != null) { _commentsRepository.Delete(comment); await _commentsRepository.SaveChangesAsync(); } }
public async Task RemoveReservation(int id) { var item = reservationRepository.All().FirstOrDefault(x => x.Id == id); if (item != null) { reservationRepository.Delete(item); await reservationRepository.SaveChangesAsync(); } }
public async Task DeleteAsync(int skillId) { var skill = _skillsRepository.All().FirstOrDefault(e => e.Id == skillId); if (skill != null) { _skillsRepository.Delete(skill); await _skillsRepository.SaveChangesAsync(); } }
public async Task DeleteAsync(int id) { var grade = _gradesRepository.All().FirstOrDefault(g => g.Id == id); if (grade != null) { _gradesRepository.Delete(grade); await _gradesRepository.SaveChangesAsync(); } }
public async Task DeleteCategory(int id) { var category = new Category { Id = id, }; categoryRepository.Delete(category); await categoryRepository.SaveChangesAsync(); }
public async Task DeleteAsync(int experienceId) { var experience = _experienceRepository.All().FirstOrDefault(e => e.Id == experienceId); if (experience != null) { _experienceRepository.Delete(experience); await _experienceRepository.SaveChangesAsync(); } }
public async Task DeleteAsync(int educationId) { var education = _educationEntityRepository.All().FirstOrDefault(e => e.Id == educationId); if (education != null) { _educationEntityRepository.Delete(education); await _educationEntityRepository.SaveChangesAsync(); } }
public async Task DeleteOrder(int orderId) { var order = await this.GetOrderByIdAsync(orderId); await orderItemService.DeleteOrderItemsByOrderId(orderId); orderRepository.Delete(order); await orderItemRepository.SaveChangesAsync(); }
public async Task Delete(int id) { var review = await reviewsRepository.GetByIdWithDeletedAsync(id); if (review == null) { throw new InvalidOperationException("The review could not be found"); } reviewsRepository.Delete(review); await reviewsRepository.SaveChangesAsync(); }
public async Task Delete(int id) { var genre = await genresRepository.GetByIdWithDeletedAsync(id); if (genre == null) { throw new InvalidOperationException("The genre could not be found"); } genresRepository.Delete(genre); await genresRepository.SaveChangesAsync(); }
public async Task DeleteAsync(int id) { var teacher = _teachersRepository.All().FirstOrDefault(s => s.Id == id); if (teacher != null) { if (teacher.Class != null) { throw new ArgumentException($"Sorry, we cannot delete a teacher that is currently leading a class. Please first assign another lead teacher for the class."); } _teachersRepository.Delete(teacher); await _teachersRepository.SaveChangesAsync(); } }
public async Task <bool> DeleteByIdAsync(string id) { if (id == null) { return(false); } var rate = await repository.GetByIdAsync(id); if (rate == null) { return(false); } repository.Delete(rate); var result = await repository.SaveChangesAsync(); return(result > 0); }
public async Task DeleteAsync(int id) { var parent = _parentsRepository.All().FirstOrDefault(p => p.Id == id); if (parent != null) { foreach (var studentPair in parent.StudentParents) { _studentParentsMappingRepository.Delete(studentPair); } await _studentParentsMappingRepository.SaveChangesAsync(); _parentsRepository.Delete(parent); await _parentsRepository.SaveChangesAsync(); } }
public async Task ChangeIsDelete(string email) { var user = _usersRepository.AllWithDeleted().FirstOrDefault(u => u.Email == email); if (user != null) { if (user.IsDeleted) { _usersRepository.Undelete(user); } else { _usersRepository.Delete(user); } await _usersRepository.SaveChangesAsync(); } }
public async Task DeleteAsync(int id) { var school = _schoolsRepository.All().FirstOrDefault(s => s.Id == id); if (school != null) { var allPeopleConnectedToSchoolUniqueIds = new List <string>(); allPeopleConnectedToSchoolUniqueIds.AddRange(school.Teachers.Select(t => t.UniqueId).ToList()); allPeopleConnectedToSchoolUniqueIds.AddRange(school.Students.Select(s => s.UniqueId).ToList()); allPeopleConnectedToSchoolUniqueIds.Add(school.Principal.UniqueId); foreach (var userUniqueId in allPeopleConnectedToSchoolUniqueIds) { await _usersService.DeleteByUniqueIdAsync(userUniqueId); } // ToDo: Add logic for classes deletion, then the logic for students above would be obsolete _schoolsRepository.Delete(school); await _schoolsRepository.SaveChangesAsync(); } }
public async Task DeleteAsync(int id) { var subject = _subjectsRepository.All().FirstOrDefault(s => s.Id == id); if (subject != null) { if (subject.StudentSubjects.Any()) { var allStudentsForSubject = _studentSubjectRepository.All().Where(s => s.SubjectId == id); foreach (var studentSubjectPair in allStudentsForSubject) { _studentSubjectRepository.Delete(studentSubjectPair); // ToDo: Decide if grades/absences delete behaviour should be handled here as well } await _studentSubjectRepository.SaveChangesAsync(); } _subjectsRepository.Delete(subject); await _subjectsRepository.SaveChangesAsync(); } }
public bool Delete(int id) { var model = addressesDb.GetById(id); if (model == null) { return(false); } var centers = addressesDb.GetById(id).SportCenters; foreach (var center in centers) { sportCenterService.DeleteById(center.Id); } addressesDb.Delete(model); addressesDb.SaveChanges(); return(true); }
public async Task DeleteByUniqueIdAsync(string uniqueId) { if (!string.IsNullOrEmpty(uniqueId)) { switch (uniqueId[0]) { case GlobalConstants.PrincipalIdPrefix: var principalRecord = _principalsRepository.All().FirstOrDefault(p => p.UniqueId == uniqueId); _principalsRepository.Delete(principalRecord); await _principalsRepository.SaveChangesAsync(); await DeleteApplicationUserByUniqueId(uniqueId); break; case GlobalConstants.TeacherIdPrefix: var teacherRecord = _teachersRepository.All().FirstOrDefault(p => p.UniqueId == uniqueId); _teachersRepository.Delete(teacherRecord); await _teachersRepository.SaveChangesAsync(); await DeleteApplicationUserByUniqueId(uniqueId); break; case GlobalConstants.StudentIdPrefix: var studentRecord = _studentsRepository.All().FirstOrDefault(p => p.UniqueId == uniqueId); _studentsRepository.Delete(studentRecord); await _studentsRepository.SaveChangesAsync(); await DeleteApplicationUserByUniqueId(uniqueId); break; case GlobalConstants.ParentIdPrefix: var parentRecord = _parentsRepository.All().FirstOrDefault(p => p.UniqueId == uniqueId); _parentsRepository.Delete(parentRecord); await _parentsRepository.SaveChangesAsync(); await DeleteApplicationUserByUniqueId(uniqueId); break; } } }
public async Task DeleteAsync(int id) { var schoolClass = _classesRepository.All().FirstOrDefault(c => c.Id == id); if (schoolClass != null) { var students = schoolClass.Students; foreach (var student in students) { _studentRepository.Delete(student); } await _studentRepository.SaveChangesAsync(); schoolClass.Teacher = null; schoolClass.TeacherId = null; _classesRepository.Update(schoolClass); _classesRepository.Delete(schoolClass); await _classesRepository.SaveChangesAsync(); await _teachersRepository.SaveChangesAsync(); } }
public bool DeleteById(int id) { var entity = sportCategoriesDb.All().FirstOrDefault(x => x.Id == id); if (entity == null) { return(false); } var centers = sportCentesDb.All(); foreach (var center in centers) { var categoriesToRemove = new List <SportCategory>(); foreach (var category in center.Categories) { if (category.Name == entity.Name) { categoriesToRemove.Add(category); } } foreach (var category in categoriesToRemove) { if (center.Categories.Any(x => x.Name == category.Name)) { center.Categories.Remove(category); } } } sportCategoriesDb.Delete(id); sportCategoriesDb.SaveChanges(); return(true); }
public async Task Delete(int id) { Subject subject = repository.All().Where(x => x.Id == id).FirstOrDefault(); repository.Delete(subject); }
public async Task <int> Delete(int id) { _catalogItemsRepository.Delete(id); return(await this._catalogItemsRepository.SaveChangesAsync()); }