2015-04-01 69 views
0

我有一個REST WCF服務,它依賴於傳遞給它要更新該列的更新方法的內容。例如,他們可以更新地址,電話號碼,電子郵件,...在C#代碼中運行多個更新存儲過程

這些更新中的每一個都運行自己的存儲過程進行更新。我不確定我的代碼是否正確,因爲當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

請格式化您的代碼!它幾乎不可讀。 – 2015-04-01 20:39:54

回答

1

你的代碼永遠只更新)從GetCustomerInfo.Instance.returnCustomerInfo(獲得的CUSTOMER_ID,而不是使用CUSTOMER_ID從CustomerData的參數傳遞。如何知道「GetCustomerInfo.Instance.returnCustomerInfo()」如何讓客戶匹配所傳遞的內容?看起來你的代碼總是隻會更新同一個用戶,而不管傳遞給例程的用戶信息如何。

+0

GetCustomerInfo.Instance.returnCustomerInfo返回正確的客戶,因爲它從輸入(如用戶名,密碼)獲取一些其他信息以匹配哪個用戶進入。 – Alma 2015-04-01 16:17:12