Ejemplo n.º 1
0
        public PartialViewResult CRUD_Role(string id = "0", string rolename = "", string displayname = "", bool active = true, string actionType = "")
        {
            if (!string.IsNullOrEmpty(actionType))
            {
                switch (actionType)
                {
                case "5":     //add role
                    if (string.IsNullOrEmpty(id))
                    {
                        var user = _roleService.FindOne(x => x.RoleName == rolename.Trim());
                        if (user == null)
                        {
                            var objectRole = new Role();
                            objectRole.RoleName    = rolename.Trim();
                            objectRole.DisplayName = displayname.Trim();
                            objectRole.Active      = active;
                            _roleService.AddNewItem(objectRole);
                        }
                    }
                    break;

                case "6":    //edit role
                    if (!string.IsNullOrEmpty(id) && string.Compare(id, "0") > 0)
                    {
                        var role = _roleService.FindById(decimal.Parse(id));
                        if (role != null)
                        {
                            role.RoleName    = rolename.Trim();
                            role.DisplayName = displayname.Trim();
                            role.Active      = active;
                            _roleService.UpdatetItem(role);
                        }
                    }
                    break;

                case "7":    //delete role
                    if (!string.IsNullOrEmpty(id) && string.Compare(id, "0") > 0)
                    {
                        var role = _roleService.FindById(decimal.Parse(id));
                        if (role != null)
                        {
                            _roleService.RemoveItem(role);
                        }
                    }
                    break;
                }
            }
            return(PartialView("_Roles", GetRoles()));
        }