public List <SupplyViewVM> getSupply(int channelId, string creater) { var list = new List <SupplyViewVM>(); using (var ctx = new ShtxSms2008Entities()) { var today = DateTime.Today; DateTime tom = today.AddDays(1); //DateTime start = today.AddDays(-6); DateTime start = today.AddMonths(-6); //var supplies = ctx.Supplies.Where(o => o.CatalogID == channelId && o.CreateDate >= start && o.CreateDate < tom && o.isChecked == true).OrderByDescending(o => o.CreateDate); //change:// //List<int> catalogIds = ctx.CataLogs.Where(o => o.ChannelId == channelId).Select(o => o.ID).ToList(); List <int> catalogIds = CacheService.GetCataLogByChannelId(channelId).Select(o => o.Id).ToList(); var supplies = ctx.Supplies.Where(o => catalogIds.Contains(o.CatalogID.Value) && o.CreateDate >= start && o.CreateDate < tom && o.isChecked == true).OrderByDescending(o => o.CreateDate); foreach (var supply in supplies) { SupplyViewVM vm = new SupplyViewVM(); vm.Id = supply.ID; vm.Product = supply.Product; vm.SupplyType = supply.SupplyType.Value; vm.Contact = supply.Contact; vm.isChecked = supply.isChecked; vm.Price = supply.Price; var img = ctx.Images.FirstOrDefault(o => o.SupplyID == supply.ID); if (img != null) { vm.Avatar = "http://api.shtx.com.cn/Upload/" + getAvatarName(img.Name); } else { vm.Avatar = "http://api.shtx.com.cn/Upload/default.jpg"; } var city = ctx.Provinces.FirstOrDefault(o => o.ID == supply.ProviceID); var province = ctx.Provinces.FirstOrDefault(o => o.ID == city.ParentID); var address = province.Name + city.Name; vm.Address = address; if (supply.CreateDate >= today) { vm.Date = supply.CreateDate.ToString("HH:mm"); } else { vm.Date = supply.CreateDate.ToString("MM-dd"); } list.Add(vm); } } return(list); }
public List <SupplyViewVM> getMySupply(string mobile) { var list = new List <SupplyViewVM>(); var today = DateTime.Today; using (var ctx = new ShtxSms2008Entities()) { var supplies = ctx.Supplies.Where(o => o.Creater == mobile).OrderByDescending(o => o.CreateDate).ToList(); foreach (var supply in supplies) { SupplyViewVM vm = new SupplyViewVM(); vm.Id = supply.ID; vm.Product = supply.Product; vm.SupplyType = supply.SupplyType.HasValue?supply.SupplyType.Value:false; vm.Contact = supply.Contact; vm.isChecked = supply.isChecked; vm.Price = supply.Price; vm.Buissnes = supply.buissnes; vm.Description = supply.Description; vm.DocumentType = supply.DocumentType.Value; vm.Mobile = supply.Mobile; vm.Quantity = supply.Quantity; var img = ctx.Images.Where(o => o.SupplyID == supply.ID).ToList(); if (img.Count > 0) { var pic = new List <string>(); var pic1 = new List <string>(); foreach (var i in img) { pic.Add("http://api.shtx.com.cn/Upload/" + i.Name); pic.Add("http://api.shtx.com.cn/Upload/" + getAvatarName(i.Name)); } vm.Pics = pic; vm.Pics1 = pic1; } else { vm.Pics1 = new List <string> { "http://api.shtx.com.cn/Upload/default.jpg" }; vm.Pics = new List <string> { "http://api.shtx.com.cn/Upload/default.jpg" }; } vm.ProvinceName = supply.provinceName; vm.CityName = supply.cityName; if (supply.CreateDate >= today) { vm.Date = supply.CreateDate.ToString("HH:mm"); } else { vm.Date = supply.CreateDate.ToString("MM-dd"); } list.Add(vm); } } return(list); }