本文整理汇总了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);
}