예제 #1
0
        public IActionResult FindListByUserGuid(Guid guid)
        {
            HttpResponseModel response = ResponseModelFactory.CreateInstance;

            using (this.DbContext)
            {
                // 有N+1次查询的性能问题
                // var query = this.DbContext.DncUser
                //    .Include(r => r.UserRoles)
                //    .ThenInclude(x => x.DncRole)
                //    .Where(x => x.Guid == guid);
                // var roles = query.FirstOrDefault().UserRoles.Select(x => new
                // {
                //    x.DncRole.Code,
                //    x.DncRole.Name
                // });
                string      sql           = @"SELECT R.* FROM DncUserRoleMapping AS URM
INNER JOIN DncRole AS R ON R.Code=URM.RoleCode
WHERE URM.UserGuid={0}";
                List <Role> query         = this.DbContext.Role.AsNoTracking().FromSqlRaw(sql, guid).ToList();
                List <int>  assignedRoles = query.ToList().Select(x => x.Id).ToList();
                var         roles         = this.DbContext.Role.AsNoTracking().Where(x => !x.IsEnable && x.IsForbidden).ToList().Select(x => new { label = x.Name, key = x.Id });
                response.SetData(new { roles, assignedRoles });
                return(this.Ok(response));
            }
        }
예제 #2
0
        public IActionResult Tree(string selected)
        {
            HttpResponseModel response = ResponseModelFactory.CreateInstance;
            List <MenuTree>   tree     = this.LoadMenuTree(selected);

            response.SetData(tree);
            return(this.Ok(response));
        }
예제 #3
0
 public JsonResult Edit(int id)
 {
     using (this.DbContext)
     {
         Icon entity = this.DbContext.Icon.AsNoTracking().FirstOrDefault(x => x.Id == id);
         HttpResponseModel response = ResponseModelFactory.CreateInstance;
         response.SetData(this.Mapper.Map <Icon, IconCreateViewModel>(entity));
         return(this.Json(response));
     }
 }
예제 #4
0
        public IActionResult FindById(int id)
        {
            using (this.DbContext)
            {
                Menu              entity   = this.DbContext.Menu.Find(id);
                MenuModel         model    = new MenuModel(entity);
                HttpResponseModel response = ResponseModelFactory.CreateInstance;
                response.SetData(model);

                return(this.Ok(response));
            }
        }
예제 #5
0
        public IActionResult FindSimpleList()
        {
            HttpResponseModel response = ResponseModelFactory.CreateInstance;

            using (this.DbContext)
            {
                var roles = this.DbContext.Role.AsNoTracking().Where(x => !x.IsEnable && x.IsForbidden).Select(x => new { x.Name, x.Id }).ToList();
                response.SetData(roles);
            }

            return(this.Ok(response));
        }
예제 #6
0
 public IActionResult Edit(string code)
 {
     using (this.DbContext)
     {
         Permission              entity   = this.DbContext.Permission.FirstOrDefault(x => x.Id == code);
         HttpResponseModel       response = ResponseModelFactory.CreateInstance;
         PermissionEditViewModel model    = this.Mapper.Map <Permission, PermissionEditViewModel>(entity);
         Menu menu = this.DbContext.Menu.FirstOrDefault(x => x.Id == entity.MenuId);
         model.MenuName = menu.Name;
         response.SetData(model);
         return(this.Ok(response));
     }
 }
예제 #7
0
        public JsonResult FindById(int id)
        {
            using (this.DbContext)
            {
                this.DbContext.Set <UserRoleMapping>().Load();
                this.DbContext.Set <Role>().Load();
                User              entity   = this.DbContext.User.Find(id);
                UserModel         model    = new UserModel(entity);
                HttpResponseModel response = ResponseModelFactory.CreateInstance;
                response.SetData(model);

                return(this.Json(response));
            }
        }