Example #1
0
        /// <summary>
        /// 收货地址详情
        /// </summary>
        /// <param name="addressId">地址ID</param>
        /// <param name="appId">appId</param>
        /// <returns></returns>
        public Jinher.AMP.BTP.Deploy.CustomDTO.AddressSDTO GetDeliveryAddressByAddressIdExt(System.Guid addressId, System.Guid appId)
        {
            var         deliveryAddress = DeliveryAddress.ObjectSet().Where(n => n.Id == addressId).FirstOrDefault();
            AddressSDTO address         = new AddressSDTO();

            if (deliveryAddress != null)
            {
                address.AddressId         = deliveryAddress.Id;
                address.UserId            = deliveryAddress.UserId;
                address.ReceiptUserName   = deliveryAddress.RecipientsUserName;
                address.ReceiptPhone      = deliveryAddress.RecipientsPhone;
                address.ReceiptAddress    = deliveryAddress.RecipientsAddress;
                address.Province          = deliveryAddress.Province;
                address.City              = deliveryAddress.City;
                address.District          = deliveryAddress.District;
                address.Street            = deliveryAddress.Street;
                address.AppId             = deliveryAddress.AppId;
                address.RecipientsZipCode = deliveryAddress.RecipientsZipCode;
                address.IsDefault         = deliveryAddress.IsDefault == true ? 1 : 0;
                address.ProvinceCode      = deliveryAddress.ProvinceCode;
                address.CityCode          = deliveryAddress.CityCode;
                address.DistrictCode      = deliveryAddress.DistrictCode;
                address.StreetCode        = deliveryAddress.StreetCode;
            }



            return(address);
        }
Example #2
0
        /// <summary>
        /// 删除收货地址
        /// </summary>
        /// <param name="addressId">地址ID</param>
        /// <param name="appId">appId</param>
        /// <returns></returns>
        public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO DeleteDeliveryAddressExt(System.Guid addressId, System.Guid appId)
        {
            ContextSession contextSession = ContextFactory.CurrentThreadContext;

            try
            {
                var address = DeliveryAddress.ObjectSet().Where(n => n.Id == addressId).FirstOrDefault();

                if (address != null)
                {
                    address.EntityState = System.Data.EntityState.Deleted;
                    contextSession.SaveObject(address);
                    contextSession.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("删除收货地址服务异常。addressId:{0}。appId:{1}", addressId, appId), ex);
                return(new ResultDTO {
                    ResultCode = 1, Message = "Error"
                });
            }
            return(new ResultDTO {
                ResultCode = 0, Message = "Success"
            });
        }
Example #3
0
        /// <summary>
        /// 获取收货地址列表
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="appId">appId</param>
        /// <returns></returns>
        public System.Collections.Generic.List <Jinher.AMP.BTP.Deploy.CustomDTO.AddressSDTO> GetDeliveryAddressExt
            (System.Guid userId, System.Guid appId)
        {
            var deliveryAddress = DeliveryAddress.ObjectSet().Where(n => n.UserId == userId).Select(
                n => new AddressSDTO
            {
                UserId            = n.UserId,
                ReceiptUserName   = n.RecipientsUserName,
                ReceiptPhone      = n.RecipientsPhone,
                ReceiptAddress    = n.RecipientsAddress,
                Province          = n.Province,
                City              = n.City,
                District          = n.District,
                Street            = n.Street,
                AppId             = n.AppId,
                AddressId         = n.Id,
                RecipientsZipCode = n.RecipientsZipCode,
                ProvinceCode      = n.ProvinceCode,
                CityCode          = n.CityCode,
                DistrictCode      = n.DistrictCode,
                StreetCode        = n.StreetCode
            }).ToList();


            return(deliveryAddress);
        }
