Example #1
0
 /// <summary>
 /// 获取运费模板详细数据
 /// </summary>
 /// <param name="freightTemplateId">运费模板编号</param>
 /// <returns></returns>
 public List <FreightTemplateDetailDTO> GetFreightTemplateDetailListByTemIdExt(Guid freightTemplateId)
 {
     try
     {
         var query = (from data in FreightTemplateDetail.ObjectSet()
                      where data.FreightTemplateId == freightTemplateId
                      select new FreightTemplateDetailDTO()
         {
             Id = data.Id,
             FreightTo = data.FreightTo,
             FirstCount = data.FirstCount,
             FirstCountPrice = data.FirstCountPrice,
             NextCount = data.NextCount,
             NextCountPrice = data.NextCountPrice,
             FreightTemplateId = data.FreightTemplateId,
             DestinationCodes = data.DestinationCodes
         }).ToList();
         return(query);
     }
     catch (Exception ex)
     {
         LogHelper.Error(string.Format("获取运费模板详细数据。freightTemplateId:{0}", freightTemplateId), ex);
         return(null);
     }
 }
Example #2
0
 /// <summary>
 /// 保存运费及其明细
 /// </summary>
 /// <param name="freight">运费模板</param>
 /// <param name="freightDetailList">运费明细集合</param>
 /// <returns></returns>
 public ResultDTO AddFreightAndFreightDetailExt(FreightTemplateDTO freight, List <FreightTemplateDetailDTO> freightDetailList)
 {
     try
     {
         if (freight == null)
         {
             return(new ResultDTO {
                 ResultCode = 2, Message = "运费模板为null"
             });
         }
         ContextSession  contextSession = ContextFactory.CurrentThreadContext;
         FreightTemplate tem            = new FreightTemplate();
         Guid            ID             = Guid.NewGuid();
         tem.Id              = ID;
         tem.Name            = freight.Name;
         tem.FreightMethod   = freight.FreightMethod;
         tem.FreightTo       = freight.FreightTo;
         tem.FirstCount      = freight.FirstCount;
         tem.FirstCountPrice = freight.FirstCountPrice;
         tem.NextCount       = freight.NextCount;
         tem.NextCountPrice  = freight.NextCountPrice;
         tem.IsFreeExp       = freight.IsFreeExp;
         tem.AppId           = freight.AppId;
         tem.SubTime         = DateTime.Now;
         tem.ModifiedOn      = DateTime.Now;
         tem.EntityState     = System.Data.EntityState.Added;
         contextSession.SaveObject(tem);
         if (freightDetailList != null && freightDetailList.Count > 0)
         {
             FreightTemplateDetail ftDetail;
             foreach (FreightTemplateDetailDTO detail in freightDetailList)
             {
                 ftDetail    = new FreightTemplateDetail();
                 ftDetail.Id = Guid.NewGuid();
                 ftDetail.FreightTemplateId = ID;
                 ftDetail.FreightTo         = detail.FreightTo;
                 ftDetail.FirstCount        = detail.FirstCount;
                 ftDetail.FirstCountPrice   = detail.FirstCountPrice;
                 ftDetail.NextCount         = detail.NextCount;
                 ftDetail.NextCountPrice    = detail.NextCountPrice;
                 ftDetail.EntityState       = System.Data.EntityState.Added;
                 contextSession.SaveObject(ftDetail);
             }
         }
         contextSession.SaveChanges();
         return(new ResultDTO {
             ResultCode = 0, Message = ID.ToString()
         });
     }
     catch (Exception ex)
     {
         LogHelper.Error(string.Format("保存运费及其明细服务异常。freight:{0},freightDetailList:{1}", JsonHelper.JsonSerializer(freight), JsonHelper.JsonSerializer(freightDetailList)), ex);
         return(new ResultDTO {
             ResultCode = 1, Message = ex.Message
         });
     }
 }
