public ContentResult Search(SearchParam param)
        {
            //园区字段
            string park = string.Empty;

            if (!string.IsNullOrEmpty(param.Park))
            {
                park = param.Park;
            }
            else
            {
                park = ParkList.FirstOrDefault();
            }

            var list       = dc.Set <V_Resource>().Where(a => a.ResourceKindID == 2 && a.Loc1 == park);
            var cbTypeList = list
                             .GroupBy(a => new { a.ResourceTypeID, a.ResourceTypeName })
                             .OrderBy(a => a.Key.ResourceTypeName)
                             .Select(a => new { a.Key.ResourceTypeID, a.Key.ResourceTypeName })
                             .ToList();
            List <object> resObjcet = new List <object>();

            foreach (var item in cbTypeList)
            {
                var rmList = list
                             .Where(a => a.ResourceTypeID == item.ResourceTypeID)
                             .GroupBy(a => new { a.Loc5, a.Loc5Name })
                             .Select(a => new { a.Key.Loc5, a.Key.Loc5Name })
                             .ToList();
                List <object> rmObjList = new List <object>();
                foreach (var it in rmList)
                {
                    var cb = list.Where(a => a.Loc5 == it.Loc5)
                             .Select(a => new
                    {
                        a.ID,
                        a.Name,
                        a.RentStatus,
                        a.Loc1,
                        a.RentBeginTime,
                        a.RentEndTime,
                        a.CustShortName,
                        a.CustTel,
                        a.RentArea
                    }).ToList();
                    rmObjList.Add(new { RID = it.Loc5, RName = it.Loc5Name, CB = cb });
                }
                resObjcet.Add(new { TID = item.ResourceTypeID, TName = item.ResourceTypeName, RM = rmObjList });
            }
            JsonSerializerSettings setting = new JsonSerializerSettings
            {
                DateFormatString = "yyyy-MM-dd"
            };
            var obj = JsonConvert.SerializeObject(resObjcet, setting).Replace("null", "\"\"");

            return(Content(obj));
        }
Esempio n. 2
0
        public ContentResult Search(SearchParam param)
        {
            string park = string.Empty;
            var    list = dc.Set <V_Resource>().Where(a => a.ResourceKindID == 1);

            if (!string.IsNullOrEmpty(param.Park))
            {
                park = param.Park;
            }
            else
            {
                park = ParkList.FirstOrDefault();
            }
            list = list.Where(a => a.Loc1 == park);
            if (!string.IsNullOrEmpty(param.Name))
            {
                list = list.Where(a => a.Name.Contains(param.Name));
            }
            if (!string.IsNullOrEmpty(param.Cust))
            {
                list = list.Where(a => a.CustLongName.Contains(param.Cust));
            }
            if (param.Status != null)
            {
                list = list.Where(a => a.Status == param.Status);
            }
            var bulidList = dc.Set <V_Building>().Where(a => a.ParkID == park).Select(a => new { a.ID, a.Name }).ToList();
            var floorList = dc.Set <V_Floor>().Where(a => a.ParkID == park).Select(a => new { a.ID, a.Name, BID = a.BuildingID }).ToList();
            var rmList    = list.Select(a => new
            {
                a.ID,
                a.Name,
                a.Status,
                a.RentBeginTime,
                a.RentEndTime,
                a.CustShortName,
                a.CustTel,
                a.RentArea,
                a.Loc4
            }).ToList();
            JsonSerializerSettings setting = new JsonSerializerSettings
            {
                DateFormatString = "yyyy-MM-dd"
            };
            var obj = JsonConvert.SerializeObject(new
            {
                park   = park,
                blist  = bulidList,
                flist  = floorList,
                rmlist = rmList
            }, setting).Replace("null", "\"\"");

            return(Content(obj));
        }