Example #4
0
        /// <summary>
        /// 删除收货地址
        /// </summary>
        /// <param name="id">地址ID</param>
        public void DeleteDeliveryAddressExt(System.Guid id)
        {
            ContextSession  contextSession  = ContextFactory.CurrentThreadContext;
            DeliveryAddress deliveryAddress = DeliveryAddress.ObjectSet().Where(n => n.Id == id).FirstOrDefault();

            if (!string.IsNullOrEmpty(deliveryAddress.ToString()))
            {
                contextSession.Delete(deliveryAddress);
            }
            contextSession.SaveChange();
        }
Example #5
0
        /// <summary>
        /// 获取收货地址列表
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="appId">appId</param>
        /// <param name="IsDefault">是否默认收货地址</param>
        /// <returns></returns>
        public System.Collections.Generic.List <Jinher.AMP.BTP.Deploy.CustomDTO.AddressSDTO> GetDeliveryAddressListExt
            (System.Guid userId, System.Guid appId, int IsDefault = 0)
        {
            // bool isde = IsDefault == 0 ? false : true;
            var aa = DeliveryAddress.ObjectSet().Where(n => n.UserId == userId).OrderByDescending(n => n.IsDefault).ThenByDescending(n => n.SubTime).Select(
                n => new AddressSDTO
            {
                UserId            = n.UserId,
                ReceiptUserName   = n.RecipientsUserName,
                ReceiptPhone      = n.RecipientsPhone,
                ReceiptAddress    = n.RecipientsAddress,
                Province          = n.Province,
                City              = n.City,
                District          = n.District,
                Street            = n.Street,
                AppId             = n.AppId,
                AddressId         = n.Id,
                RecipientsZipCode = n.RecipientsZipCode,
                IsDefault         = (n.IsDefault == true ? 1 : 0),
                ProvinceCode      = n.ProvinceCode,
                CityCode          = n.CityCode,
                DistrictCode      = n.DistrictCode,
                StreetCode        = n.StreetCode
            });
            List <AddressSDTO> deliveryAddress = new List <AddressSDTO>();

            foreach (var addressSdto in aa)
            {
                deliveryAddress.Add(addressSdto);
            }

            //如果没有默认收货地址 获取最新添加的收货地址
            if (IsDefault == 1 && deliveryAddress != null && deliveryAddress.Count() > 0)
            {
                var deliveryAddressnew = deliveryAddress.Where(n => n.IsDefault == IsDefault).ToList();

                if (deliveryAddressnew == null || deliveryAddressnew.Count() == 0)
                {
                    System.Collections.Generic.List <AddressSDTO> list = new System.Collections.Generic.List <AddressSDTO>();
                    list.Add(deliveryAddress.FirstOrDefault());
                    deliveryAddress = list;
                }
                else
                {
                    deliveryAddress = deliveryAddressnew;
                }
            }
            return(deliveryAddress);
        }
