2017-07-17 6 views
-1

2つの戻りOK文を1つのIfで使用するには問題がありますか? 文?私は戻ってきますPardotUtilitesと呼ばれるクラスから作成と更新を行い、Createは私にIDを返します。更新は、編集後にファーストネーム、電子メール、電話番号を返す必要があります。「var update」に到達できないコードはなぜですか?複数のreturnOkステートメントを動作させるにはどうすればよいですか?

namespace GSWebAPI.Controllers 
{ 
    public class CampainProspectsController : ApiController 
    { 

     [HttpPost] 
     public IHttpActionResult Post([FromBody] JToken Value) 
     { 
      string tocreate = ""; 
      //string toupdate = ""; 
      Prospects res = new Prospects(); 
      res.Error = ""; 
      res.Status = ""; 

      var results = JsonConvert.DeserializeObject<Prospects>(Value.ToString()); 
      if (results != null) 
      { 
       // results 
       results.id = Guid.NewGuid().ToString(); 
       tocreate = "first_name=" + results.first_name + "&last_name=" + results.last_name + "&email=" + results.email + "&phone=" + results.phone + "&id=" + results.id; 

       var idstr = PardotUtilities.Create(tocreate); 
       return Ok(idstr); 
    // Error here "unreachable code" 
     var update = PardotUtilities.Update(tocreate, results.id); 
       return Ok(update); 
       PardotUtilities.Upsert(tocreate, results.id); 

       PardotUtilities.Query(tocreate, results.id); 
       PardotUtilities.Delete(tocreate, results.id); 




       // return Ok(update); 

      } 

      return Ok(); 
     } 
     //public class 

      public class Prospects 
     { 

      public String Status { get; set; } 
      public String Error { get; set; } 

      public string id { get; set; } 
      public string email { get; set; } 
      public string first_name { get; set; } 
      public string last_name { get; set; } 
      public string password { get; set; } 
      public string company { get; set; } 
      public string website { get; set; } 
      public string job_title { get; set; } 
      public string department { get; set; } 
      public string contry { get; set; } 
      public string address_one { get; set; } 
      public string address_two { get; set; } 
      public string city { get; set; } 
      public string state { get; set; } 
      public string territory { get; set; } 
      public string zip { get; set; } 
      public string phone { get; set; } 
      public string fax { get; set; } 
      public string source { get; set; } 
      public string annual_revenue { get; set; } 
      public string employees { get; set; } 
      public string industry { get; set; } 
      public string years_in_business { get; set; } 
      public string comments { get; set; } 
      public string notes { get; set; } 
      public string score { get; set; } 
      public string grade { get; set; } 
      public string last_activity_at { get; set; } 
      public string recent_interaction { get; set; } 
      public string crm_lead_fid { get; set; } 
      public string crm_contact_fid { get; set; } 
      public string crm_owner_fid { get; set; } 
      public string crm_account_fid { get; set; } 
      public string salesforce { get; set; } 
      public string crm_last_sync { get; set; } 
      public string crm_url { get; set; } 
      public string is_do_not_email { get; set; } 
      public string is_do_not_call { get; set; } 
      public string opted_out { get; set; } 
      public string is_reviewed { get; set; } 
      public string is_starred { get; set; } 
      public string created_at { get; set; } 
      public string updated_at { get; set; } 
+3

'return'メソッドで実行パスの終わりで到達しなかった場合、コードが再開

return Ok(idstr); 

達すると。同じスコープレベルのそれ以降のものは到達不能になります。あるメソッドに複数の 'return'を持たせることはできますが、それらは異なる実行パスになければなりません。たとえば' if(something){return 1; } else {return 2;} ' – juharr

+0

あなたは' 'return'''を前に持っているからです。 – tym32167

答えて

2

メソッドは、メソッドが呼び出され、したがって、決して

return Ok(update); 
+0

両方のリターンを有効にするにはどうすればよいですか? – Micheal

+0

両方のOK呼び出しの結果を含むListを返すことができます –

関連する問題