-1

在一个 If 语句中使用两个 return Ok 语句对我来说有问题吗?我从一个名为 PardotUtilites 的类返回 Create 和 update,Create 返回一个 Id。并且更新应该在编辑后返回名字、电子邮件和电话号码。

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; }
4

1 回答 1

2

当方法达到

return Ok(idstr);

代码在调用方法的地方恢复,因此永远不会到达

return Ok(update);
于 2017-07-17T14:22:02.507 回答