Exemplo n.º 1
0
        public ActionResult GrantModeratorRights(ToModerator toModerator)
        {
            var entry = new SectionModerator
            {
                UserId      = toModerator.UserId,
                SectionId   = toModerator.SectionId,
                DateGranted = DateTime.Now
            };
            User user = _repository.GetUserById(toModerator.UserId);

            user.RoleId = roleRepository.GetAllRoles().Single(x => x.Name == "Moderator").RoleId;
            _repository.UpdateUser(user);
            sectionModeratorsRepository.Add(entry);
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public ActionResult GrantModeratorRights(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            User user = _repository.GetUserById(id.Value);

            if (user == null)
            {
                return(HttpNotFound());
            }
            var sectionsCanBeModerated = sectionRepository.Sections.ToList()
                                         .Where(section => (user.SectionModerators.Any(x => x.SectionId == section.SectionId)) == false);

            ViewBag.SectionId = new SelectList(sectionsCanBeModerated, "SectionId", "Name");
            ToModerator toModerator = new ToModerator
            {
                UserId   = user.UserId,
                Username = user.Username
            };

            return(View(toModerator));
        }