public ActionResult Index(string id, string key) { string userId = User.Identity.GetUserId(); var user = _userRepository.Find(userId); if (user == null) { return(new HttpNotFoundResult()); } var invite = _inviteRepository.Find(id); if (invite == null || invite.SecurityKey != key) { return(new HttpNotFoundResult()); } // add user to organization user.Organizations.Add(invite.OrganizationId); _userRepository.Save(user); // delete invite _inviteRepository.Delete(invite); return(RedirectToAction("Index", "Organization")); }
public void Insert(ChallengeIdeaDto challengeIdeaDto) { var invite = _inviteRepository.Find(x => x.ChallengeId == challengeIdeaDto.Id && x.UserId == Guid.Parse("8268c85c-6355-4ebd-b498-0d1a8839e052")) .FirstOrDefault(); if (invite == null) { return; } foreach (var idea in challengeIdeaDto.Ideas) { idea.InviteId = invite.Id; var tmpIdea = _ideaRepository.GetById(idea.Id); if (tmpIdea == null) { _ideaRepository.Add(idea); } else { tmpIdea.Title = idea.Title; tmpIdea.Description = idea.Description; _ideaRepository.Update(tmpIdea); } } var challenge = _challengeRepository.GetById(challengeIdeaDto.Id); if (challenge.ChallengeState == 2) { challenge.ChallengeState += 1; } }
private bool HasAccess(string id, out Invite invite, out User user) { invite = null; string userId = User.Identity.GetUserId(); user = _userRepository.Find(userId); if (user == null) { return(false); } invite = _inviteRepository.Find(id); if (invite == null) { return(true); // allow create } // user must be member return(invite.OrganizationId == user.Id || user.Organizations.Contains(invite.OrganizationId)); }