public AddressObj GetAddress(int addressId) { using (helper = new SqlHelper()) { helper.AddIntParameter("@AddressID", addressId); using (SqlDataReader dr = helper.ExecuteReader("select Address,Zip,Receiver,Mobile,Phone,UserAddress.CityID,UserAddress.RegionID,UserID,Province.ProvinceID,CityName,RegionName,ProvinceName from UserAddress inner join City on UserAddress.CityID=City.CityID inner join Province on Province.ProvinceID=City.ProvinceID left join Region on Region.RegionID=UserAddress.RegionID where AddressID=@AddressID", CommandType.Text)) { if (dr.HasRows && dr.Read()) { AddressObj addressObj = new AddressObj(); addressObj.AddressID = addressId; addressObj.Address = dr[0] == DBNull.Value ? null : (string)dr[0]; addressObj.Zip = dr[1] == DBNull.Value ? null : (string)dr[1]; addressObj.Receiver = dr[2] == DBNull.Value ? null : (string)dr[2]; addressObj.Mobile = dr[3] == DBNull.Value ? null : (string)dr[3]; addressObj.Phone = dr[4] == DBNull.Value ? null : (string)dr[4]; addressObj.CityID = dr[5] == DBNull.Value ? 0 : (int)dr[5]; addressObj.RegionID = dr[6] == DBNull.Value ? 0 : (int)dr[6]; addressObj.UserID = dr[7] == DBNull.Value ? 0 : (int)dr[7]; return(addressObj); } return(null); } } }
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 })); }
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 })); }
public void ModifyAddress(AddressObj addressObj) { using (helper = new SqlHelper()) { helper.AddIntParameter("@AddressID", addressObj.AddressID); helper.AddIntParameter("@UserID", addressObj.UserID); helper.AddStringParameter("@Address", 200, addressObj.Address); helper.AddStringParameter("@Zip", 20, addressObj.Zip); helper.AddStringParameter("@Receiver", 20, addressObj.Receiver); helper.AddStringParameter("@Mobile", 20, addressObj.Mobile); helper.AddStringParameter("@Phone", 50, addressObj.Phone); helper.AddIntParameter("@CityID", addressObj.CityID); helper.AddIntParameter("@RegionID", addressObj.RegionID); string sql = "update UserAddress set Address=@Address,Zip=@Zip,Receiver=@Receiver,Mobile=@Mobile,Phone=@Phone,CityID=@CityID,RegionID=@RegionID where AddressID=@AddressID"; helper.ExecuteNonQuery(sql, CommandType.Text); } }
public void AddAddress(AddressObj addressObj) { using (helper = new SqlHelper()) { SqlParameter addressIdParam = helper.AddOutputParameter("@AddressID"); helper.AddIntParameter("@UserID", addressObj.UserID); helper.AddStringParameter("@Address", 200, addressObj.Address); helper.AddStringParameter("@Zip", 20, addressObj.Zip); helper.AddStringParameter("@Receiver", 20, addressObj.Receiver); helper.AddStringParameter("@Mobile", 20, addressObj.Mobile); helper.AddStringParameter("@Phone", 50, addressObj.Phone); helper.AddIntParameter("@CityID", addressObj.CityID); helper.AddIntParameter("@RegionID", addressObj.RegionID); string sql = "insert into UserAddress (UserID,Address,Zip,Receiver,Mobile,Phone,CityID,RegionID) values (@UserID,@Address,@Zip,@Receiver,@Mobile,@Phone,@CityID,@RegionID)"; helper.ExecuteNonQuery(sql, CommandType.Text); } }
public ActionResult DeleteAddress(int addressId) { UserObj user = AppData.SessionUser; if (user == null) { return(Json(new { success = false, msg = "您还未登录!" })); } UserBLL userBLL = new UserBLL(); AddressObj addressObj = userBLL.GetAddress(addressId); if (addressObj == null || addressObj.UserID != user.UserID) { return(Json(new { success = false, msg = "您无法删除该地址!" })); } userBLL.DeleteAddress(user.UserID, addressId); return(Json(new { success = true })); }
public ActionResult DeleteAddress(int id, int addressId) { if (!AppData.IsManagerLogin) { return(Json(new { success = false, msg = "您未登录后台或会话已过期" })); } if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 1305)) { return(Json(new { success = false, msg = "您没有执行该操作的权限" })); } UserBLL userBLL = new UserBLL(); AddressObj addressObj = userBLL.GetAddress(addressId); if (addressObj == null) { return(Json(new { success = false, msg = "您无法删除该地址!" })); } userBLL.DeleteAddress(id, addressId); return(Json(new { success = true })); }
public void ModifyAddress(AddressObj addressObj) { dal.ModifyAddress(addressObj); }
public void AddAddress(AddressObj addressObj) { dal.AddAddress(addressObj); }