protected int _AddCart(string pno, int qty) { int ret = 0; if (!string.IsNullOrEmpty(pno) && CurrentUser != null) { Domain.Models.Product.PROD_MASTER prod = PROD_MASTERService.GetProduct(pno); if (prod != null) { if (CurrentUser.AccountInfo != null) { string unitPriceType = string.Empty; double uPrice = 0; PROD_MASTERService.GetSellingPrice(prod.ProductNo, CurrentUser.AccountInfo.Account_no, out uPrice, out unitPriceType); if (uPrice == 0) { uPrice = (double)prod.ListPrice; } var model = new SALES_EBASKETModel { ID = Quick.Framework.Tool.CombHelper.NewComb().ToString(), ContactID = CurrentUser.Id, CreateDate = DateTime.Now, Creator = CurrentUser.AccountInfo.Account_no, CustomerID = CurrentUser.AccountInfo.Account_no,//request ModiDate = DateTime.Now, Modifier = CurrentUser.AccountInfo.Account_no, ProductNo = prod.ProductNo, Quantity = Convert.ToDouble(qty), Unit = prod.BaseUOFM, UnitPrice = uPrice, UnitPType = unitPriceType, Status = 0, MakeOrderID = "", }; if ((bool)CurrentUser.IsContractLimit && unitPriceType != "L") //only to purchase contract goods { if (unitPriceType == "S") //Special Price { bool hasContractPrice = SALES_CONTRACTPRICEService.IsExist(CurrentUser.AccountInfo.Account_no, prod.ProductNo); if (!hasContractPrice) { return(-10); //return Json(new { success = false, message = "You need to purchase contract goods." }); } } } ret = SALES_EBASKETService.ModificationCart(model); //成功了 //ret = SALES_EBASKETService.ModificationByProce(model);//有问题不可以使用 } } } return(ret); }
public int ModificationCart(SALES_EBASKETModel model) { var entity = SALES_EBASKETList.ToList().Where(t => t.CustomerID == model.CustomerID && t.ContactID == model.ContactID && t.ProductNo == model.ProductNo && t.Status == 0).FirstOrDefault(); if (entity == null) { entity = new SALES_EBASKET { ID = CombHelper.NewComb().ToString(), CustomerID = model.CustomerID, ContactID = model.ContactID, ProductNo = model.ProductNo, Quantity = model.Quantity, UnitPrice = model.UnitPrice, Unit = model.Unit, Creator = model.Creator, Modifier = model.Modifier, CreateDate = model.CreateDate, ModiDate = model.ModiDate, MakeOrderID = model.MakeOrderID, //RowID = model.RowID, Status = model.Status, UnitPType = model.UnitPType, }; return(SALES_EBASKETRepository.Insert(entity)); } else { //entity.ID = model.ID; //entity.CustomerID = model.CustomerID; //entity.ContactID = model.ContactID; //entity.ProductNo = model.ProductNo; entity.Quantity += model.Quantity; //entity.UnitPrice = model.UnitPrice; //entity.Unit = model.Unit; //entity.Creator = model.Creator; entity.Modifier = model.Modifier; //entity.CreateDate = model.CreateDate; entity.ModiDate = model.ModiDate; //entity.MakeOrderID = model.MakeOrderID; //entity.RowID = model.RowID; //entity.Status = model.Status; //entity.UnitPType = model.UnitPType; return(SALES_EBASKETRepository.Update(entity)); //这个是可以成功; 注意entity是通过entities集成读取 //return SALES_EBASKETRepository.Update(e => new { e.Quantity }, entity); //这个局部更新 } }
public OperationResult Insert(SALES_EBASKETModel model) { var entity = new SALES_EBASKET { ID = model.ID, CustomerID = model.CustomerID, ContactID = model.ContactID, ProductNo = model.ProductNo, Quantity = model.Quantity, UnitPrice = model.UnitPrice, Unit = model.Unit, Creator = model.Creator, Modifier = model.Modifier, CreateDate = model.CreateDate, ModiDate = model.ModiDate, MakeOrderID = model.MakeOrderID, RowID = model.RowID, Status = model.Status, UnitPType = model.UnitPType, }; SALES_EBASKETRepository.Insert(entity); return(new OperationResult(OperationResultType.Success, "Added successfully")); }
/// <summary> /// 使用存储过程更新, 但不知道怎样可以同步上下文; /// </summary> /// <param name="model"></param> /// <returns></returns> public int ModificationByProce(SALES_EBASKETModel model) { var entity = SALES_EBASKETRepository.EntitiesToList.Where(t => t.CustomerID == model.CustomerID && t.ContactID == model.ContactID && t.ProductNo == model.ProductNo && t.Status == 0).FirstOrDefault(); if (entity == null) { entity = new SALES_EBASKET { ID = CombHelper.NewComb().ToString(), CustomerID = model.CustomerID, ContactID = model.ContactID, ProductNo = model.ProductNo, Quantity = model.Quantity, UnitPrice = model.UnitPrice, Unit = model.Unit, Creator = model.Creator, Modifier = model.Modifier, CreateDate = model.CreateDate, ModiDate = model.ModiDate, MakeOrderID = model.MakeOrderID, //RowID = model.RowID, Status = model.Status, UnitPType = model.UnitPType, }; } else { //entity.ID = model.ID; entity.CustomerID = model.CustomerID; entity.ContactID = model.ContactID; entity.ProductNo = model.ProductNo; entity.Quantity = model.Quantity; entity.UnitPrice = model.UnitPrice; entity.Unit = model.Unit; //entity.Creator = model.Creator; entity.Modifier = model.Modifier; //entity.CreateDate = model.CreateDate; entity.ModiDate = model.ModiDate; entity.MakeOrderID = model.MakeOrderID; //entity.RowID = model.RowID; //entity.Status = model.Status; entity.UnitPType = model.UnitPType; } int ret = SALES_EBASKETRepository.ModificationByProce(entity); //这里刷新内存中数据集; //------------------------------- ////一直有问题不可以使用 //var entity_new = SALES_EBASKETRepository.EntitiesToList.Where(t => t.ID == entity.ID); //if (entity_new.Count() > 0) { SALES_EBASKETRepository.ReLoad(entity_new.FirstOrDefault()); } else //{ // SALES_EBASKETRepository.Add(entity); //} SALES_EBASKETRepository.Load(); //--------------------------------------- return(ret); }