コード例 #1
0
        public ActionResult Delete(int LabelId)
        {
            LabelProfile label = _context.LabelProfiles.FirstOrDefault(x => x.Id == LabelId);

            label.IsDelete = true;
            _context.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
コード例 #2
0
        public IActionResult Change(LabelProfile labelProfile)
        {
            LabelProfile label = _context.LabelProfiles.FirstOrDefault(x => x.Id == labelProfile.Id);

            label.Introduction = labelProfile.Introduction;
            label.Name         = labelProfile.Name;
            _context.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
コード例 #3
0
        public IActionResult Change(long?id)
        {
            if (id == null)
            {
                return(RedirectToAction(nameof(Index)));
            }
            LabelProfile label = _context.LabelProfiles.FirstOrDefault(x => x.Id == id);

            return(View(label));
        }
コード例 #4
0
        public IActionResult New(NewViewModel model)
        {
            LabelProfile label = new LabelProfile();

            label.Introduction = model.Introduction;
            label.Name         = model.Name;
            label.IsDelete     = false;
            _context.LabelProfiles.Add(label);
            _context.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
コード例 #5
0
        /// <summary>
        /// 展示所有的题目
        /// </summary>
        /// <returns></returns>
        public IActionResult Index(int page = 0)
        {
            var user = HttpContext.Session.Get <UserProfileModel>("CurrentUser");
            // 将题目和他的标签查询出来
            List <ProblemAndHisLabel> problemAndHisLabels = new List <ProblemAndHisLabel>();

            foreach (var item in _context.Problems.Where(x => x.IsDelete == false).Skip(page * PageSize).Take(PageSize).ToList())
            {
                ProblemAndHisLabel problemAndHisLabel = new ProblemAndHisLabel();
                problemAndHisLabel.problem = item;

                if (user != null)
                {
                    var issolve = _context.Tracks.FirstOrDefault(x => x.ProblemId == item.Id && x.SubmitterId == user.Id.ToString());
                    if (issolve == null)
                    {
                        problemAndHisLabel.IsSolved = false;
                    }
                    else
                    {
                        problemAndHisLabel.IsSolved = true;
                    }
                }
                else
                {
                    problemAndHisLabel.IsSolved = false;
                }


                // 去查每一个题目的标签
                List <LabelProfile> labelProfiles = new List <LabelProfile>();
                foreach (var ProblemLabelitem in _context.ProblemLabels.Where(x => x.ProblemId == item.Id.ToString()).ToList())
                {
                    LabelProfile labelProfile = _context.LabelProfiles.FirstOrDefault(x => x.Id == long.Parse(ProblemLabelitem.LabelId));
                    labelProfiles.Add(labelProfile);
                }
                problemAndHisLabel.labelProfiles = labelProfiles;
                problemAndHisLabels.Add(problemAndHisLabel);
            }

            //获得所有标签
            List <LabelProfile> AllLables = _context.LabelProfiles.ToList();


            IndexViewModel model = new IndexViewModel
            {
                ProblemModels = problemAndHisLabels,
                AllLables     = AllLables,
                Page          = page
            };

            return(View(model));
        }
コード例 #6
0
        public IActionResult ChangeProblem(int page = 0)
        {
            var user = HttpContext.Session.Get <UserProfileModel>("CurrentUser");

            if (user == null)
            {
                TempData["Message"] = "请先登录";
                return(RedirectToAction("Login", "Auth"));
            }
            // 将题目和他的标签查询出来
            List <ProblemAndHisLabel> problemAndHisLabels = new List <ProblemAndHisLabel>();

            foreach (var item in _context.Problems.Where(x => x.IsDelete == false).Skip(page * PageSize).Take(PageSize).ToList())
            {
                ProblemAndHisLabel problemAndHisLabel = new ProblemAndHisLabel();
                problemAndHisLabel.problem = item;
                // 去查每一个题目的标签
                List <LabelProfile> labelProfiles = new List <LabelProfile>();
                foreach (var ProblemLabelitem in _context.ProblemLabels.Where(x => x.ProblemId == item.Id.ToString()).ToList())
                {
                    LabelProfile labelProfile = _context.LabelProfiles.FirstOrDefault(x => x.Id == long.Parse(ProblemLabelitem.LabelId));
                    labelProfiles.Add(labelProfile);
                }
                problemAndHisLabel.labelProfiles = labelProfiles;
                problemAndHisLabels.Add(problemAndHisLabel);
            }

            //获得所有标签
            List <LabelProfile> AllLables = _context.LabelProfiles.ToList();


            IndexViewModel model = new IndexViewModel
            {
                ProblemModels = problemAndHisLabels,
                AllLables     = AllLables,
                Page          = page
            };

            return(View(model));
        }
コード例 #7
0
        public IActionResult Recommend(int page = 0)
        {
            var user = HttpContext.Session.Get <UserProfileModel>("CurrentUser");

            if (user == null)
            {
                TempData["Message"] = "请先登录";
                return(RedirectToAction("Login", "Auth"));
            }
            List <RecommendProblem> recommendProblems = new List <RecommendProblem>();

            foreach (var item in _context.Problems.Where(x => x.IsDelete == false).ToList())
            {
                int weight = 0;
                foreach (var problemlabel in _context.ProblemLabels.Where(x => x.ProblemId == item.Id.ToString()).ToList())
                {
                    foreach (var userlabel in _context.UserLabels.Where(x => x.UserId == user.Id.ToString()).ToList())
                    {
                        if (userlabel.LabelId == problemlabel.LabelId)
                        {
                            weight += userlabel.Weight * problemlabel.Weight;
                        }
                    }
                }
                if (_context.Tracks.FirstOrDefault(x => x.ProblemId == item.Id && x.Status == Models.Judge.JudgeStatus.Accept) != null)
                {
                    weight = -1;
                }
                RecommendProblem recommendProblem = new RecommendProblem
                {
                    problem = item,
                    Weight  = weight
                };
                recommendProblems.Add(recommendProblem);
            }
            recommendProblems.Sort((l, r) => r.Weight.CompareTo(l.Weight));

            List <ProblemAndHisLabel> problemAndHisLabels = new List <ProblemAndHisLabel>();

            foreach (var item in recommendProblems.Skip(page * PageSize).Take(PageSize).ToList())
            {
                ProblemAndHisLabel problemAndHisLabel = new ProblemAndHisLabel();
                problemAndHisLabel.problem = item.problem;

                if (user != null)
                {
                    var issolve = _context.Tracks.FirstOrDefault(x => x.ProblemId == item.problem.Id && x.SubmitterId == user.Id.ToString());
                    if (issolve == null)
                    {
                        problemAndHisLabel.IsSolved = false;
                    }
                    else
                    {
                        problemAndHisLabel.IsSolved = true;
                    }
                }
                else
                {
                    problemAndHisLabel.IsSolved = false;
                }


                // 去查每一个题目的标签
                List <LabelProfile> labelProfiles = new List <LabelProfile>();
                foreach (var ProblemLabelitem in _context.ProblemLabels.Where(x => x.ProblemId == item.problem.Id.ToString()).ToList())
                {
                    LabelProfile labelProfile = _context.LabelProfiles.FirstOrDefault(x => x.Id == long.Parse(ProblemLabelitem.LabelId));
                    labelProfiles.Add(labelProfile);
                }
                problemAndHisLabel.labelProfiles = labelProfiles;
                problemAndHisLabels.Add(problemAndHisLabel);
            }

            //获得所有标签
            List <LabelProfile> AllLables = _context.LabelProfiles.ToList();
            IndexViewModel      model     = new IndexViewModel
            {
                ProblemModels = problemAndHisLabels,
                AllLables     = AllLables,
                Page          = page
            };

            return(View(model));
        }