Example #3
0
 /// <summary>
 /// 删除运费模板
 /// </summary>
 /// <param name="Id"></param>
 /// <returns></returns>
 public ResultDTO DeleteFreightExt(Guid Id)
 {
     try
     {
         ContextSession contextSession = ContextFactory.CurrentThreadContext;
         var            query          = FreightTemplateDetail.ObjectSet().Where(s => s.FreightTemplateId == Id).ToList();
         if (query != null && query.Count > 0)
         {
             foreach (FreightTemplateDetail detail in query)
             {
                 detail.EntityState = System.Data.EntityState.Deleted;
                 contextSession.Delete(detail);
             }
         }
         var fpfQuery = FreightPartialFree.ObjectSet().Where(fpf => fpf.FreightTemplateId == Id);
         if (fpfQuery.Any())
         {
             foreach (FreightPartialFree partialFree in fpfQuery)
             {
                 partialFree.EntityState = System.Data.EntityState.Deleted;
                 contextSession.Delete(partialFree);
             }
         }
         FreightTemplate tem = FreightTemplate.ObjectSet().Where(s => s.Id == Id).FirstOrDefault();
         if (tem != null)
         {
             tem.EntityState = System.Data.EntityState.Deleted;
             contextSession.Delete(tem);
         }
         contextSession.SaveChanges();
         return(new ResultDTO {
             ResultCode = 0, Message = "Success"
         });
     }
     catch (Exception ex)
     {
         LogHelper.Error(string.Format("删除运费模板服务异常。Id:{0}", Id), ex);
         return(new ResultDTO {
             ResultCode = 1, Message = ex.Message
         });
     }
 }
Example #4
0
 /// <summary>
 /// 删除一条模板明细
 /// </summary>
 /// <param name="freightDetailId"></param>
 /// <returns></returns>
 public ResultDTO DeleteFreightDetailExt(Guid freightDetailId)
 {
     try
     {
         ContextSession        contextSession = ContextFactory.CurrentThreadContext;
         FreightTemplateDetail detail         = FreightTemplateDetail.ObjectSet().Where(s => s.Id == freightDetailId).FirstOrDefault();
         if (detail != null)
         {
             detail.EntityState = System.Data.EntityState.Deleted;
             contextSession.Delete(detail);
         }
         contextSession.SaveChanges();
         return(new ResultDTO {
             ResultCode = 0, Message = "Success"
         });
     }
     catch (Exception ex)
     {
         LogHelper.Error(string.Format("删除一条模板明细服务异常。freightDetailId:{0}", freightDetailId), ex);
         return(new ResultDTO {
             ResultCode = 1, Message = ex.Message
         });
     }
 }
Example #5
0
        /// <summary>
        /// 增加一条运费明细
        /// </summary>
        /// <param name="freightDetail"></param>
        /// <returns></returns>
        public ResultDTO AddFreightDetailExt(FreightTemplateDetailDTO freightDetail)
        {
            try
            {
                if (freightDetail != null)
                {
                    ContextSession        contextSession = ContextFactory.CurrentThreadContext;
                    FreightTemplateDetail detail         = new FreightTemplateDetail();
                    Guid id = Guid.NewGuid();
                    detail.Id                = id;
                    detail.FreightTo         = freightDetail.FreightTo;
                    detail.FirstCount        = freightDetail.FirstCount;
                    detail.FirstCountPrice   = freightDetail.FirstCountPrice;
                    detail.NextCount         = freightDetail.NextCount;
                    detail.NextCountPrice    = freightDetail.NextCountPrice;
                    detail.FreightTemplateId = freightDetail.FreightTemplateId;

                    detail.EntityState = System.Data.EntityState.Added;
                    contextSession.SaveObject(detail);
                    contextSession.SaveChanges();
                    return(new ResultDTO {
                        ResultCode = 0, Message = id.ToString()
                    });
                }
                return(new ResultDTO {
                    ResultCode = 2, Message = "穿入的实体为null"
                });
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("服务异常。freightDetail:{0}", freightDetail), ex);
                return(new ResultDTO {
                    ResultCode = 1, Message = ex.Message
                });
            }
        }
