public JsonResult UpdateParameters(IEnumerable <_post_Product_Attr> items) { ResultBase_form result = new ResultBase_form(); result.status = 1; result.msg = "操作成功"; try { //清除数据 Guid pid = items.First().ProductID; if (Product_Att_ValService.instance().DeleteByProductID(pid) > 0 && Product_PriceService.instance().DeleteByProductID(pid) > 0) { foreach (var item in items) { //添加属性值 Product_Att_Val pv = new Product_Att_Val(); pv.ID = Guid.NewGuid(); pv.ProductID = pid; pv.Value = item.Att_val; pv.Att_Key_ID = item.Att_key; pv.Short = item.Short; if (Product_Att_ValService.instance().Insert(pv) > 0) { //添加价格 Product_Price pp = new Product_Price(); pp.ID = Guid.NewGuid(); pp.ProductID = pid; pp.Price = item.Price; pp.Stock = item.Stock; pp.Att_Key = item.Att_key; pp.Att_Val = pv.ID; Product_PriceService.instance().Insert(pp); } } } } catch { result.status = 0; result.msg = "操作失败"; } return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult GetParameters(string id) { Guid pid; List <_post_Product_Attr> result = new List <_post_Product_Attr>(); if (Guid.TryParse(id, out pid)) { IEnumerable <Product_Att_Val> pvs = Product_Att_ValService.instance().GetEnumByProductID(pid).OrderBy(m => m.Short); foreach (var pv in pvs) { _post_Product_Attr att = new _post_Product_Attr(); att.ProductID = pid; att.Att_val = pv.Value; att.Att_key = pv.Att_Key_ID; Product_Price pp = Product_PriceService.instance().GetEnumByKVP(pid, pv.Att_Key_ID, pv.ID); att.Price = pp.Price; att.Stock = pp.Stock; att.Short = pv.Short; result.Add(att); } } return(Json(result, JsonRequestBehavior.AllowGet)); }