-1

Is there a problem for me to use two return Ok statements in one If statement? i am returning Create and update from a class called PardotUtilites and Create returns me an Id. And Update should return first name, email and phone number after editing.

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; }
Micheal
  • 37
  • 6
  • 4
    A `return` is the end of an execution path in a method. So anything after it, at the same scope level, will be unreachable. You can have more than one `return` in a method, but they have to be in different execution paths, for example `if(something) { return 1; } else { return 2;}` – juharr Jul 17 '17 at 14:21
  • Because you have ```return``` before it. – tym32167 Jul 17 '17 at 14:21

1 Answers1

2

When the method reaches

return Ok(idstr);

The code resumes where the method was called and therefore never reaches

return Ok(update);
Romano Zumbé
  • 7,893
  • 4
  • 33
  • 55