public JsonResult Save(SuppliersProductType obj) { try { List <SuppliersProductType> list = Session["SupplierProducts"] as List <SuppliersProductType>; if (list == null) { list = new List <SuppliersProductType>(); } SuppliersProductType findOne = list.Find(p => p.SKU == obj.SKU); if (findOne != null) { // findOne = obj; list.Remove(findOne); list.Add(obj); } else { list.Add(obj); } Session["SupplierProducts"] = list; } catch (Exception ee) { return(Json(new { IsSuccess = false, ErrorMsg = "出错了" })); } return(Json(new { IsSuccess = true })); }
public void DelProduct(string id) { List <SuppliersProductType> list = Session["SupplierProducts"] as List <SuppliersProductType>; SuppliersProductType findOne = list.Find(p => p.SKU == id.ToString()); list.Remove(findOne); Session["SupplierProducts"] = list; }
/// <summary> /// 根据Id获取 /// </summary> /// <param name="Id"></param> /// <returns></returns> public SuppliersProductType GetById(int Id) { SuppliersProductType obj = NSession.Get <SuppliersProductType>(Id); if (obj == null) { throw new Exception("返回实体为空"); } else { return(obj); } }
public JsonResult Create(SuppliersProductType obj) { try { NSession.SaveOrUpdate(obj); NSession.Flush(); } catch (Exception ee) { return(Json(new { IsSuccess = false, ErrorMsg = "出错了" })); } return(Json(new { IsSuccess = true })); }
public JsonResult DeleteConfirmed(int id) { try { SuppliersProductType obj = GetById(id); NSession.Delete(obj); NSession.Flush(); } catch (Exception ee) { return(Json(new { IsSuccess = false, ErrorMsg = "出错了" })); } return(Json(new { IsSuccess = true })); }
private void SaveSupplier(PurchasePlanType obj) { object exit = NSession.CreateQuery("from SupplierType where SuppliersName='" + obj.Suppliers + "'").UniqueResult(); if (exit == null) { SupplierType super = new SupplierType { SuppliersName = obj.Suppliers }; NSession.Save(super); NSession.Flush(); SuppliersProductType product = new SuppliersProductType { SId = super.Id, SKU = obj.SKU, Price = obj.Price, Web = obj.ProductUrl }; NSession.Save(product); NSession.Flush(); } else { IList <SupplierType> list = NSession.CreateQuery("from SupplierType where SuppliersName='" + obj.Suppliers + "'").List <SupplierType>(); object productexit = NSession.CreateQuery("from SuppliersProductType where SId='" + list[0].Id + "' and SKU='" + obj.SKU + "' ").UniqueResult(); if (productexit == null) { SuppliersProductType product = new SuppliersProductType { SId = list[0].Id, SKU = obj.SKU, Price = obj.Price, Web = obj.ProductUrl }; NSession.Save(product); NSession.Flush(); } } }
public ActionResult Edit(int id) { SuppliersProductType obj = GetById(id); return(View(obj)); }