public ActionResult GetById(long?productId) { var inventorylist = new AllProducts(); if (productId != null) { var groupName = (GroupName)productId; var query = new InventoryQuery().GetInventories(groupName.ToString()); if (query != null) { foreach (var inventory in query) { var inverntoryModel = new InventoriesModel() { Id = inventory.Id, GroupName = groupName.ToString(), ItemsCount = inventory.ItemsCount, ProductName = inventory.ProductName }; inventorylist.InventoriesModels.Add(inverntoryModel); } } } return(PartialView("ProductsGrid", inventorylist)); }
/// <summary> /// 通过查询条件查询库存个数 /// </summary> /// <param name="t"></param> /// <returns></returns> public float searchInventoryCountByCondition(InventoryQuery t) { LayerDbContext context = new LayerDbContext(); var result = context.inventory.Where(x => x.id > 0); result = string.IsNullOrEmpty(t.materialName) ? result : result.Where(x => x.materialInfo.materialName == (t.materialName)); result = !t.materialId.HasValue ? result : result.Where(x => x.materialId == t.materialId); result = string.IsNullOrEmpty(t.mat_size) ? result : result.Where(x => x.materialInfo.mat_size == t.mat_size); result = string.IsNullOrEmpty(t.alias) ? result : result.Where(x => x.materialInfo.alias == (t.alias)); result = string.IsNullOrEmpty(t.remark) ? result : result.Where(x => x.materialInfo.remark.Contains(t.remark)); return(result.Select(x => x.count).Sum()); }
public InventoryQuerySpec() { var clientId = Guid.NewGuid(); InventoryData.Clients.Add(clientId); _fakeContextAccessor = new HttpContextAccessor(); _fakeContextAccessor.HttpContext = new DefaultHttpContext(); _fakeContextAccessor.HttpContext.Request.Headers["Authorization"] = $"Bearer {clientId}"; _mockInventory = new Mock <IInventoryRepository>(); _mockInventory.Setup(m => m.DoesClientExist(clientId)).ReturnsAsync(true); _testObject = new InventoryQuery(_fakeContextAccessor, _mockInventory.Object); }
/// <summary> /// 查询页面展示 /// </summary> /// <param name="pager"></param> /// <param name="t"></param> /// <returns></returns> public async Task <List <InventorySimpleModel> > searchByCondition(Pager <List <InventorySimpleModel> > pager, InventoryQuery t) { int start = (pager.page - 1) * pager.recPerPage; LayerDbContext context = new LayerDbContext(); var inventoryResult = context.inventory.GroupBy(x => x.materialId).Select(x => new { materialId = x.Key, count = x.Sum(item => item.count) }); var materialResult = context.materialInfos.Where(x => x.id > 0); materialResult = string.IsNullOrEmpty(t.materialName) ? materialResult : materialResult.Where(x => x.materialName == (t.materialName)); materialResult = string.IsNullOrEmpty(t.mat_size) ? materialResult : materialResult.Where(x => x.mat_size == t.mat_size); materialResult = string.IsNullOrEmpty(t.alias) ? materialResult : materialResult.Where(x => x.alias == (t.alias)); materialResult = string.IsNullOrEmpty(t.remark) ? materialResult : materialResult.Where(x => x.remark.Contains(t.remark)); var returnData = from x in materialResult join y in inventoryResult on x.id equals y.materialId into Temp from temp in Temp.DefaultIfEmpty() select new InventorySimpleModel { materialId = x.id, alais = x.alias, materialName = x.materialName, mat_size = x.mat_size, unit = x.unit, alarmCount = x.alarmCount, count = temp == null?0:temp.count }; if (t.lackFlag == 0) { returnData = returnData.Where(x => x.alarmCount >= x.count); } else if (t.lackFlag == 1) { returnData = returnData.Where(x => x.alarmCount < x.count); } returnData = returnData.OrderBy(x => x.count).Skip(start).Take(pager.recPerPage); return(await Task.Factory.StartNew(() => returnData.ToList())); }
public async Task <Pager <List <InventorySimpleModel> > > searchByCondition(Pager <List <InventorySimpleModel> > pager, InventoryQuery condition) { pager.data = await dao.searchByCondition(pager, condition); pager.recTotal = dao.searchCountByCondition(); return(pager); }
public async Task <ActionResult> search(Pager <List <InventorySimpleModel> > pager, InventoryQuery condition) { pager = await service.searchByCondition(pager, condition); ViewBag.condition = condition; return(View("Index", pager)); }
// GET: Inventory public ActionResult Index(Pager <List <InventorySimpleModel> > pager, InventoryQuery condition) { ViewBag.condition = condition; return(View(pager)); }