Example #6
0
        /// <summary>
        /// 保存运费模板及其明细
        /// </summary>
        /// <param name="freightDTO">一个运费模板相关的所有信息</param>
        /// <returns></returns>
        public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO SaveFreightTemplateFullExt(Jinher.AMP.BTP.Deploy.CustomDTO.FreightTempFullDTO freightDTO)
        {
            ResultDTO result = new ResultDTO();

            try
            {
                #region 参数验证

                if (freightDTO == null)
                {
                    result.ResultCode = 2;
                    result.Message    = "参数错误,参数不能为空!";
                    return(result);
                }



                List <FreightTemplateDetailDTO> fdetailList = freightDTO.DetailList;
                List <FreightPartialFreeDTO>    pfList      = freightDTO.PartialFreeList;

                if (fdetailList != null && fdetailList.Any())
                {
                    foreach (FreightTemplateDetailDTO ftd in fdetailList)
                    {
                        if (string.IsNullOrWhiteSpace(ftd.DestinationCodes))
                        {
                            result.ResultCode = 4;
                            result.Message    = "参数错误,请指定区域!";
                            return(result);
                        }
                    }
                }

                if (pfList != null && pfList.Any())
                {
                    foreach (FreightPartialFreeDTO fpf in pfList)
                    {
                        if (string.IsNullOrWhiteSpace(fpf.DestinationCodes))
                        {
                            result.ResultCode = 5;
                            result.Message    = "参数错误,请指定包邮区域!";
                            return(result);
                        }
                    }
                }

                #endregion



                ContextSession contextSession = ContextFactory.CurrentThreadContext;


                FreightTemplate tem       = null;
                bool            isNewTemp = false;

                Guid tempId = freightDTO.Freight.Id;

                if (tempId != Guid.Empty)
                {
                    tem = FreightTemplate.ObjectSet().Where(s => s.Id == freightDTO.Freight.Id).FirstOrDefault();
                }
                else
                {
                    tempId    = Guid.NewGuid();
                    isNewTemp = true;

                    int existNameCount = (from ft in FreightTemplate.ObjectSet()
                                          where ft.Name == freightDTO.Freight.Name &&
                                          ft.AppId == freightDTO.Freight.AppId
                                          select ft.Id).Count();
                    if (existNameCount > 0)
                    {
                        result.ResultCode = 3;
                        result.Message    = "已存在相同名称的运费模板!";
                        return(result);
                    }
                }

                if (tem == null)
                {
                    tem       = new FreightTemplate();
                    isNewTemp = true;
                }


                //运费模板
                tem.FillWith(freightDTO.Freight);
                tem.Id         = tempId;
                tem.FreightTo  = string.IsNullOrWhiteSpace(freightDTO.Freight.FreightTo) ? "" : freightDTO.Freight.FreightTo;
                tem.ModifiedOn = DateTime.Now;

                if (isNewTemp)
                {
                    tem.SubTime     = DateTime.Now;
                    tem.EntityState = System.Data.EntityState.Added;
                    contextSession.SaveObject(tem);
                }

                IEnumerable <FreightTemplateDetail> detailListOri      = null;
                IEnumerable <FreightPartialFree>    partialFreeListOri = null;
                if (!isNewTemp)
                {
                    detailListOri = from ftd in FreightTemplateDetail.ObjectSet()
                                    where ftd.FreightTemplateId == tempId
                                    select ftd;
                    partialFreeListOri = from pf in FreightPartialFree.ObjectSet()
                                         where pf.FreightTemplateId == tempId
                                         select pf;
                }
                if (detailListOri == null)
                {
                    detailListOri = new List <FreightTemplateDetail>();
                }
                if (partialFreeListOri == null)
                {
                    partialFreeListOri = new List <FreightPartialFree>();
                }

                //模板详情。
                IEnumerable <Guid> detailIdsNew = new List <Guid>();

                if (fdetailList != null && fdetailList.Count > 0)
                {
                    detailIdsNew = from ftd in fdetailList select ftd.Id;
                    foreach (FreightTemplateDetailDTO detail in fdetailList)
                    {
                        bool isdetailNew = false;
                        FreightTemplateDetail ftDetail = detailListOri.Where(detOri => detOri.Id == detail.Id).FirstOrDefault();
                        if (ftDetail == null)
                        {
                            ftDetail    = new FreightTemplateDetail();
                            isdetailNew = true;
                        }
                        ftDetail.FillWith(detail);
                        ftDetail.FreightTemplateId = tempId;
                        if (isdetailNew)
                        {
                            ftDetail.Id          = Guid.NewGuid();
                            ftDetail.EntityState = System.Data.EntityState.Added;
                            contextSession.SaveObject(ftDetail);
                        }
                    }
                }

                //删除db中有,更新列表中没有的FreightTemplateDetail
                if (detailListOri.Any())
                {
                    var delDetails = from ftd in detailListOri
                                     where (!detailIdsNew.Contains(ftd.Id))
                                     select ftd;
                    if (delDetails.Any())
                    {
                        foreach (var det in delDetails)
                        {
                            det.EntityState = System.Data.EntityState.Deleted;
                        }
                    }
                }

                //部分包邮信息。
                IEnumerable <Guid> pfIdsNew = new List <Guid>();

                if (pfList != null && pfList.Count > 0)
                {
                    pfIdsNew = from pf in pfList select pf.Id;
                    foreach (FreightPartialFreeDTO fpfDto in pfList)
                    {
                        bool isFpfNew          = false;
                        FreightPartialFree fpf = partialFreeListOri.Where(detOri => detOri.Id == fpfDto.Id).FirstOrDefault();
                        if (fpf == null)
                        {
                            fpf      = new FreightPartialFree();
                            isFpfNew = true;
                        }
                        fpf.FillWith(fpfDto);
                        fpf.FreightTemplateId = tempId;

                        if (isFpfNew)
                        {
                            fpf.Id          = Guid.NewGuid();
                            fpf.EntityState = System.Data.EntityState.Added;
                            contextSession.SaveObject(fpf);
                        }
                    }
                }
                //删除db中有,更新列表中没有的FreightTemplateDetail
                if (partialFreeListOri.Any())
                {
                    var delpfs = from pf in partialFreeListOri
                                 where (!pfIdsNew.Contains(pf.Id))
                                 select pf;
                    if (delpfs.Any())
                    {
                        foreach (var det in delpfs)
                        {
                            det.EntityState = System.Data.EntityState.Deleted;
                        }
                    }
                }


                contextSession.SaveChanges();
                return(new ResultDTO {
                    ResultCode = 0, Message = tempId.ToString()
                });
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("SaveFreightTemplateFullExt服务异常。freightDTO:{0}", JsonHelper.JsonSerializer(freightDTO)), ex);
                return(new ResultDTO {
                    ResultCode = 1, Message = "保存运费模板及其明细服务异常!"
                });
            }
        }
