コード例 #1
0
        public ActionResult Create([Bind(Include = "Name")] Roles role)
        {
            role.Id = Guid.NewGuid().ToString();
            if (ModelState.IsValid)
            {
                SqlHelper.CreateRole(role.Id, role.name);
                return(RedirectToAction("Index"));
            }

            return(View(role));
        }
コード例 #2
0
        public ActionResult Create(FormCollection collection)
        {
            var userId = Session["UserId"].ToString();

            SqlHelper.DbContext();
            string   id          = Guid.NewGuid().ToString();
            string   profileId   = collection["Profiles"];
            Profiles profileName = SqlHelper.GetProfile(profileId);
            string   roleId      = collection["Roles"];
            Roles    roleName    = SqlHelper.GetRole(roleId);

            if (ModelState.IsValid)
            {
                SqlHelper.CreateProfileRole(id, profileId, profileName.name, roleId, roleName.name);
                return(RedirectToAction("Index"));
            }

            return(View(layoutViewModel.LayoutViewModelProfileRolesBuilder(Session["UserId"].ToString())));
        }
コード例 #3
0
        public ActionResult Edit(FormCollection collection)
        {
            var userId = Session["UserId"].ToString();

            if (ModelState.IsValid)
            {
                SqlHelper.DbContext();
                List <ProfileRoles> profileRoles = SqlHelper.GetAllProfileRoles();
                for (var i = 0; i < profileRoles.Count; i++)
                {
                    string updateProfile = collection["ProfileRoles[" + i + "].ProfileName"];
                    string updateRole    = collection["ProfileRoles[" + i + "].RoleName"];
                    if (profileRoles[i].ProfileName != updateProfile || profileRoles[i].RoleName != updateRole && profileRoles[i].RoleName != null)
                    {
                        Profiles profile = SqlHelper.GetProfileByName(updateProfile);
                        Roles    role    = SqlHelper.GetRoleByName(updateRole);
                        SqlHelper.EditProfileRoles(profileRoles[i].Id, profile.Id, updateProfile, role.Id, updateRole);
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(layoutViewModel.LayoutViewModelProfileRolesBuilder(userId)));
        }