Example #6
0
        /// <summary>
        /// 添加收货地址
        /// </summary>
        /// <param name="addressDTO">地址实体</param>
        /// <param name="appId">APPId</param>
        /// <returns></returns>
        public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO SaveDeliveryAddressExt(Jinher.AMP.BTP.Deploy.CustomDTO.AddressSDTO addressDTO)
        {
            try
            {
                ResultDTO result = ValidAddress(addressDTO);
                if (result.ResultCode != 0)
                {
                    return(result);
                }

                DeliveryAddressDTO deliveryAddressDTO = new DeliveryAddressDTO();
                ContextSession     contextSession     = ContextFactory.CurrentThreadContext;
                deliveryAddressDTO.EntityState        = System.Data.EntityState.Added;
                deliveryAddressDTO.Id                 = Guid.NewGuid();
                deliveryAddressDTO.AppId              = addressDTO.AppId;
                deliveryAddressDTO.Name               = "收货地址";
                deliveryAddressDTO.RecipientsUserName = addressDTO.ReceiptUserName;
                deliveryAddressDTO.UserId             = addressDTO.UserId;
                deliveryAddressDTO.RecipientsPhone    = addressDTO.ReceiptPhone;
                deliveryAddressDTO.RecipientsAddress  = addressDTO.ReceiptAddress;
                deliveryAddressDTO.Province           = addressDTO.Province;
                deliveryAddressDTO.City               = addressDTO.City;
                deliveryAddressDTO.District           = addressDTO.District;
                deliveryAddressDTO.Street             = addressDTO.Street;
                deliveryAddressDTO.ProvinceCode       = addressDTO.ProvinceCode;
                deliveryAddressDTO.CityCode           = addressDTO.CityCode;
                deliveryAddressDTO.DistrictCode       = addressDTO.DistrictCode;
                deliveryAddressDTO.StreetCode         = addressDTO.StreetCode;
                deliveryAddressDTO.RecipientsZipCode  = addressDTO.RecipientsZipCode;
                deliveryAddressDTO.IsDefault          = addressDTO.IsDefault == 1 ? true : false;
                DeliveryAddress deliveryAddress = new DeliveryAddress().FromEntityData(deliveryAddressDTO);
                if (addressDTO.IsDefault == 1)
                {
                    DeliveryAddress.ObjectSet().Context.ExecuteStoreCommand("update DeliveryAddress  set IsDefault=0 where UserId='" + deliveryAddress.UserId + "'");
                }
                contextSession.SaveObject(deliveryAddress);
                contextSession.SaveChanges();
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("添加收货地址服务异常。addressDTO:{0}", JsonHelper.JsonSerializer(addressDTO)), ex);
                return(new ResultDTO {
                    ResultCode = 1, Message = "添加收货地址异常!"
                });
            }
            return(new ResultDTO {
                ResultCode = 0, Message = "Success"
            });
        }
Example #7
0
        /// <summary>
        /// 编辑收货地址 设置默认地址
        /// </summary>
        /// <param name="addressId">地址ID</param>
        /// <returns></returns>
        public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO UpdateDeliveryAddressIsDefaultExt(System.Guid addressId)
        {
            ContextSession contextSession = ContextFactory.CurrentThreadContext;

            try
            {
                var address = DeliveryAddress.ObjectSet().FirstOrDefault(n => n.Id == addressId);

                if (address != null)
                {
                    if (!address.IsDefault)
                    {
                        var alist = DeliveryAddress.ObjectSet().Where(t => t.UserId == address.UserId && t.Id != addressId);
                        foreach (var a in alist)
                        {
                            a.IsDefault   = false;
                            a.EntityState = System.Data.EntityState.Modified;
                            contextSession.SaveObject(a);
                        }
                        address.IsDefault = true;
                    }
                    else
                    {
                        address.IsDefault = false;
                    }

                    address.EntityState = System.Data.EntityState.Modified;
                    contextSession.SaveObject(address);
                    contextSession.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("编辑收货地址服务异常。addressId:{0}。", addressId), ex);
                return(new ResultDTO {
                    ResultCode = 1, Message = "Error"
                });
            }
            return(new ResultDTO {
                ResultCode = 0, Message = "Success"
            });
        }
Example #8
0
        /// <summary>
        /// 查询用户收货地址
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <returns></returns>
        public System.Collections.Generic.List <Jinher.AMP.BTP.Deploy.DeliveryAddressDTO> GetAllDeliveryAddressExt(System.Guid userId)
        {
            DeliveryAddressDTO dto = new DeliveryAddressDTO();
            var deliveryAddress    = DeliveryAddress.ObjectSet().Where(n => n.UserId.Equals(userId));
            var result             = from d in deliveryAddress
                                     select new DeliveryAddressDTO
            {
                AppId              = d.AppId,
                City               = d.City,
                Code               = d.Code,
                District           = d.District,
                Id                 = d.Id,
                IsDefault          = d.IsDefault,
                Name               = d.Name,
                Province           = d.Province,
                RecipientsAddress  = d.RecipientsAddress,
                RecipientsPhone    = d.RecipientsPhone,
                RecipientsUserName = d.RecipientsUserName,
                UserId             = d.UserId
            };

            return(result.ToList());
        }
