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 RoleAdd(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);
                if (repository.IsExist(model.Name))
                {
                    throw new Exception("名称已存在。");
                }
                model.Status        = true;
                model.CreatorUserId = Session.GetCurrentUser().Id;
                foreach (int permissionId in permissionIds)
                {
                    SuncerePermission permission = permissionRepository.FirstOrDefault(permissionId);
                    model.SuncerePermissions.Add(permission);
                    permission.SuncereRoles.Add(model);
                }
                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 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.º 4
0
        public ActionResult RoleDelete(string ids)
        {
            AjaxResult result;

            try
            {
                int[]                    idArray    = ids.Split(',').Select(o => int.Parse(o)).ToArray();
                FluentModel              db         = Session.GetFluentModel();
                SuncereRoleRepository    repository = new SuncereRoleRepository(db);
                IQueryable <SuncereRole> query      = repository.Query(idArray);
                foreach (SuncereRole role in query)
                {
                    foreach (SuncereUser user in role.SuncereUsers)
                    {
                        user.SuncereRoles.Remove(role);
                    }
                    foreach (SuncerePermission permission in role.SuncerePermissions)
                    {
                        permission.SuncereRoles.Remove(role);
                    }
                    role.SuncereUsers.Clear();
                    role.SuncerePermissions.Clear();
                }
                db.Delete(query);
                db.SaveChanges();
                result = AjaxResult.GetDeleteAjaxResult(true);
            }
            catch (Exception e)
            {
                result = AjaxResult.GetDeleteAjaxResult(false);
            }
            return(Json(result, JsonRequestBehavior.DenyGet));
        }
Exemplo n.º 5
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.º 6
0
        public ActionResult RoleList(DateTime?startTime, DateTime?endTime, string keyword)
        {
            FluentModel           db         = Session.GetFluentModel();
            SuncereRoleRepository repository = new SuncereRoleRepository(db);
            List <SuncereRole>    list       = repository.Query(startTime, endTime, keyword).ToList();

            ViewData["startTime"] = startTime;
            ViewData["endTime"]   = endTime;
            ViewData["keyword"]   = keyword;
            return(View(list));
        }
Exemplo n.º 7
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.º 8
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));
        }