小编gsm*_*ida的帖子

MVC 4 Web Api Post

我想从远程客户端插入,因为我需要通过http发送数据.
我可以getPerformances()正确使用httpClient api/performances?date={0}

我想问一下我的postPorformances()内部实现PerformancesController是否正确以及是否如何从客户端调用它?

这是我的实现:

public class PerformancesController : ApiController
    {
        // GET api/performances
        public IEnumerable<Performance> getPerformances(DateTime date)
        {
            return DataProvider.Instance.getPerformances(date);
        }

        public HttpResponseMessage postPerformances(Performance p)
        {
            DataProvider.Instance.insertPerformance(p);
            var response = Request.CreateResponse<Performance>(HttpStatusCode.Created, p);
            return response;
        }
    }
Run Code Online (Sandbox Code Playgroud)
public class Performance {
    public int Id {get;set;}
    public DateTime Date {get;set;}
    public decimal Value {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

我试过这个,但我要注意:

  private readonly HttpClient _client;
  string request = String.Format("api/performances");
  var jsonString = "{\"Date\":" + p.Date + ",\"Value\":" + p.Value …
Run Code Online (Sandbox Code Playgroud)

c# asp.net httpclient asp.net-web-api

6
推荐指数
1
解决办法
1万
查看次数

使用条件LINQ设置值

我正在从表中选择一些数据,其中包含与表有关系A的列value和类型,B其中有一列coef包含(-1,0,1)AI中检索时想要将valuewith 乘以coef.

c# linq entity-framework repository linq-to-sql

0
推荐指数
1
解决办法
591
查看次数