我有一个REST WCF服务,它取决于它将更新该列的更新方法的传递。例如,他们可以更新地址,电话号码,电子邮件......
每个更新都运行自己的存储过程进行更新。我不确定我的代码是否正常,因为当2个用户尝试在同一时间更新他们的电子邮件地址时发生了一些问题,因此它将第二个用户电子邮件地址更新为第一个用户。
public Model.ReturnResponse UpdateCustomerProfile(Model.Customer CustomerData)
{
Model.Customer customer = GetCustomerInfo.Instance.returnCustomerInfo();
Model.ReturnResponse rs = new Model.ReturnResponse();
DAL.DataManager dal = new DAL.DataManager();
foreach (var pr in CustomerData.GetType().GetProperties())
{
string name = pr.Name;
object temp = pr.GetValue(CustomerData, null);
if (temp is int)
{
int value = (int)temp;
if (value != 0)
{
string prName = pr.Name;
break;
}
}
if (temp is string)
{
if (temp != null)
{
string prName = pr.Name;
if (prName == "WORKPHONE")
{
dal.Update_CustomerPhone(customer.Customer_ID, temp.ToString(), "WORK");
}
if (prName =="HOMEPHONE")
{
dal.Update_CustomerPhone(customer.Customer_ID, temp.ToString(), "HOME");
}
if (prName =="MOBILEPHONE")
{
dal.Update_CustomerPhone(customer.Customer_ID, temp.ToString(), "MOBILE");
}
if (prName == "FAXPHONE")
{
dal.Update_CustomerPhone(customer.Customer_ID, temp.ToString(), "FAX");
}
if (prName == "PRIMARYEMAIL")
{
dal.Update_Customer_Email(customer.Customer_ID, temp.ToString(), "PRIMARY");
}
}
if (prName == "SECONDARYEMAIL")
{
dal.Update_Customer_Email(customer.Customer_ID, temp.ToString(), "SECONDARY");
}
}
//Mailing Adress
if (prName == "MAILINGADDRESSADDRESS_1")
{
dal.Update_CustomerAddress(customer.Customer_ID, temp.ToString(), null, null, "STR_CP_MAILING");
}
if (prName == "MAILINGADDRESSADDRESS_2")
{
dal.Update_CustomerAddress(customer.Customer_ID, null, temp.ToString(), null, null, null,"STR_CP_MAILING");
}
if (prName == "STR_CP_MAILINGADDRESSCITY")
{
dal.Update_CustomerAddress(customer.Customer_ID, null, null, temp.ToString(), null, null, "CP_MAILING");
}
}
}
if (temp is bool)
{
string prName = pr.Name;
if (prName == "OnlineAgreement")
{
bool Online_Agreement = dal.Get_Online_Agreement_ByCustomerID(customer.Customer_ID);
if (Online_Agreement != Convert.ToBoolean(temp))
{
dal.Update_Customer_Online_Agreement(customer.Customer_ID, Convert.ToBoolean(temp));
}
}
}
}
}
答案 0 :(得分:1)
您的代码只会更新从GetCustomerInfo.Instance.returnCustomerInfo()获取的Customer_ID,而不是使用在参数中从CustomerData传递的Customer_ID。 " GetCustomerInfo.Instance.returnCustomerInfo()"知道让客户匹配传递的内容吗?看起来您的代码将始终只更新同一个用户,无论将哪些用户信息传递给例程。