public IActionResult GetMainCommodity() //返回商品 { CommodityDetailsView commodity = new CommodityDetailsView(); commodity = commdDetailService.DisplayCommodityDetails(Global.GCommodityID); string str = JsonConvert.SerializeObject(commodity); return(new ContentResult { Content = str, ContentType = "application/json" }); }
public CommodityDetailsView DisplayCommodityDetails(string commodityId) { if (commodityId == "") { return(null); } else { Commodity newCommodity = _context.Commodities.FirstOrDefault(c => c.CommodityId == commodityId); CommodityDetailsView newCommodityDetails = new CommodityDetailsView(); newCommodityDetails.commodityId = commodityId; newCommodityDetails.name = newCommodity.Name; newCommodityDetails.intro = newCommodity.Description; newCommodityDetails.price = newCommodity.Price; newCommodityDetails.imgUrl = newCommodity.Url; newCommodityDetails.storage = newCommodity.Storage; newCommodityDetails.shopId = newCommodity.ShopId; newCommodityDetails.category = newCommodity.Category; newCommodityDetails.errorCode = 0; return(newCommodityDetails); } }