Пример #1
0
        public async Task <ActionResult> Create(
            [Bind(Include = "Name,Description")] CERPA.Models.ApplicationGroup applicationgroup,
            params string[] selectedRoles)
        {
            if (ModelState.IsValid)
            {
                // Create the new Group:
                var result = await this.GroupManager.CreateGroupAsync(applicationgroup);

                if (result.Succeeded)
                {
                    selectedRoles = selectedRoles ?? new string[] { };

                    // Add the roles selected:
                    await this.GroupManager
                    .SetGroupRolesAsync(applicationgroup.Id, selectedRoles);
                }
                return(RedirectToAction("Index"));
            }

            // Otherwise, start over:
            ViewBag.RoleId = new SelectList(
                this.RoleManager.Roles.ToList(), "Id", "Name");
            return(View(applicationgroup));
        }
Пример #2
0
        public async Task <ActionResult> DeleteConfirmed(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CERPA.Models.ApplicationGroup applicationgroup = await this.GroupManager.FindByIdAsync(id);

            await this.GroupManager.DeleteGroupAsync(id);

            return(RedirectToAction("Index"));
        }
Пример #3
0
        public async Task <ActionResult> Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CERPA.Models.ApplicationGroup applicationgroup = await this.GroupManager.FindByIdAsync(id);

            if (applicationgroup == null)
            {
                return(HttpNotFound());
            }
            return(View(applicationgroup));
        }
Пример #4
0
        public async Task <ActionResult> Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CERPA.Models.ApplicationGroup applicationgroup =
                await this.GroupManager.Groups.FirstOrDefaultAsync(g => g.Id == id);

            if (applicationgroup == null)
            {
                return(HttpNotFound());
            }
            var groupRoles = this.GroupManager.GetGroupRoles(applicationgroup.Id);

            string[] RoleNames = groupRoles.Select(p => p.Name).ToArray();
            ViewBag.RolesList  = RoleNames;
            ViewBag.RolesCount = RoleNames.Count();
            return(View(applicationgroup));
        }
Пример #5
0
        public async Task <ActionResult> Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CERPA.Models.ApplicationGroup applicationgroup = await this.GroupManager.FindByIdAsync(id);

            if (applicationgroup == null)
            {
                return(HttpNotFound());
            }

            // Get a list, not a DbSet or queryable:
            var allRoles = await this.RoleManager.Roles.ToListAsync();

            var groupRoles = await this.GroupManager.GetGroupRolesAsync(id);

            var model = new GroupViewModel()
            {
                Id          = applicationgroup.Id,
                Name        = applicationgroup.Name,
                Description = applicationgroup.Description
            };

            // load the roles/Roles for selection in the form:
            foreach (var Role in allRoles)
            {
                var listItem = new SelectListItem()
                {
                    Text     = Role.Name,
                    Value    = Role.Id,
                    Selected = groupRoles.Any(g => g.Id == Role.Id)
                };
                model.RolesList.Add(listItem);
            }
            return(View(model));
        }
Пример #6
0
 public IdentityResult CreateGroup(ApplicationGroup group)
 {
     _groupStore.Create(group);
     return(IdentityResult.Success);
 }
Пример #7
0
        public async Task <IdentityResult> CreateGroupAsync(ApplicationGroup group)
        {
            await _groupStore.CreateAsync(group);

            return(IdentityResult.Success);
        }