Web Api 实现新建功能接口
ResultModel类 是一个结果类
public class ResultModel
{
/// <summary>
/// 返回结果状态
/// </summary>
public int code { get; set; }
/// <summary>
/// 是否操作成功
/// </summary>
public bool success { get; set; }
/// <summary>
/// 错误消息提示
/// </summary>
public string message { get; set; }
/// <summary>
/// 结果列表
/// </summary>
public object data { get; set; }
}
创建功能
/// <summary>
/// 新建数据
/// </summary>
/// <returns></returns>
[HttpPost]
public ResultModel InsertData([FromBody] DataInsertViewModel InsertModel)//前端获取的数据存放在一个viewmodel中
{
var result = new ResultModel();
using (var ef = new CrmEntity())
{
//插入的数据库表
var model = new data()
{
is_transform = InsertModel.is_transform,
followup = InsertModel.followup,
name = InsertModel.name,
come_id = InsertModel.come_id,
customer_id = InsertModel.customer_id,
next_time = InsertModel.next_time,
telephone = InsertModel.telephone,
mobile = InsertModel.mobile,
address = InsertModel.address,
remark = InsertModel.remark
};
//添加数据
ef.data.Add(model);
//保存数据
if (ef.SaveChanges() > 0)
{
result.code = 200;
result.message = "新建成功";
result.data = model;
}
else
{
result.code = 500;
result.message = "新建失败";
}
return result;
}
}
注:MVC API +EntityFramework技术实现该功能;DataInsertViewModel 为前端传输数据的接受,字段最好依据对应model所需字段;
Web Api 实现新建功能接口的更多相关文章
- Web Api 实现删除功能接口
删除数据 [HttpDelete] public ResultModel DeleteDataById(int id) { var result = new ResultModel(); //实例化数 ...
- ASP.NET WEB API微信支付通知接口,返回xml数据,微信服务器不识别问题
原文:ASP.NET WEB API微信支付通知接口,返回xml数据,微信服务器不识别问题 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/MrTra ...
- Visual Studio 2013 Preview - ASP.NET, MVC 5, Web API 2新功能搶先看
Visual Studio 2013 Preview - ASP.NET, MVC 5, Web API 2新功能搶先看 來自TechEd North America 2013的第一手消息 以下資訊均 ...
- 用ASP.NET Web API技术开发HTTP接口(二)
在第一部分,我们创建了一个基本的ASP.NET Web API项目,新建成功了数据表,然后添加了一些测试数据,最后创建了API控制器,用json格式把数据表里面的内容成功输出到浏览器上.接下来我们将继 ...
- 用ASP.NET Web API技术开发HTTP接口
开发工具 Visual Studio 2013 SQL Server 2008 R2 准备工作 启动Visual Studio 2013,新建一个ASP.NET Web应用程序,命名为SimpleAP ...
- 用ASP.NET Web API技术开发HTTP接口(一)
开发工具 Visual Studio 2013 SQL Server 2008 R2 准备工作 启动Visual Studio 2013,新建一个ASP.NET Web应用程序,命名为SimpleAP ...
- python web自动化测试框架搭建(功能&接口)——接口用例实现
测试用例基类: # coding=utf-8 import unittest import Logger log = Logger.Loger() class BaseCase(unittest.Te ...
- python web自动化测试框架搭建(功能&接口)——接口公共方法
接口公共方法有:数据引擎.http引擎.Excel引擎 1.数据引擎:获取用例.结果检查.结果统计 # -*- coding:utf-8 -*- from XlsEngine import XlsEn ...
- python web自动化测试框架搭建(功能&接口)——接口测试模块
Python接口测试采用python读取excel的方法,通过requests库发送请求和接收响应.模块有: Data:用于存放excel用例的,用例格式: iutil: 接口公共方法,数据引擎.ht ...
随机推荐
- 基于windows 10打造的kali工具集
基于windows 10打造的kali工具集.iso,适合于习惯使用windows的安全从业者.if you like it,please touch star! 作为安全从业主,Kali都是必备工具 ...
- PHP7.2.6安装sodium扩展
安装libsodium libsodium是安装sodium扩展的必须依赖条件,我这里提供两种安装方式,编译和直接yum 编译安装libsodium wget https://github.com/j ...
- selenium 框架
结构如下: test_project|--logs|---pages |---register_page.py| |---base_page.py|---test_case |- ...
- 团队第五次——Alpha2的发布
这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/2019autumnsystemanalysisanddesign/ 这个作业要求在哪里 https:// ...
- xadmin引入django-stdimage在列表页预览图片
一.安装 pip install django-stdimage 安装django-stdimage库 https://github.com/codingjoe/django-stdimage Git ...
- wordpress迁移后登陆时出现Forbidden You don’t have permission to access /wp-login.php on this server
之前在vps上,最近迁移到了php虚拟主机上,迁移后发现无法登陆后台出现403:Forbidden You don’t have permission to access /wp-login.php ...
- 201871010115——马北《面向对象程序设计JAVA》第二周学习总结
项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p ...
- http协议 c++ 接收
http消息格式:header+\r\n\r\n+ chunkLen + \r\n + chunkData + \r\n + chunkLen + \r\n + chunkData +\r\n + 0 ...
- linux 以导入文件形式添加定时任务(crontab)时需要注意的坑
在实际操作过程中发现,使用导入文件形式添加定时任务时,会将用户已有的定时任务全部覆盖清理(先清空,再重新导入),所以在使用文件导入定时任务时,需要先将已有定时任务导出,然后将新任务进行追加到已有定时任 ...
- 【反防盗链】img 标签 访问图片 返回403 forbidden问题
解决方案,页面头添加 <meta name="referrer" content="no-referrer" /> 隐藏请求体中标注来源referr ...