private decimal getMaxAmount(decimal estimateAmount, int productType, int userLvl) { IBase_ProductInfo_DetailService base_ProductInfo_DetailService = BLLContainer.Resolve <IBase_ProductInfo_DetailService>(); decimal customerUpper = base_ProductInfo_DetailService.GetModels(p => p.ProductType == productType && p.UserLvl == userLvl).Max(m => (decimal?)m.CustomerUpper).GetValueOrDefault(); return(Math.Round(estimateAmount * customerUpper * 0.01M, 2, MidpointRounding.AwayFromZero)); }
public ActionResult DeleteProduct(int id) { string errMsg = "删除成功"; //开启EF事务 using (TransactionScope ts = new TransactionScope()) { try { IBase_ProductInfoService base_ProductInfoService = BLLContainer.Resolve <IBase_ProductInfoService>(); if (base_ProductInfoService.GetCount(p => p.ID == id) == 0) { errMsg = "该产品信息不存在"; return(RedirectToAction("Index", "ProductInfoManage", new { errMsg = errMsg })); } var base_ProductInfo = base_ProductInfoService.GetModels(p => p.ID == id).FirstOrDefault(); if (!base_ProductInfoService.Delete(base_ProductInfo)) { errMsg = "数据库更新失败"; return(RedirectToAction("Index", "ProductInfoManage", new { errMsg = errMsg })); } IBase_ProductInfo_DetailService base_ProductInfo_DetailService = BLLContainer.Resolve <IBase_ProductInfo_DetailService>(); var dbContext = DbContextFactory.CreateByModelNamespace(typeof(Base_ProductInfo_Detail).Namespace); var base_ProductInfo_Details = base_ProductInfo_DetailService.GetModels(p => p.ProductType == base_ProductInfo.ID).ToList(); foreach (var item in base_ProductInfo_Details) { dbContext.Entry(item).State = System.Data.Entity.EntityState.Deleted; } if (dbContext.SaveChanges() < 0) { errMsg = "数据库更新失败"; return(RedirectToAction("Index", "ProductInfoManage", new { errMsg = errMsg })); } ts.Complete(); } catch (Exception ex) { return(RedirectToAction("Index", "ProductInfoManage", new { errMsg = ex.Message })); } } //更新缓存 ProductTypeBusiness.Init(); return(RedirectToAction("Index", "ProductInfoManage", new { errMsg = errMsg })); }