示例#1
0
        public ActionResult SaveAddress()
        {
            UserObj user = AppData.SessionUser;

            if (user == null)
            {
                return(Json(new { success = false, msg = "您还未登录!" }));
            }

            UserBLL    userBLL    = new UserBLL();
            Validation validation = new Validation();
            int        addressId  = validation.GetInt("addressId");
            AddressObj addressObj;

            if (addressId == 0)
            {
                addressObj           = new AddressObj();
                addressObj.AddressID = addressId;
                addressObj.UserID    = user.UserID;
            }
            else
            {
                addressObj = userBLL.GetAddress(addressId);
                if (addressObj == null || addressObj.UserID != user.UserID)
                {
                    return(Json(new { success = false, msg = "您无法修改该地址!" }));
                }
            }

            addressObj.Receiver = validation.Get("receiver", false, "收货人姓名不可为空!");
            addressObj.Address  = validation.Get("address", false, "详细地址不可为空!");
            addressObj.Zip      = validation.Get("zip");
            addressObj.Mobile   = validation.Get("mobile");
            addressObj.Phone    = validation.Get("phone");
            addressObj.CityID   = validation.GetInt("cityId");
            addressObj.RegionID = validation.GetInt("regionId");

            if (validation.HasError)
            {
                return(Json(new { success = false, msg = "参数错误!", errors = validation.GetErrors() }));
            }

            if (string.IsNullOrEmpty(addressObj.Phone) && string.IsNullOrEmpty(addressObj.Mobile))
            {
                return(Json(new { success = false, msg = "手机或固话必填一项!" }));
            }

            if (addressObj.AddressID == 0)
            {
                userBLL.AddAddress(addressObj);
            }
            else
            {
                userBLL.ModifyAddress(addressObj);
            }

            return(Json(new { success = true }));
        }
示例#2
0
        public ActionResult SaveAddress(int id)
        {
            if (!AppData.IsManagerLogin)
            {
                return(Json(new { success = false, msg = "您未登录后台或会话已过期" }));
            }
            if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 1304))
            {
                return(Json(new { success = false, msg = "您没有执行该操作的权限" }));
            }

            UserBLL    userBLL    = new UserBLL();
            Validation validation = new Validation();
            int        addressId  = validation.GetInt("addressId");
            AddressObj addressObj;

            if (addressId == 0)
            {
                addressObj           = new AddressObj();
                addressObj.AddressID = addressId;
                addressObj.UserID    = id;
            }
            else
            {
                addressObj = userBLL.GetAddress(addressId);
            }

            addressObj.Receiver = validation.Get("receiver", false, "收货人姓名不可为空!");
            addressObj.Address  = validation.Get("address", false, "详细地址不可为空!");
            addressObj.Zip      = validation.Get("zip");
            addressObj.Mobile   = validation.Get("mobile");
            addressObj.Phone    = validation.Get("phone");
            addressObj.CityID   = validation.GetInt("cityId");
            addressObj.RegionID = validation.GetInt("regionId");

            if (validation.HasError)
            {
                return(Json(new { success = false, msg = "参数错误!", errors = validation.GetErrors() }));
            }

            if (string.IsNullOrEmpty(addressObj.Phone) && string.IsNullOrEmpty(addressObj.Mobile))
            {
                return(Json(new { success = false, msg = "手机或固话必填一项!" }));
            }

            if (addressObj.AddressID == 0)
            {
                userBLL.AddAddress(addressObj);
            }
            else
            {
                userBLL.ModifyAddress(addressObj);
            }

            return(Json(new { success = true }));
        }