在一个If中使用两个返回Ok语句是否有问题 声明?我正在返回从名为PardotUtilites的类创建和更新,并且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; }
答案 0 :(得分:2)
当方法到达
时return Ok(idstr);
代码将在调用方法的地方恢复,因此永远不会到达
return Ok(update);