/// <summary> /// 修改【---事务---】 /// </summary> /// <param name="dp"></param> /// <returns></returns> public static int EdiStocks(Losts dep, List <LostDetail> list) { PSSEntities db = new PSSEntities(); int fg = 1; ///以下开始事务操作 using (var tx = db.Database.BeginTransaction()) { try { //将要修改的创建人找回来,避免修改时没有创建人 Losts st = db.Losts.FirstOrDefault(p => p.LostID == dep.LostID); st.DepotID = dep.DepotID; st.LostDate = dep.LostDate; st.LostDesc = dep.LostDesc; db.LostDetail.RemoveRange(db.LostDetail.Where(p => p.LostID == dep.LostID)); if (list != null) { db.LostDetail.AddRange(list); } db.SaveChanges(); tx.Commit(); } catch (Exception e) { fg = 0; tx.Rollback(); throw new Exception(e.Message); } } return(fg); }
public void CreateTest() { LostsVM vm = _controller.Wtm.CreateVM <LostsVM>(); Losts v = new Losts(); v.LostID = "sWTrOWsWR"; v.DepotsID = AddDepots(); v.LostDesc = "Pzf0KpTYy"; v.LostState = SCMSupplyChain.Model.LostState.未定义1; vm.Entity = v; var rv = _controller.Add(vm); Assert.IsInstanceOfType(rv, typeof(OkObjectResult)); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <Losts>().Find(v.ID); Assert.AreEqual(data.LostID, "sWTrOWsWR"); Assert.AreEqual(data.LostDesc, "Pzf0KpTYy"); Assert.AreEqual(data.LostState, SCMSupplyChain.Model.LostState.未定义1); Assert.AreEqual(data.CreateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10); } }
/// <summary> /// 添加【---事务---】 /// </summary> /// <param name="dep"></param> /// <returns></returns> public static int AddStocks(Losts dep, List <LostDetail> list) { PSSEntities db = new PSSEntities(); int fg = 1; using (var tx = db.Database.BeginTransaction()) { try { db.Losts.Add(dep); if (list != null) { db.LostDetail.AddRange(list); } db.SaveChanges(); tx.Commit(); } catch (Exception e) { fg = 0; tx.Rollback(); throw new Exception(e.Message); } } return(fg); }
public void BatchDeleteTest() { Losts v1 = new Losts(); Losts v2 = new Losts(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v1.LostID = "sWTrOWsWR"; v1.DepotsID = AddDepots(); v1.LostDesc = "Pzf0KpTYy"; v1.LostState = SCMSupplyChain.Model.LostState.未定义1; v2.LostID = "Gm3F7ECaV"; v2.DepotsID = v1.DepotsID; v2.LostDesc = "6iJgee"; v2.LostState = SCMSupplyChain.Model.LostState.未定义1; context.Set <Losts>().Add(v1); context.Set <Losts>().Add(v2); context.SaveChanges(); } var rv = _controller.BatchDelete(new string[] { v1.ID.ToString(), v2.ID.ToString() }); Assert.IsInstanceOfType(rv, typeof(OkObjectResult)); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data1 = context.Set <Losts>().Find(v1.ID); var data2 = context.Set <Losts>().Find(v2.ID); Assert.AreEqual(data1, null); Assert.AreEqual(data2, null); } rv = _controller.BatchDelete(new string[] {}); Assert.IsInstanceOfType(rv, typeof(OkResult)); }
/// <summary> /// 审核报损单 /// </summary> /// <param name="id"></param> /// <returns></returns> public static int CKInDepot(string id, int userid) { PSSEntities db = new PSSEntities(); int fg = 1; ///以下开始事务操作 using (var tx = db.Database.BeginTransaction()) { try { Losts st = db.Losts.FirstOrDefault(s => s.LostID.Equals(id)); st.LostState = 1; ObjectParameter para = new ObjectParameter("DD", ""); db.pro_order("InOutDepot", "IODNum", "RK", para); string IODNum = para.Value.ToString(); //添加出库记录 db.InOutDepot.Add(new InOutDepot() { DepotID = st.DepotID, IODType = 2, IODNum = IODNum, IODDate = DateTime.Now, IODUser = userid, IODDesc = st.LostDesc }); db.SaveChanges(); int inod = db.InOutDepot.Max(i => i.IODID); List <LostDetail> list = db.LostDetail.Where(p => p.LostID.Equals(id)).ToList();//销售出库详单 foreach (LostDetail item in list) { if (db.DepotStock.FirstOrDefault(p => p.DepotID.Equals(st.DepotID) && p.ProID == item.ProID) == null) {//如果指定的仓库中不存在该商品 throw new Exception("报损仓库不存在该商品,操作失败!"); } else {//如果指定仓库存在这个商品,修改这个商品的库存 DepotStock ds = db.DepotStock.FirstOrDefault(d => d.ProID == item.ProID); if (ds.DSAmount < item.LDAmount) { throw new Exception("商品库存小于报损数量,操作失败!"); } ds.DSAmount = ds.DSAmount - item.LDAmount; } //添加入库记录详情 db.InOutDepotDetail.Add(new InOutDepotDetail() { IODID = inod, ProID = item.ProID, IODDAmount = item.LDAmount, IODDPrice = item.LDPrice }); } db.SaveChanges(); tx.Commit(); } catch (Exception e) { tx.Rollback(); throw new Exception(e.Message); } } return(fg); }
/// <summary> /// 修改订单 /// </summary> /// <param name="pd"></param> /// <param name="list"></param> /// <returns></returns> public ActionResult Edit(Losts pd, List <LostDetail> list) { if (LostsBLL.EdiStocks(pd, list) > 0) { return(Content("edit_yes")); } else { return(Content("edit_no")); } }
/// <summary> /// 添加订单 /// </summary> /// <param name="pd"></param> /// <param name="list"></param> /// <returns></returns> public ActionResult Add(Losts pd, List <LostDetail> list) { pd.UserID = Convert.ToInt32(Session["uid"]); if (LostsBLL.AddStocks(pd, list) > 0) { return(Content("add_yes")); } else { return(Content("add_no")); } }
public void GetTest() { Losts v = new Losts(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.LostID = "sWTrOWsWR"; v.DepotsID = AddDepots(); v.LostDesc = "Pzf0KpTYy"; v.LostState = SCMSupplyChain.Model.LostState.未定义1; context.Set <Losts>().Add(v); context.SaveChanges(); } var rv = _controller.Get(v.ID.ToString()); Assert.IsNotNull(rv); }
public void EditTest() { Losts v = new Losts(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.LostID = "sWTrOWsWR"; v.DepotsID = AddDepots(); v.LostDesc = "Pzf0KpTYy"; v.LostState = SCMSupplyChain.Model.LostState.未定义1; context.Set <Losts>().Add(v); context.SaveChanges(); } LostsVM vm = _controller.Wtm.CreateVM <LostsVM>(); var oldID = v.ID; v = new Losts(); v.ID = oldID; v.LostID = "Gm3F7ECaV"; v.LostDesc = "6iJgee"; v.LostState = SCMSupplyChain.Model.LostState.未定义1; vm.Entity = v; vm.FC = new Dictionary <string, object>(); vm.FC.Add("Entity.LostID", ""); vm.FC.Add("Entity.DepotsID", ""); vm.FC.Add("Entity.LostDesc", ""); vm.FC.Add("Entity.LostState", ""); var rv = _controller.Edit(vm); Assert.IsInstanceOfType(rv, typeof(OkObjectResult)); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <Losts>().Find(v.ID); Assert.AreEqual(data.LostID, "Gm3F7ECaV"); Assert.AreEqual(data.LostDesc, "6iJgee"); Assert.AreEqual(data.LostState, SCMSupplyChain.Model.LostState.未定义1); Assert.AreEqual(data.UpdateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.UpdateTime.Value).Seconds < 10); } }
public int UpdateLosts([FromBody] Losts s) { return(s.UpdateLosts(s)); }
public int PostNewLosts([FromBody] Losts s) { return(s.PostNewLosts(s)); }
public List <Losts> GetMyLosts(int userId) { Losts s = new Losts(); return(s.GetMyLosts(userId)); }
public List <Losts> GetAllLosts(string neiName) { Losts s = new Losts(); return(s.GetAllLosts(neiName)); }
/// <summary> /// 修改【---事务---】 /// </summary> /// <param name="dp"></param> /// <returns></returns> public static int EdiStocks(Losts dep, List <LostDetail> list) { return(LostsDAL.EdiStocks(dep, list)); }