【发布时间】:2015-12-09 13:03:10
【问题描述】:
我已经开始学习 RESTful API,需要一些指导来激发动力。谢谢 我正在尝试将数据存储到由 Android 的 URL 获取的 SQL 服务器中。我正在使用在 Visual Studio 中使用 MVC4 和实体框架创建的宁静 API。 以下网址用于获取数据
http://localhost/finalWebAPI/api/Location/ahmad%6078.000%6089.000
我想在 ahmad 之后保存拆分字符串的值。 下面的代码是模型类中的数据模型
public class locationdata
{
public static AndroidDBEntities2 db = new AndroidDBEntities2();
public static string locationcordinates(string name){
if (name != null) {
string[] str = name.Split('%');
string name1 = str[0];
string id1 = str[1];
string id2 = str[2];
user u = (from u1 in db.users
where u1.user_name ==name1
select u1).First();
u.lag = id1;
u.lng = id2;
db.SaveChanges() ;
}
return null;
}
这里是控制器
public HttpResponseMessage Get(string id)
{
var reg1 = locationdata.locationcordinates(id);
// var employees = locationdata.UpdateEmployee(name,l);
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, reg1);
return response;
}
路线如下
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional });
【问题讨论】:
-
你的问题到底是什么?
标签: c# api rest model-view-controller