Exemplo n.º 1
0
        public ActionResult RoleEdit(int id, SuncereRole model)
        {
            AjaxResult result;

            try
            {
                int[]                       permissionIds        = Request.Params["SuncerePermissions"].Split(',').Select(o => int.Parse(o)).ToArray();
                FluentModel                 db                   = Session.GetFluentModel();
                SuncereRoleRepository       repository           = new SuncereRoleRepository(db);
                SuncerePermissionRepository permissionRepository = new SuncerePermissionRepository(db);
                SuncereRole                 role                 = repository.FirstOrDefault(id);
                role.Remark             = model.Remark;
                role.LastModifierUserId = Session.GetCurrentUser().Id;
                foreach (SuncerePermission permission in role.SuncerePermissions)
                {
                    permission.SuncereRoles.Remove(role);
                }
                role.SuncerePermissions.Clear();
                foreach (int permissionId in permissionIds)
                {
                    SuncerePermission permission = permissionRepository.FirstOrDefault(permissionId);
                    role.SuncerePermissions.Add(permission);
                    permission.SuncereRoles.Add(role);
                }
                db.SaveChanges();
                result = AjaxResult.GetEditAjaxResult(true);
            }
            catch (Exception e)
            {
                result = AjaxResult.GetEditAjaxResult(false);
            }
            return(Json(result, JsonRequestBehavior.DenyGet));
        }
Exemplo n.º 2
0
        public ActionResult UserAdd(SuncereUser model)
        {
            AjaxResult result;

            try
            {
                int[]                 roleIds    = Request.Params["SuncereRoles"].Split(',').Select(o => int.Parse(o)).ToArray();
                FluentModel           db         = Session.GetFluentModel();
                SuncereUserRepository repository = new SuncereUserRepository(db);
                if (repository.IsExist(model.UserName))
                {
                    throw new Exception("用户名已存在。");
                }
                model.Password      = AsymmetricEncryption.Default.Encrypt(model.Password);
                model.Status        = true;
                model.CreatorUserId = Session.GetCurrentUser().Id;
                SuncereRoleRepository roleRepository = new SuncereRoleRepository(db);
                foreach (int roleId in roleIds)
                {
                    SuncereRole role = roleRepository.FirstOrDefault(roleId);
                    role.SuncereUsers.Add(model);
                    model.SuncereRoles.Add(role);
                }
                db.Add(model);
                db.SaveChanges();
                result = AjaxResult.GetAddAjaxResult(true);
            }
            catch (Exception e)
            {
                result = AjaxResult.GetAddAjaxResult(false);
            }
            return(Json(result, JsonRequestBehavior.DenyGet));
        }
Exemplo n.º 3
0
        public ActionResult RoleEdit(int id)
        {
            FluentModel              db             = Session.GetFluentModel();
            SuncereRoleRepository    repository     = new SuncereRoleRepository(db);
            List <SuncerePermission> permissionList = db.SuncerePermissions.Where(o => o.Status).ToList();

            ViewData["SuncerePermissions"] = permissionList;
            return(View(repository.FirstOrDefault(id)));
        }
Exemplo n.º 4
0
        public ActionResult RoleEnable(int id, bool status)
        {
            AjaxResult result;

            try
            {
                FluentModel           db         = Session.GetFluentModel();
                SuncereRoleRepository repository = new SuncereRoleRepository(db);
                SuncereRole           role       = repository.FirstOrDefault(id);
                role.Status             = status;
                role.LastModifierUserId = Session.GetCurrentUser().Id;
                db.SaveChanges();
                result = AjaxResult.GetEditAjaxResult(true);
            }
            catch (Exception e)
            {
                result = AjaxResult.GetEditAjaxResult(false);
            }
            return(Json(result, JsonRequestBehavior.DenyGet));
        }
Exemplo n.º 5
0
        public ActionResult UserEdit(int id, SuncereUser model)
        {
            AjaxResult result;

            try
            {
                int[]                 roleIds        = Request.Params["SuncereRoles"].Split(',').Select(o => int.Parse(o)).ToArray();
                FluentModel           db             = Session.GetFluentModel();
                SuncereUserRepository repository     = new SuncereUserRepository(db);
                SuncereRoleRepository roleRepository = new SuncereRoleRepository(db);
                SuncereUser           user           = repository.FirstOrDefault(id);
                if (!string.IsNullOrEmpty(model.Password))
                {
                    user.Password = AsymmetricEncryption.Default.Encrypt(model.Password);
                }
                user.EmailAddress = model.EmailAddress;
                user.PhoneNumber  = model.PhoneNumber;
                foreach (SuncereRole role in user.SuncereRoles)
                {
                    role.SuncereUsers.Remove(user);
                }
                user.SuncereRoles.Clear();
                foreach (int roleId in roleIds)
                {
                    SuncereRole role = roleRepository.FirstOrDefault(roleId);
                    user.SuncereRoles.Add(role);
                    role.SuncereUsers.Add(user);
                }
                user.Remark             = model.Remark;
                user.LastModifierUserId = Session.GetCurrentUser().Id;
                db.SaveChanges();
                result = AjaxResult.GetEditAjaxResult(true);
            }
            catch (Exception e)
            {
                result = AjaxResult.GetEditAjaxResult(false);
            }
            return(Json(result, JsonRequestBehavior.DenyGet));
        }