Ejemplo n.º 1
0
        public ActionResult DeviceList(DeviceQueryModel query, string keywords)
        {
            var eId = 0L;

            if (long.TryParse(keywords, out eId))
            {
                query.DeviceIdLike = eId;
            }
            else
            {
                query.NameLike = keywords;
            }

            using (var db = new MbContext())
            {
                //DOTO 获取当前单位下拥有的设备
                if (CurrentUser.User.RoleKey.HasFlag(LZY.BX.Model.Enum.UserType.SvcCompanyUserAdmin))
                {
                    IQueryable <Device> equipmentModel;
                    if (query.DeviceIdLike != null || query.NameLike != null)
                    {
                        equipmentModel = db.Device
                                         .Where(query);
                    }
                    else
                    {
                        var deviceArr = db.DeviceContract.Where(x => x.ServiceCompanyId == CurrentUser.User.ServiceCompanyId).Select(t => t.DeviceId).ToArray();
                        equipmentModel = db.Device.Where(x => deviceArr.Contains(x.DeviceId));
                    }
                    //设备列表主数据
                    query.Data = equipmentModel
                                 .OrderByDescending(x => x.CreateTime)
                                 .Skip(query.PageInfo.RecIndex)
                                 .Take(query.PageInfo.PageSize)
                                 .ToList();
                    //品牌字典
                    var brandsIds = query.Data.Select(x => x.BrandId).ToList();

                    query.BrandDic = db.Brand
                                     .Where(x => brandsIds.Contains(x.BrandId))
                                     .ToLookup(x => x.BrandId)
                                     .ToDictionary(x => x.Key, x => x.First());

                    ////设备信息
                    var equipmentIds = query.Data.Select(x => x.CategoryId).ToList();

                    query.CategoryDic = db.Category
                                        .Where(t => equipmentIds.Contains(t.CategoryId))
                                        .ToLookup(x => x.CategoryId)
                                        .ToDictionary(x => x.Key, x => x.First());
                    //设备数量
                    query.PageInfo.TotalCount = equipmentModel.Count();
                }
            }
            return(View(query));
        }
Ejemplo n.º 2
0
        public ActionResult DeviceList(DeviceQueryModel query)
        {
            using (var db = new MbContext())
            {
                var model = db.Device.Where(query).OrderBy(t => t.CreateTime);

                query.Data = model
                             .Include(t => t.UseCompany)
                             .Include(t => t.Brand)
                             .Include(t => t.Brand.Manufacturer)
                             .Include(t => t.Area)
                             .Include(t => t.Category)
                             .Skip(query.PageInfo.RecIndex)
                             .Take(query.PageInfo.PageSize)
                             .ToList();

                query.PageInfo.TotalCount = model.Count();

                return(View(query));
            }
        }