public void AddGamer(long Id, Gamer gamer = null) { gamer = gamer ?? Service <Gamer> .I.Get(Id); IO_GameGamer gameGamer = new IO_GameGamer(gamer, Game); Game.GameGamers.Add(gameGamer); }
public List <Result> Results() { List <Result> results = new List <Result>(); foreach (Gamer gamer in Gamers) { List <IO_Answer> answers = gamer.Answers .Where(x => x.RecipientId == gamer.Id) .GroupBy(x => x.TaskId).Select(x => x.First()).ToList(); List <IO_Attribute> attributes = answers .SelectMany(x => x.Task.TaskAttributes.Select(z => z.Attribute)) .GroupBy(x => x.Id).Select(x => x.First()).ToList(); List <IO_Feature> features = Service <IO_Feature> .I .Get(x => x.FeatureAttributes.All(z => attributes.Any(a => a.Id == z.AttributeId))) .OrderByDescending(x => x.FeatureAttributes.Count()).ToList(); if (features.Count() > 0) { foreach (IO_Feature feature in features) { results.Add(new Result() { Gamer = gamer, Feature = feature, Count = feature.FeatureAttributes.Count() }); } } else { IO_Feature feature = Service <IO_Feature> .I.Get(12); results.Add(new Result() { Gamer = gamer, Feature = feature, Count = feature.FeatureAttributes.Count() }); } } results = Result.SearchMax(results); foreach (Result R in results) { IO_GameGamer gamer = GameGamer(R.Gamer.Id); gamer.Feature = R.Feature; gamer.FeatureId = R.Feature.Id; } Game.End = DateTime.Now; Service <IO_GameSession> service = Service <IO_GameSession> .I; service.Create(Game); service.SaveFromDataBase(); isEnd = true; return(results); }
public void RemoveGamer(long Id) { IO_GameGamer gameGamer = Game.GameGamers.FirstOrDefault(x => x.GamerId == Id)?.Get <IO_GameGamer>(); if (gameGamer != null) { foreach (IO_Task task in Game.GameTasks.Select(x => x.Task).ToList()) { foreach (IO_Answer answer in task.Answers.Where(x => x.RecipientId == Id || x.SenderId == Id)) { if (answer.SenderId == Id) { answer.SenderId = null; answer.Sender = null; } else { task.Answers.Remove(answer); } } } Game.GameGamers.Remove(gameGamer); } }