Example #9
0
        /// <summary>
        /// 保存(添加或修改)收货地址
        /// <para>Service Url: http://devbtp.sv.iuoooo.com/Jinher.AMP.BTP.SV.DeliveryAddressSV.svc/SaveDeliveryAddressNew
        /// </para>
        /// </summary>
        /// <param name="addressDTO">地址实体</param>
        /// <returns></returns>
        public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO SaveDeliveryAddressNewExt(Jinher.AMP.BTP.Deploy.CustomDTO.AddressSDTO addressDTO)
        {
            try
            {
                ResultDTO result = ValidAddressNew(addressDTO);
                if (result.ResultCode != 0)
                {
                    return(result);
                }

                ContextSession contextSession = ContextFactory.CurrentThreadContext;

                DeliveryAddress deliveryAddress = null;
                if (addressDTO.AddressId != Guid.Empty)
                {
                    deliveryAddress = DeliveryAddress.ObjectSet().Where(n => n.Id == addressDTO.AddressId).FirstOrDefault();
                }

                if (deliveryAddress == null)
                {
                    deliveryAddress    = DeliveryAddress.CreateDeliveryAddress();
                    deliveryAddress.Id = Guid.NewGuid();
                }
                else
                {
                    deliveryAddress.EntityState = System.Data.EntityState.Modified;
                }
                deliveryAddress.Name = "";
                if (addressDTO.UserId != Guid.Empty)
                {
                    deliveryAddress.UserId = addressDTO.UserId;
                }

                deliveryAddress.AppId = addressDTO.AppId;
                deliveryAddress.RecipientsUserName = addressDTO.ReceiptUserName;
                deliveryAddress.RecipientsPhone    = addressDTO.ReceiptPhone;
                deliveryAddress.RecipientsAddress  = addressDTO.ReceiptAddress;
                deliveryAddress.Province           = addressDTO.Province;
                deliveryAddress.City              = addressDTO.City;
                deliveryAddress.District          = addressDTO.District;
                deliveryAddress.Street            = addressDTO.Street;
                deliveryAddress.RecipientsZipCode = addressDTO.RecipientsZipCode;
                deliveryAddress.ProvinceCode      = addressDTO.ProvinceCode;
                deliveryAddress.CityCode          = addressDTO.CityCode;
                deliveryAddress.DistrictCode      = addressDTO.DistrictCode;
                deliveryAddress.StreetCode        = addressDTO.StreetCode;
                deliveryAddress.IsDefault         = addressDTO.IsDefault == 1 ? true : false;
                if (addressDTO.IsDefault == 1)
                {
                    DeliveryAddress.ObjectSet().Context.ExecuteStoreCommand("update DeliveryAddress  set IsDefault=0 where UserId='" + deliveryAddress.UserId + "'");
                }
                contextSession.SaveObject(deliveryAddress);
                contextSession.SaveChanges();
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("SaveDeliveryAddressNewExt异常。addressDTO:{0},异常信息:{1}", addressDTO, ex));
                return(new ResultDTO {
                    ResultCode = 1, Message = "Error"
                });
            }
            return(new ResultDTO {
                ResultCode = 0, Message = "Success"
            });
        }
Example #10
0
        /// <summary>
        /// 查询一条收货地址
        /// </summary>
        /// <param name="id">地址ID</param>
        /// <returns></returns>
        public Jinher.AMP.BTP.Deploy.DeliveryAddressDTO GetDeliveryAddressExt(System.Guid id)
        {
            DeliveryAddress deliveryAddress = DeliveryAddress.ObjectSet().Where(n => n.Id == id).FirstOrDefault();

            return(deliveryAddress.ToEntityData());
        }