public TerminalGoods[] SearchTerminalGoods(string mode, string terminal = null) { Terminal = terminal ?? Terminal; var customer = mongo.CustomerCollection.AsQueryable().Where(c => !c.IsDisabled).SelectMany(c => c.Cabinets).Where(c => c.Computer == Terminal).ToList(); var fills = customer.SelectMany(c => c.Drawers).Where(d => !d.IsRecycleBin).SelectMany(d => d.Boxes).SelectMany(b => b.Fills).ToArray(); var tGoods = mongo.TerminalGoodsCollection.AsQueryable().Where(t => t.Computer == Terminal).ToList().Select(t => { t.StorageQuota = double.IsNaN(t.StorageQuota) ? 0.0 : t.StorageQuota; t.WarningQuota = double.IsNaN(t.WarningQuota) ? 0.0 : t.WarningQuota; t.Goods = t.Goods ?? new Goods { UniqueId = t.GoodsId, }; return(t); }).ToArray(); switch (mode) { case "All": /* do nothing */ break; case "Usage": tGoods = tGoods.Join(fills.Select(f => f.GoodsId).Distinct(), tg => tg.GoodsId, g => g, (tg, g) => tg).ToArray(); break; default: tGoods = new TerminalGoods[0]; break; } foreach (var tg in tGoods) { tg.CurrentQuota = fills.Where(f => f.GoodsId == tg.GoodsId).Sum(f => f.QtyExisted); } return(tGoods.OrderByDescending(t => t.CurrentQuota).ThenBy(t => t.Goods.Pinyin).ToArray()); }
public async Task <string> ModifyTerminalGoodsAsync([FromBody] TerminalGoods tg) { tg.UniqueId = tg.UniqueId ?? SfraObject.GenerateId(); tg.Goods = tg.Goods ?? mongo.GoodsCollection.AsQueryable().FirstOrDefault(f => f.UniqueId == tg.GoodsId); await mongo.TerminalGoodsCollection.FindOneAndReplaceAsync <TerminalGoods>(x => x.UniqueId == tg.UniqueId, tg, new FindOneAndReplaceOptions <TerminalGoods, TerminalGoods> { IsUpsert = true }); return(tg.UniqueId); }