public ActionResult Register(string token)
        {
            var invitation = _invitationRepository.GetActiveByToken(token, i => i.Securable, i => i.Securable.Members);

            if (invitation == null)
            {
                throw new HttpException(400, "Invalid token");
            }

            var user = _userRepository.GetCurrentUser(_securityHelper);

            var securable = invitation.Securable;

            if (!securable.Members.Any(u => u.Id == user.Id))
            {
                _securableAttacher.EnsureAttached(securable);
                _userAttacher.EnsureAttached(user);

                if (user.Securables == null)
                {
                    user.Securables = new List <Securable>();
                }
                user.Securables.Add(securable);

                _userRepository.Update(user);
            }
            invitation.AssignedToId = user.Id;

            _invitationRepository.Update(invitation);

            return(RedirectToAction("Index", "Dashboard", new { Area = "Manage" }));
        }
        public static void RemoveMember(this IRepository<Securable> repository, IAttacher<Securable> attacher, int userId, int securableId)
        {
            var securable = repository.GetBy(s => s.Id == securableId, s=>s.Members);
            attacher.EnsureAttached(securable);
            var toRemove = securable.Members.Where(m => m.Id == userId).ToList();
            foreach (var user in toRemove)
            {
                securable.Members.Remove(user);
            }

            repository.Update(securable);
        }
 public ActionResult EnsureBlogsHaveAuthorSecurables()
 {
     foreach (var blog in _blogRepo.GetAll().Where(b => b.AuthorSecurable == null).ToList())
     {
         _blogAttacher.EnsureAttached(blog);//Entities must be attached to muck about with nav properties
         var securable = new Data.Securable();
         _securableRepo.Create(securable);
         blog.AuthorSecurable = securable;
         _blogRepo.Update(blog);
     }
     return(RedirectToAction("Index", "Dashboard"));
 }
        public static void RemoveMember(this IRepository <Securable> repository, IAttacher <Securable> attacher, int userId, int securableId)
        {
            var securable = repository.GetBy(s => s.Id == securableId, s => s.Members);

            attacher.EnsureAttached(securable);
            var toRemove = securable.Members.Where(m => m.Id == userId).ToList();

            foreach (var user in toRemove)
            {
                securable.Members.Remove(user);
            }

            repository.Update(securable);
        }