当前位置: 首页>>代码示例>>C#>>正文


C# System.Collections.Generic.List.Distinct方法代码示例

本文整理汇总了C#中System.Collections.Generic.List.Distinct方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.List.Distinct方法的具体用法?C# System.Collections.Generic.List.Distinct怎么用?C# System.Collections.Generic.List.Distinct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.Generic.List的用法示例。


在下文中一共展示了System.Collections.Generic.List.Distinct方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SolvingTask

        public ActionResult SolvingTask(int id, string Answer)
        {
            SolveTaskModel Model = new SolveTaskModel();
            ApplicationDbContext DB = new ApplicationDbContext();

            Model.Nicknames = new System.Collections.Generic.Dictionary<string,string>();
            Model.Task = DB.Tasks.First(c => c.UserTaskID == id);
            Model.Answers = DB.Answers.Where(c => c.TaskID == id).AsEnumerable();
            Model.Tags = DB.Tags.Where(c => c.TaskID == id).AsEnumerable();
            Model.UserName = DB.Users.First(c => c.Id == Model.Task.UserID).UserName;
            Model.Comments = DB.Comments.Where(c => c.TaskID == id).AsEnumerable();

            System.Collections.Generic.List<string> IDs = new System.Collections.Generic.List<string>();
            foreach(var i in DB.Comments.Where(c => c.TaskID == id))
                IDs.Add(i.UserID);
            IDs = IDs.Distinct().ToList();

            foreach (var i in IDs)
            {
                Model.Nicknames.Add(i, DB.Users.First(c=>c.Id==i).NickName);
            }
            
            string CurrentUserID = DB.Users.First(c => c.UserName == User.Identity.Name).Id;
            Model.Rating = 0;
            if (DB.Ratings.Any(c => c.UserID == CurrentUserID && c.TaskID == id)==true)
                Model.Rating = DB.Ratings.First(c => c.UserID == CurrentUserID && c.TaskID == id).RatingValue;
            
            Model.Solved = -1;
            if (DB.Tasks.Any(c => c.UserID == CurrentUserID && c.UserTaskID == id) == true)
                Model.Solved = -2;
            else
            {
                if (DB.Solves.Any(c => c.UserID == CurrentUserID && c.TaskID == id) == true)
                {
                    Model.Solved = -3;
                }
                else
                {
                    if (Answer != "" && Answer != null)
                    {
                        if (DB.Answers.Where(c => (c.TaskID == id) && (c.AnswerText == Answer)).ToList().Count != 0)
                        {
                            Model.Solved = 1;
                            Solves NewSolve = new Solves();
                            NewSolve.TaskID = id;
                            NewSolve.UserID = CurrentUserID;
                            DB.Solves.Add(NewSolve);
                            DB.Tasks.First(c => c.UserTaskID == id).SolveCount++;
                            DB.Entry(NewSolve).State = System.Data.Entity.EntityState.Added;
                            DB.SaveChanges();
                        }
                        else
                            Model.Solved = 0;
                    }
                }

            }
            return View(Model);
        }
开发者ID:Senfer,项目名称:FinalITRCP,代码行数:59,代码来源:ManageController.cs


注:本文中的System.Collections.Generic.List.Distinct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。