Ejemplo n.º 1
0
        public async Task <List <DeliveryAddressDTO> > GetLstDeliveryAddress(string userId)
        {
            var pUserId = Guid.Parse(userId);
            var output  = new List <DeliveryAddressDTO>();

            try
            {
                var result = await HanomaContext.DeliveryAddress.Where(p => p.UserId == pUserId).OrderByDescending(x => x.IsDefault).ToListAsync();

                if (result != null)
                {
                    foreach (var p in result)
                    {
                        DeliveryAddressDTO item = new DeliveryAddressDTO();
                        item.Id           = p.Id;
                        item.UserId       = userId;
                        item.UserName     = p.UserName;
                        item.PhoneNumber  = p.PhoneNumber;
                        item.LocationId   = p.LocationId;
                        item.DistrictId   = p.DistrictId;
                        item.Address      = p.Address;
                        item.IsDefault    = p.IsDefault;
                        item.LocationName = HanomaContext.Location.FirstOrDefault(x => x.Location_ID == p.LocationId)?.Name;
                        item.DistrictName = HanomaContext.District.FirstOrDefault(x => x.Id == p.DistrictId)?.Name;
                        output.Add(item);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(output);
        }
Ejemplo n.º 2
0
        public void AddDeliveryAddress(DeliveryAddressDTO model)
        {
            var da = DeliveryAddressFactory.CreateInstance(model.UserId, model.LinkMan, model.Gender, model.Mobile, model.Mark, model.IsDefault, model.Province, model.City, model.Area, model.StreetAddress, model.Postcode, model.CreatedBy);

            _deliveryAddressRepository.Add(da);
            _dbUnitOfWork.Commit();
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> SetDeliveryAddress([FromBody] DeliveryAddressDTO postedAddress)
        {
            var address        = mapper.Map <DeliveryAddress>(postedAddress);
            var deliveryTotals = await service.SetDeliveryAddress(address);

            var deliveryTotalsDto = mapper.Map <CheckoutPageDeliveryTotalsDTO>(deliveryTotals);

            return(ResponseJson(deliveryTotalsDto));
        }
Ejemplo n.º 4
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"
            });
        }
Ejemplo n.º 5
0
        public async Task <DeliveryAddressDTO> DeleteDeliveryAddress(int Id, string UserId)
        {
            var output = new DeliveryAddressDTO();
            var result = await _repoWrapper.ShoppingCart.DeleteDeliveryAddress(Id, UserId);

            if (result)
            {
                output.ErrorCode = "00";
                output.Message   = "Xóa thành công";
            }
            else
            {
                output.ErrorCode = "01";
                output.Message   = "Có lỗi trong quá trình xóa";
            }
            return(output);
        }
Ejemplo n.º 6
0
        public async Task <DeliveryAddressDTO> PostDeliveryAddress(DeliveryAddressDTO model)
        {
            var output = new DeliveryAddressDTO();
            var result = await _repoWrapper.ShoppingCart.PostDeliveryAddress(model);

            if (result)
            {
                output.ErrorCode = "00";
                output.Message   = "Thêm mới địa chỉ thành công";
            }
            else
            {
                output.ErrorCode = "01";
                output.Message   = "Có lỗi trong quá trình cập nhật";
            }
            return(output);
        }
Ejemplo n.º 7
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());
        }
Ejemplo n.º 8
0
 public void Post([FromBody] DeliveryAddressDTO value)
 {
     value.UserId = value.CreatedBy = UserId;
     _deliveryAddressAppService.AddDeliveryAddress(value);
 }
Ejemplo n.º 9
0
        public async Task <bool> PostDeliveryAddress(DeliveryAddressDTO model)
        {
            try
            {
                if (model != null)
                {
                    var pUserId = Guid.Parse(model.UserId);
                    var item    = await HanomaContext.DeliveryAddress.FirstOrDefaultAsync(p => p.Id == model.Id && p.CreateBy == pUserId);

                    if (item == null)
                    {
                        //Add Delivery
                        var addItem = new DeliveryAddress();
                        addItem.UserId       = pUserId;
                        addItem.UserName     = model.UserName;
                        addItem.PhoneNumber  = model.PhoneNumber;
                        addItem.LocationId   = model.LocationId;
                        addItem.DistrictId   = model.DistrictId;
                        addItem.Address      = model.Address;
                        addItem.IsDefault    = model.IsDefault;
                        addItem.CreateBy     = pUserId;
                        addItem.CreateDate   = DateTime.Now;
                        addItem.LastEditBy   = pUserId;
                        addItem.LastEditDate = DateTime.Now;
                        HanomaContext.DeliveryAddress.Add(addItem);
                        await HanomaContext.SaveChangesAsync();

                        //Update Default
                        if (model.IsDefault == true)
                        {
                            var lstItem = await HanomaContext.DeliveryAddress.Where(p => p.CreateBy == pUserId).ToListAsync();

                            foreach (var p in lstItem)
                            {
                                if (p.Id == addItem.Id)
                                {
                                    continue;
                                }
                                var pItem = await HanomaContext.DeliveryAddress.FirstOrDefaultAsync(x => x.Id == p.Id);

                                pItem.IsDefault = false;
                                await HanomaContext.SaveChangesAsync();
                            }
                        }
                    }
                    else
                    {
                        //Update
                        item.UserName     = model.UserName;
                        item.PhoneNumber  = model.PhoneNumber;
                        item.LocationId   = model.LocationId;
                        item.DistrictId   = model.DistrictId;
                        item.Address      = model.Address;
                        item.IsDefault    = model.IsDefault;
                        item.LastEditBy   = pUserId;
                        item.LastEditDate = DateTime.Now;
                        await HanomaContext.SaveChangesAsync();

                        //Update Default
                        if (model.IsDefault == true)
                        {
                            var lstItem = await HanomaContext.DeliveryAddress.Where(p => p.CreateBy == pUserId).ToListAsync();

                            foreach (var p in lstItem)
                            {
                                if (p.Id == model.Id)
                                {
                                    continue;
                                }
                                var pItem = await HanomaContext.DeliveryAddress.FirstOrDefaultAsync(x => x.Id == p.Id);

                                pItem.IsDefault = false;
                                await HanomaContext.SaveChangesAsync();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
        }