public void RemoveUserAddressAsync_GivenNull_ThrowsException()
        {
            UserAddressService addressService = new UserAddressService(CreateUserAddressMockRepository().Object);

            Func <Task> act = async() => await addressService.RemoveUserAddressAsync(null);

            act.Should().Throw <ArgumentNullException>();
        }
        public async Task GetAddressAsync_AddressNotExisting_ReturnsNull()
        {
            UserAddressService addressService = new UserAddressService(CreateUserAddressMockRepository().Object);

            var result = await addressService.GetAddressAsync("noAddressUser");

            result.Should().BeNull();
        }
        public void UpdateAdressAsync_GivenNull_ThrowsException()
        {
            var repositoryMock = CreateUserAddressMockRepository();
            UserAddressService addressService = new UserAddressService(repositoryMock.Object);

            Func <Task> act = async() => await addressService.UpdateAdressAsync(null);

            act.Should().Throw <ArgumentNullException>();
        }
        public async Task RemoveUserAddressAsync_Id_InvokesRepositoryRemoveAsync()
        {
            var repositoryMock = CreateUserAddressMockRepository();
            UserAddressService addressService = new UserAddressService(repositoryMock.Object);

            await addressService.RemoveUserAddressAsync("1");

            repositoryMock.Verify(p => p.RemoveAsync("1"), Times.Once);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取地址信息
        /// </summary>
        /// <returns></returns>
        protected string GetAddr(object pid)
        {
            UserAddress ua = UserAddressService.GetModel(Convert.ToInt32(pid));

            if (ua != null)
            {
                return(AreaInfoService.GetName(Convert.ToInt32(ua.qq)) + " " + AreaInfoService.GetName(Convert.ToInt32(ua.weixin)) + " " + AreaInfoService.GetName(Convert.ToInt32(ua.zipcode)) + " " + ua.address + " " + ua.addressDetail);
            }
            return("");
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 获取地址信息
        /// </summary>
        /// <returns></returns>
        protected string GetAddr(object pid)
        {
            UserAddress ua = UserAddressService.GetModel(Convert.ToInt32(pid));

            if (ua != null)
            {
                return(ua.zipcode + " " + ua.address);
            }
            return("");
        }
Ejemplo n.º 7
0
 public AddressController(bookstoreContext context,
                          CityServices cityServices,
                          UserAddressService userAddressService,
                          UserServices userServices,
                          IMapper mapper)
 {
     _context            = context;
     _cityServices       = cityServices;
     _userAddressService = userAddressService;
     _userServices       = userServices;
     _mapper             = mapper;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 收货人信息
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="recieveUser"></param>
        /// <param name="mobile"></param>
        /// <param name="address"></param>
        /// <returns></returns>
        protected string GetSend(object pid, object recieveUser, object mobile, object address)
        {
            UserAddress ua = UserAddressService.GetModel(Convert.ToInt32(pid));

            if (ua != null)
            {
                return("<a title='" + ua.relName + " " + ua.mobile + "/" + ua.tel + "  " + ua.qq + " " + ua.weixin + " " + ua.zipcode + " " + ua.address + "'>" + ua.relName + "/" + ua.mobile + "</a>");
            }
            else
            {
                return("<a title='" + mobile + " " + address + "'>" + recieveUser + "/" + mobile + "</a>");
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 获取地址列表
        /// </summary>
        /// <param name="openId"></param>
        /// <returns></returns>
        public AddressListsModel GetAddressList(int accountId)
        {
            var model       = new AddressListsModel();
            var GetUserInfo = IAccountService.GetById(accountId);//获取userId

            if (GetUserInfo != null)
            {
                // accountId = GetUserInfo.accountId;
                if (GetUserInfo.defaultAddressId != 0)
                {
                    model.defaultAddressId = GetUserInfo.defaultAddressId;
                    var DefGetAddressInfo = UserAddressService.GetById(model.defaultAddressId);
                    if (DefGetAddressInfo != null)
                    {
                        model.defaultDetailedAddress = DefGetAddressInfo.detailedAddress;
                        model.defaultMoblie          = DefGetAddressInfo.moblie;
                        model.defaultProvinceName    = DefGetAddressInfo.provinceName == null ? " " : DefGetAddressInfo.provinceName;
                        model.defaultRecipients      = DefGetAddressInfo.recipients;
                    }
                    else
                    {
                        model.defaultAddressId = 0;
                    }
                }
                else
                {
                    model.defaultAddressId = 0;
                }
            }

            var GetAddressInfo = UserAddressService.GetByAccountId(accountId);

            if (GetAddressInfo != null && GetAddressInfo.ModelList != null && GetAddressInfo.ModelList.Count > 0)
            {
                //地址列表赋值
                model.AddressList = GetAddressInfo.ModelList.ToList().Select(x => new AddressListModel()
                {
                    userAddressId   = x.userAddressId,
                    moblie          = x.moblie,
                    recipients      = x.recipients,
                    detailedAddress = x.detailedAddress,
                    city            = CityService.GetById(x.cityId) == null ? "" : CityService.GetById(x.cityId).Name,
                    province        = ProvinceService.GetById(x.provinceId) == null ? "" : ProvinceService.GetById(x.provinceId).Name,
                    ProvinceName    = x.provinceName,
                    zipCode         = x.zipCode
                }).ToList();

                return(model);
            }
            return(null);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 绑定信息
        /// </summary>
        private void BindData()
        {
            DataSet ds = AreaInfoService.GetList("parentId = 0");

            if (ds.Tables[0].Rows.Count > 0)
            {
                location_p.DataSource     = ds;
                location_p.DataTextField  = "areaName";
                location_p.DataValueField = "id";
                location_p.DataBind();
            }
            location_p.Items.Insert(0, new ListItem("请选择", "0"));
            location_c.Items.Insert(0, new ListItem("请选择", "0"));
            location_a.Items.Insert(0, new ListItem("请选择", "0"));
            UserAddress item = UserAddressService.GetModel(id);

            if (item != null)
            {
                ViewState["labelname"]   = item.addressDetail;
                ViewState["address"]     = item.address;
                ViewState["telephone"]   = item.tel;
                ViewState["mobile"]      = item.mobile;
                ViewState["name"]        = item.relName;
                location_p.SelectedValue = item.qq;

                location_c.Items.Clear();
                ds = AreaInfoService.GetList("parentId = " + location_p.SelectedValue);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    location_c.DataSource     = ds;
                    location_c.DataTextField  = "areaName";
                    location_c.DataValueField = "id";
                    location_c.DataBind();
                }
                location_c.Items.Insert(0, new ListItem("请选择", "0"));
                location_c.SelectedValue = item.weixin;

                location_a.Items.Clear();
                ds = AreaInfoService.GetList("parentId = " + location_c.SelectedValue);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    location_a.DataSource     = ds;
                    location_a.DataTextField  = "areaName";
                    location_a.DataValueField = "id";
                    location_a.DataBind();
                }
                location_a.Items.Insert(0, new ListItem("请选择", "0"));
                location_a.SelectedValue = item.zipcode;
            }
        }
Ejemplo n.º 11
0
        public void Ready(string orderNo)
        {
            Load();
            var user = UserInformation; //_securityHelper.GetCurrentUser();

            if (user != null)
            {
                var order = OrderService.GetByOrderNo(orderNo);
                if (orderNo != null)
                {
                    item         = order.item;
                    orderDetails = order.OrderDetails;
                    if (orderDetails != null)
                    {
                        foreach (var od in orderDetails)
                        {
                            quantity += od.quantity;
                            //amount += od.price * od.quantity;
                        }
                    }
                }
                var request = new UserAddressRequest();
                request.UserId   = user.UserId;
                request.PageSize = 20;
                var Address = UserAddressService.GetByUserId(request);
                if (Address != null && Address.TotalCount > 0)
                {
                    ListUserAddress = Address.ModelList.Select(x => new SelectModel()
                    {
                        Id = x.userAddressId, Name = GetAddress(x)
                    }).ToList();
                }
                if (item.provinceId > 0)
                {
                    ListCity = GetCity(item.provinceId).Select(x => new SelectModel()
                    {
                        Id = x.CityId, Name = x.Name
                    }).ToList();
                }
                Discount  = Math.Round(CountDiscount(Account.presentExp + Account.activatePoint, order.item.amount), 2);
                payAmount = order.item.amount - Discount;
            }
            ListProvince = GetProvinceAll().Select(x => new SelectModel()
            {
                Id = x.ProvinceId, Name = x.Name
            }).ToList();
        }
        public async Task GetAddressAsync_AddressExists_ReturnsAddressDTO()
        {
            UserAddressService addressService = new UserAddressService(CreateUserAddressMockRepository().Object);
            UserAddressDTO     addressDTO     = new UserAddressDTO
            {
                UserAddressId = "1",
                Address1      = "Example Street",
                Address2      = "Example House",
                City          = "Example City",
                ZipCode       = "11-111",
                State         = "Example State",
                Country       = "Example Country"
            };

            var result = await addressService.GetAddressAsync("1");

            result.Should().BeEquivalentTo(addressDTO);
        }
        public async Task UpdateAdressAsync_GivenAddress_InvokesRepositoryUpdateAsync()
        {
            var repositoryMock = CreateUserAddressMockRepository();
            UserAddressService addressService = new UserAddressService(repositoryMock.Object);
            UserAddressDTO     addressDTO     = new UserAddressDTO
            {
                UserAddressId = "1",
                Address1      = "Example Street",
                Address2      = "Example House",
                City          = "Example City",
                ZipCode       = "11-111",
                State         = "Example State",
                Country       = "Example Country"
            };

            await addressService.UpdateAdressAsync(addressDTO);

            repositoryMock.Verify(p => p.UpdateAsync(It.Is <UserAddress>(s => s.UserAddressId == "1")), Times.Once);
        }
        public async Task CreateAddressAsync_GivenAddress_InvokesRepositoryCreateAsync()
        {
            var mockRepository = CreateUserAddressMockRepository();
            UserAddressService addressService = new UserAddressService(mockRepository.Object);
            UserAddressDTO     addressDTO     = new UserAddressDTO
            {
                UserAddressId = "2",
                Address1      = "Example Street",
                Address2      = "Example House",
                City          = "Example City",
                ZipCode       = "11-111",
                State         = "Example State",
                Country       = "Example Country"
            };

            await addressService.CreateAddressAsync(addressDTO);

            mockRepository.Verify(s => s.CreateAsync(It.Is <UserAddress>(x => x.UserAddressId == "2")), Times.Once);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// A user relocates from one city to another. We need to process this move. This includes calls to numerous external subsystems. This is somewhat messy to look at, and thus our maintainability potential might suffer. By hiding the complexity behind a facade, we gain a lot.
        /// </summary>
        public static void Main()
        {
            var user = new { Name = "Clint" };

            // validate user:
            UserValidationService validationService = new UserValidationService();
            bool isUserValid = validationService.IsUserValid(user.Name);

            if (!isUserValid)
            {
                return;
            }

            UserAddressService userAddressService = new UserAddressService();
            var userAddress = userAddressService.GetAddress(user.Name);

            // confirm user's address
            GovernmentAddressService governmentAddressService = new GovernmentAddressService();
            bool addressCanBeConfirmed = governmentAddressService.CanConfirmAddress(user.Name, userAddress);

            if (!addressCanBeConfirmed)
            {
                return;
            }

            // mark user as moved in primary database
            DataBaseService dataBaseService = new DataBaseService();

            dataBaseService.UpdateUsersAddress(user.Name, userAddress);

            // indicate user's move in our data-warehouse
            DataWarehouseService dataWarehouseService = new DataWarehouseService();

            dataWarehouseService.RegisterUserRelocation(user.Name);

            // Lab - introduce a facade-class, that introduces a simpler interface in regards to the above service-calls.
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 订单详情
        /// </summary>
        /// <param name="quantity"></param>
        /// <param name="openId"></param>
        /// <returns></returns>
        public ListOrderDetail GetOrders(string orderNo)
        {
            var     model     = new ListOrderDetail();
            decimal totalAmt  = 0;
            var     orderInfo = OrderService.GetOrderNo(orderNo);

            if (orderInfo == null)
            {
                return(null);
            }
            else
            {
                model.payState        = orderInfo.orderState;
                model.recipients      = orderInfo.recipients == null ? " " : orderInfo.recipients;
                model.detailedAddress = orderInfo.detailedAddress == null ? " " : orderInfo.detailedAddress;
                model.moblie          = orderInfo.moblie == null ? " " : orderInfo.moblie;
                model.Remark          = orderInfo.remark == null ? " " : orderInfo.remark;
                model.orderState      = orderInfo.orderState;
                model.Freight         = orderInfo.freight;
                model.ExpressCompany  = orderInfo.ExpressCompany == null ? " " : orderInfo.ExpressCompany;
                model.ExpressNumber   = orderInfo.ExpressNumber == null ? " " : orderInfo.ExpressNumber;
                model.UserAddressId   = orderInfo.UserAddressId;
                model.orderNo         = orderInfo.orderNo;
            }
            var orderDtlInfo = OrderDetailService.GetAllByOrderNo(orderNo).ToList();

            if (orderDtlInfo != null)
            {
                foreach (var item in orderDtlInfo)
                {
                    var dtlModel  = new OrderDetailsModel();
                    var commodity = JuMeiMallService.GetById(item.commodityId);
                    if (commodity == null)
                    {
                        return(null);
                    }
                    if (commodity.commodityState == CommodityStates.soldOut)
                    {
                        return(null);
                    }
                    //数量

                    dtlModel.Image = GetFirstImage(commodity.images);

                    dtlModel.Id = item.commodityId;

                    dtlModel.Price = item.price;

                    dtlModel.quantity = item.quantity;

                    dtlModel.Title = commodity.commodityName;

                    dtlModel.specification = item.specification;
                    // totalAmt += commodity.commodityPrice * item.quantity;
                    //freight = commodity.commodityFreight;
                    model.OrderDetailsList.Add(dtlModel);
                }
            }
            model.TotalAmt = orderInfo.amount;
            model.Freight  = orderInfo.freight;
            var GetAddressInfo = UserAddressService.GetByAccountId(orderInfo.userId);

            if (GetAddressInfo != null && GetAddressInfo.ModelList != null && GetAddressInfo.ModelList.Count > 0)
            {
                //地址列表赋值
                model.ListUserAddress = GetAddressInfo.ModelList.ToList().Select(x => new UserAddress()
                {
                    userAddressId   = x.userAddressId,
                    moblie          = x.moblie,
                    recipients      = x.recipients,
                    detailedAddress = x.detailedAddress,
                    //city = CityService.GetById(x.cityId) == null ? "" : CityService.GetById(x.cityId).Name,
                    //province = ProvinceService.GetById(x.provinceId) == null ? "" : ProvinceService.GetById(x.provinceId).Name,
                    //ProvinceName = x.provinceName,
                    //zipCode = x.zipCode
                }).ToList();

                return(model);
            }
            return(model);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 付款后更新订单
        /// </summary>
        /// <param name="orderNo"></param>
        /// <param name="userAddressId"></param>
        /// <returns></returns>
        public ResultMessage UpdOrderPaid(string orderNo, int userAddressId, string remark, decimal totalAmt)
        {
            var tran = TransactionHelper.BeginTransaction();

            try
            {
                var userAddress = UserAddressService.GetById(userAddressId);
                if (userAddress == null)
                {
                    return new ResultMessage()
                           {
                               Code = -1, Msg = "订单数据地址录入有误,请截图并联系管理员,订单号:" + orderNo
                           }
                }
                ;

                var orderInfo = OrderService.GetOrderNo(orderNo);
                if (orderInfo == null)
                {
                    return new ResultMessage()
                           {
                               Code = -1, Msg = "订单数据丢失,请截图并联系管理员,订单号:" + orderNo
                           }
                }
                ;
                //if (totalAmt != orderInfo.amount + orderInfo.freight)
                //{
                //    return new ResultMessage() { Code = -1, Msg = "订单金额与订单不一致,请截图并联系管理员,订单号:" + orderNo };
                //}
                orderInfo.detailedAddress = userAddress.provinceName + " " + userAddress.detailedAddress;
                orderInfo.provinceId      = userAddress.provinceId;
                orderInfo.cityId          = userAddress.cityId;
                //orderInfo.orderState = OrderStates.paid;
                //orderInfo.payState = PayStates.paid;
                //orderInfo.submitTime = DateTime.Now;
                orderInfo.recipients        = userAddress.recipients;
                orderInfo.moblie            = userAddress.moblie;
                orderInfo.remark            = remark;
                orderInfo.zipCode           = userAddress.zipCode;
                orderInfo.distributionstate = DistributionStates.unfilled;
                //orderInfo.payType = PayTypes.weChatPayment;
                orderInfo.payAmount     = orderInfo.amount + orderInfo.freight;
                orderInfo.UserAddressId = userAddress.userAddressId;
                OrderService.Update(orderInfo);

                tran.Commit();
                //TransactionHelper.Commit();
                return(new ResultMessage()
                {
                    Code = 0, Msg = orderNo
                });
            }
            catch (Exception ex)
            {
                logService.Insert(ex);
                return(new ResultMessage()
                {
                    Code = -1, Msg = "订单数据录入有误,请截图并联系管理员,订单号:" + orderNo
                });
            }
            finally { tran.Dispose(); }
        }