Example #7
0
 /// <summary>
 /// 更新运费模板和运费详细信息列表
 /// </summary>
 /// <param name="freight"></param>
 /// <param name="freightDetailList"></param>
 /// <returns></returns>
 public ResultDTO UpdateFreightAndFreightDetailExt(FreightTemplateDTO freight, List <FreightTemplateDetailDTO> freightDetailList)
 {
     try
     {
         if (freight == null)
         {
             return(new ResultDTO {
                 ResultCode = 2, Message = "运费模板为null"
             });
         }
         ContextSession  contextSession = ContextFactory.CurrentThreadContext;
         FreightTemplate fTemplate      = FreightTemplate.ObjectSet().Where(s => s.Id == freight.Id).FirstOrDefault();
         fTemplate.Name            = freight.Name;
         fTemplate.IsFreeExp       = freight.IsFreeExp;
         fTemplate.FreightMethod   = freight.FreightMethod;
         fTemplate.FirstCount      = freight.FirstCount;
         fTemplate.FirstCountPrice = freight.FirstCountPrice;
         fTemplate.NextCount       = freight.NextCount;
         fTemplate.NextCountPrice  = freight.NextCountPrice;
         fTemplate.ModifiedOn      = DateTime.Now;
         fTemplate.EntityState     = System.Data.EntityState.Modified;
         contextSession.SaveObject(fTemplate);
         if (freightDetailList != null && freightDetailList.Count > 0)
         {
             FreightTemplateDetail detail;
             foreach (FreightTemplateDetailDTO ftDetail in freightDetailList)
             {
                 if (ftDetail.Id == Guid.Empty)
                 {
                     detail                   = new FreightTemplateDetail();
                     detail.FreightTo         = ftDetail.FreightTo;
                     detail.FirstCount        = ftDetail.FirstCount;
                     detail.FirstCountPrice   = ftDetail.FirstCountPrice;
                     detail.NextCount         = ftDetail.NextCount;
                     detail.NextCountPrice    = ftDetail.NextCountPrice;
                     detail.Id                = Guid.NewGuid();
                     detail.FreightTemplateId = fTemplate.Id;
                     detail.EntityState       = System.Data.EntityState.Added;
                     contextSession.SaveObject(detail);
                 }
                 else
                 {
                     detail = FreightTemplateDetail.ObjectSet().Where(s => s.Id == ftDetail.Id).FirstOrDefault();
                     if (detail != null)
                     {
                         detail.FreightTo       = ftDetail.FreightTo;
                         detail.FirstCount      = ftDetail.FirstCount;
                         detail.FirstCountPrice = ftDetail.FirstCountPrice;
                         detail.NextCount       = ftDetail.NextCount;
                         detail.NextCountPrice  = ftDetail.NextCountPrice;
                         detail.EntityState     = System.Data.EntityState.Modified;
                         contextSession.SaveObject(detail);
                     }
                 }
             }
         }
         contextSession.SaveChanges();
         return(new ResultDTO {
             ResultCode = 0, Message = "Success"
         });
     }
     catch (Exception ex)
     {
         LogHelper.Error(string.Format("更新运费及其明细服务异常。freight:{0},freightDetailList:{1}", JsonHelper.JsonSerializer(freight), JsonHelper.JsonSerializer(freightDetailList)), ex);
         return(new ResultDTO {
             ResultCode = 1, Message = ex.Message
         });
     }
 }