public bool AddParticipantToDefaultTeam(string participantId) { using (var db = new ContestMeterDbContext()) { var user = db.Users.Find(participantId); if (user == null) { return(false); } var defaultTeam = db.Teams.FirstOrDefault(t => t.Name == "Одиночки"); if (defaultTeam == null) { return(false); } var teamParticipant = new TeamParticipant { Id = Guid.NewGuid(), TeamId = defaultTeam.Id, ParticipantId = user.Id }; db.Entry(teamParticipant).State = EntityState.Added; user.TeamId = defaultTeam.Id; defaultTeam.Participants.Add(user); db.Entry(user).State = EntityState.Modified; db.Entry(defaultTeam).State = EntityState.Modified; db.SaveChanges(); return(true); } }
public int damage = 1; // 1/2 heart by default public void OnCollisionEnter2D(Collision2D other) { GameObject otherObject = other.gameObject; TeamParticipant otherParticipant = otherObject.GetComponent <TeamParticipant>(); if (otherParticipant != null) { if (otherParticipant.GetTeam().OnOpposingTeam(team.GetTeam())) { Destroy(gameObject); HealthSystem health = otherObject.GetComponent <HealthSystem>(); health.Damage(damage); } } }
public async Task <ActionResult> AddParticipants(Guid?teamId, string id) { if (teamId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var team = await _db.Teams.FindAsync(teamId); if (team == null) { return(HttpNotFound()); } if (!User.IsInRole("administrator") && !_db.TeamParticipants.Any(tp => tp.TeamId == teamId)) { TempData["Message"] = "Вы не имеете право добавлять участников для данной команды"; return(RedirectToAction("Edit", new { id })); //ViewBag.ErrorMessage = "Вы не имеете право добавлять участников для данной команды"; //return View("Error"); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (team.MaxTeamNumber <= team.Participants.Count) { TempData["Message"] = "Достигнуто максимальное количество участников команды."; return(RedirectToAction("Edit", new { id = teamId })); } var participant = _db.Users.Find(id); if (participant == null) { return(HttpNotFound()); } if (participant.TeamId != null) { TempData["Message"] = "Участник '" + participant.UserName + "' не был добавлен в команду '" + team.Name + "', так как состоит в другой команде - '" + participant.Team.Name + "'. Пожалуйста, сначала удалите его из этой команды."; return(RedirectToAction("Edit", new { id = teamId })); } participant.TeamId = teamId; team.Participants.Add(participant); participant.Team = team; var teamParticipant = new TeamParticipant { Id = Guid.NewGuid(), TeamId = (Guid)teamId, ParticipantId = id }; _db.Entry(teamParticipant).State = EntityState.Added; _db.Entry(participant).State = EntityState.Modified; _db.Entry(team).State = EntityState.Modified; await _db.SaveChangesAsync(); return(RedirectToAction("Edit", new { id = teamId })); }