public IActionResult Delete(string userId) { List <SavedUser> yourUsers = _context.SavedUsers.Where(x => x.Employer == User.FindFirst(ClaimTypes.NameIdentifier).Value).ToList(); yourUsers = yourUsers.Where(x => x.JobSeeker == userId).ToList(); foreach (SavedUser u in yourUsers) { _context.Remove(u); } _context.SaveChanges(); return(RedirectToAction("Index")); }
// Returns View : confirms that you saved your skills to the current user // Action: Saves checked off skills into the UserSkills table // Routed Data : list of integers representing skill ids from Skills table public IActionResult AddSkills(List <int> skillId) { // Check if skill ids aren't empty if (skillId.Count != 0) { // Get all existing skills current user already has var check = _context.UserSkills.Where(x => x.UserId == User.FindFirst(ClaimTypes.NameIdentifier).Value); foreach (int i in skillId) { // Avoid adding duplicates by checking if check skill ids exists within the current user if (check.Where(x => x.SkillId == i).ToList().Count <= 0) { UserSkill s = new UserSkill(); s.UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value; s.SkillId = i; _context.UserSkills.Add(s); } } } // Check if skill is unchecked, if it is unchecked but skill is in UserSkills table, remove it var check2 = _context.UserSkills.Where(x => x.UserId == User.FindFirst(ClaimTypes.NameIdentifier).Value).ToList(); foreach (UserSkill u in check2) { // If you cannot find skill in UserSkills table, remove it if (skillId.IndexOf((int)u.SkillId) == -1) { _context.UserSkills.Remove(u); Skill s = _context.Skills.Where(x => x.Id == u.SkillId).ToList()[0]; if (s.Vote < 5 && s.Vote > 0) { s.Vote--; if (s.Vote == 0) { _context.Remove(s); } _context.SaveChanges(); } } } _context.SaveChanges(); return(View()); }