public ActionResult SetTag(int id, int tid)//checked { var solution = DbContext.Solutions.Find(id); var contest = solution.Problem.Contest; var user = (Entity.User)ViewBag.CurrentUser; if (solution.ID != user.ID && !IsMaster(contest.ID)) { return(Content("Failed")); } var tags = solution.SolutionTags.Where(x => x.AlgorithmTagID == tid).ToList(); if (tags.Count == 0) { var tag = new SolutionTag { AlgorithmTagID = tid, SolutionID = id }; DbContext.SolutionTags.Add(tag); DbContext.SaveChanges(); return(Content("Added")); } else { foreach (var tag in tags) { DbContext.SolutionTags.Remove(tag); } DbContext.SaveChanges(); return(Content("Deleted")); } }
public ActionResult SetTag(int id, int tid) { var solution = DbContext.Solutions.Find(id); if (solution.Problem.Hide && (CurrentUser == null || (CurrentUser.ID != solution.UserID && CurrentUser.ID != solution.Problem.UserID && !IsMaster()))) { return(Content("Failed")); } var tags = solution.SolutionTags.Where(x => x.AlgorithmTagID == tid).ToList(); if (tags.Count == 0) { var tag = new SolutionTag { AlgorithmTagID = tid, SolutionID = id }; DbContext.SolutionTags.Add(tag); DbContext.SaveChanges(); return(Content("Added")); } else { foreach (var tag in tags) { DbContext.SolutionTags.Remove(tag); } DbContext.SaveChanges(); return(Content("Deleted")); } }