/// <summary> /// 保存区间运费模板及其明细 /// </summary> /// <param name="inputDTO"></param> /// <returns></returns> public Deploy.CustomDTO.ResultDTO SaveRangeFreightTemplateExt(Deploy.CustomDTO.RangeFreightTemplateInputDTO inputDTO) { var output = new ResultDTO(); if (inputDTO == null) { output.ResultCode = 2; output.Message = "参数错误, inputDTO 不能为空"; } try { if (inputDTO.TemplateId != Guid.Empty) { OnlyUpdateRangeFreightTemplate(inputDTO); } else { OnlyCreateRangeFreightTemplate(inputDTO); } output.isSuccess = true; } catch (Exception ex) { LogHelper.Error(string.Format("保存区间运费时出现异常.{0} input:{1}", ex.Message, JsonHelper.JsonSerializer(inputDTO)), ex); output.ResultCode = 3; output.Message = ex.Message; } return(output); }
/// <summary> /// 仅更新区间运费模板 /// </summary> /// <param name="inputDTO"></param> private void OnlyUpdateRangeFreightTemplate(Deploy.CustomDTO.RangeFreightTemplateInputDTO inputDTO) { if (inputDTO == null) { throw new ArgumentNullException("inputDTO"); } if (inputDTO.TemplateId == Guid.Empty) { throw new ArgumentException("inputDTO.TemplateId"); } var templateId = inputDTO.TemplateId; var template = FreightTemplate.ObjectSet().FirstOrDefault(predicate => predicate.Id == templateId); if (template == null) { throw new Exception(string.Format("未找到运费模板对象 FreightTemplateId: {0}", templateId)); } template.Name = inputDTO.Name; template.IsFreeExp = inputDTO.FreeExpress; template.ModifiedId = base.ContextDTO.LoginUserID; FreightRangeDetails.ObjectSet() .Where(predicate => predicate.TemplateId == templateId) .ToList() .ForEach(freight => freight.EntityState = System.Data.EntityState.Deleted); var context = ContextFactory.CurrentThreadContext; foreach (var group in inputDTO.Freights.GroupBy(selector => selector.IsSpecific)) { foreach (var freight in group) { var detail = FreightRangeDetails.CreateFreightRangeDetails(); detail.TemplateId = template.Id; detail.ProvinceCodes = freight.ProvinceCodes; detail.IsSpecific = freight.IsSpecific; detail.Min = freight.Min; detail.Max = freight.Max; detail.Cost = freight.Cost; context.SaveObject(detail); } } context.SaveObject(template); context.SaveChange(); }
public Deploy.CustomDTO.ResultDTO SaveRangeFreightTemplate(Deploy.CustomDTO.RangeFreightTemplateInputDTO freightDTO) { //定义返回值 Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO result; try { //调用代理方法 result = base.Channel.SaveRangeFreightTemplate(freightDTO); } catch { //抛异常 throw; } finally { //关链接 ChannelClose(); } //返回结果 return(result); }
/// <summary> /// 仅创建区间运费模板 /// </summary> /// <param name="inputDTO"></param> private void OnlyCreateRangeFreightTemplate(Deploy.CustomDTO.RangeFreightTemplateInputDTO inputDTO) { var context = ContextFactory.CurrentThreadContext; var template = FreightTemplate.CreateFreightTemplate(); template.AppId = inputDTO.AppId; template.SubId = base.ContextDTO.LoginUserID; template.Name = inputDTO.Name; template.IsFreeExp = inputDTO.FreeExpress; template.PricingMethod = 3; //按区间计价 template.SubTime = DateTime.Now; template.ExpressType = 0; template.FreightMethod = 0; template.FreightTo = ""; template.FirstCount = 0M; template.FirstCountPrice = 0M; template.NextCount = 0M; template.NextCountPrice = 0M; template.ModifiedOn = DateTime.Now; template.IsDefault = 0; context.SaveObject(template); foreach (var freight in inputDTO.Freights) { var detail = FreightRangeDetails.CreateFreightRangeDetails(); detail.TemplateId = template.Id; detail.ProvinceCodes = freight.ProvinceCodes; detail.IsSpecific = !string.IsNullOrEmpty(freight.ProvinceCodes); detail.Min = freight.Min; detail.Max = freight.Max; detail.Cost = freight.Cost; context.SaveObject(detail); } context.SaveChanges(); }
/// <summary> /// 保存区间运费模板及其明细 /// </summary> /// <param name="inputDTO"></param> /// <returns></returns> public Deploy.CustomDTO.ResultDTO SaveRangeFreightTemplate(Deploy.CustomDTO.RangeFreightTemplateInputDTO inputDTO) { base.Do(); return(this.SaveRangeFreightTemplateExt(inputDTO)); }