/// <summary> /// 添加运价信息 /// </summary> /// <param name="model">运价信息实体</param> /// <returns>返回1:添加成功</returns> public bool Add(Model.TicketStructure.TicketFreightInfo model) { bool IsResult = false; if (model.IsEnabled) { IList <EyouSoft.Model.TicketStructure.AvailablePackInfo> list = iBuyDal.GetAvailableInfo(DateTime.Now, model.Company.ID, model.RateType, model.NoGadHomeCityId); if (list != null && list.Count > 0) { EyouSoft.Model.TicketStructure.AvailablePackInfo AvailModel = (EyouSoft.Model.TicketStructure.AvailablePackInfo)list[0]; model.FreightBuyId = AvailModel.BuyId; IList <EyouSoft.Model.TicketStructure.AvailablePackInfo> list1 = new List <EyouSoft.Model.TicketStructure.AvailablePackInfo>(); EyouSoft.Model.TicketStructure.AvailablePackInfo AvaiModel1 = new EyouSoft.Model.TicketStructure.AvailablePackInfo(); AvaiModel1.BuyId = AvailModel.BuyId; AvaiModel1.PackType = AvailModel.PackType; AvaiModel1.AvailableNum = 1; list1.Add(AvaiModel1); AvaiModel1 = null; AvailModel = null; IsResult = idal.AddFreightInfo(model) > 0 ? true : false; if (IsResult) { IsResult = iBuyDal.SetAvailableNum(list1); } list1 = null; } list = null; } else { model.FreightBuyId = string.Empty; IsResult = idal.AddFreightInfo(model) > 0 ? true : false; } return(IsResult); }
/// <summary> /// 修改运价信息 /// </summary> /// <param name="model">运价信息实体</param> /// <returns>返回1:添加成功</returns> public bool Update(Model.TicketStructure.TicketFreightInfo model) { #region 当前运价修改之前的实体 Model.TicketStructure.TicketFreightInfo OldModel = GetModel(model.Id); if (OldModel == null) { return(false); } #endregion #region 购买记录变量 IList <EyouSoft.Model.TicketStructure.AvailablePackInfo> AvailableList = new List <EyouSoft.Model.TicketStructure.AvailablePackInfo>();//设置购买记录集合列表 EyouSoft.Model.TicketStructure.AvailablePackInfo AvaiModel1 = null; #endregion bool IsResult = false; //[新增时启用状态为关闭] if (model.IsEnabled && String.IsNullOrEmpty(model.FreightBuyId.Trim())) { #region 可用的套餐购买集合 IList <EyouSoft.Model.TicketStructure.AvailablePackInfo> list = iBuyDal.GetAvailableInfo(DateTime.Now, model.Company.ID, model.RateType, model.NoGadHomeCityId); #endregion if (list != null && list.Count > 0) { //常规的运价购买记录 IList <EyouSoft.Model.TicketStructure.AvailablePackInfo> CGeAvailabList = list.Where(Item => (Item.PackType == EyouSoft.Model.TicketStructure.PackageTypes.常规)).ToList(); //当前运价信息所属的类型的购买记录 IList <EyouSoft.Model.TicketStructure.AvailablePackInfo> CurrTypeAvailabList = list.Where(Item => (Item.PackType == model.BuyType)).ToList(); if ((CurrTypeAvailabList == null || CurrTypeAvailabList.Count == 0) && (CGeAvailabList == null || CGeAvailabList.Count == 0)) { return(false); // } EyouSoft.Model.TicketStructure.AvailablePackInfo AvailModel = null; if (CurrTypeAvailabList != null && CurrTypeAvailabList.Count > 0) //当前的购买类型的优先级高 { AvailModel = CurrTypeAvailabList[0]; } else { AvailModel = CGeAvailabList[0]; } CurrTypeAvailabList = null; CGeAvailabList = null; model.FreightBuyId = AvailModel.BuyId; AvaiModel1 = new EyouSoft.Model.TicketStructure.AvailablePackInfo(); AvaiModel1.BuyId = AvailModel.BuyId; AvaiModel1.PackType = AvailModel.PackType; AvaiModel1.AvailableNum = 1;//注:[此处设置为1在数据层处理为-1] AvailableList.Add(AvaiModel1); AvaiModel1 = null; AvailModel = null; list = null; } else { return(false); //当前没有可用的运价条数 } } else if (model.IsEnabled != OldModel.IsEnabled && model.FreightBuyId.Trim() != "") { AvaiModel1 = new EyouSoft.Model.TicketStructure.AvailablePackInfo(); AvaiModel1.BuyId = model.FreightBuyId; AvaiModel1.PackType = model.BuyType; if (model.IsEnabled) { AvaiModel1.AvailableNum = 1;//注:[此处设置为-1在数据层处理为+1] } else { AvaiModel1.AvailableNum = -1; } AvailableList.Add(AvaiModel1); AvaiModel1 = null; } OldModel = null; IsResult = idal.UpdateFreightInfo(model) > 0 ? true : false; if (IsResult && AvailableList.Count > 0) { IsResult = iBuyDal.SetAvailableNum(AvailableList); } AvailableList = null; return(IsResult); }