博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WebApi 增删改查
阅读量:6187 次
发布时间:2019-06-21

本文共 14880 字,大约阅读时间需要 49 分钟。

///         /// 展示终端列表(后台)(Zoe)        ///         /// 
public KeyValuePair
> GetTerminalList(string SerialNum, int rows, int page) { if (string.IsNullOrWhiteSpace(SerialNum)) SerialNum = ""; IExtensionRepository
TerminalService = DIFactory.ObjectContainer.Resolve
>(); IExtensionRepository
TerminalTypeService = DIFactory.ObjectContainer.Resolve
>(); IExtensionRepository
terminalUpgradePackageRepo = DIFactory.ObjectContainer.Resolve
>(); var TerminalQuery = TerminalService.GetModel(p => p.SerialNum.Contains(SerialNum) ).AsEnumerable(); var TerminalTypeQuery = TerminalTypeService.GetModel().AsEnumerable(); var terminalUpgradePackageQuery = terminalUpgradePackageRepo.GetModel().AsEnumerable(); var query = from u in TerminalQuery from o in TerminalTypeQuery join p in terminalUpgradePackageQuery on o.Id equals p.TerminalTypeId into jop from p in jop.DefaultIfEmpty() where u.TypeId== o.Id orderby u.CreateTime descending select new TerminalAll { Id = u.Id, SerialNum = u.SerialNum, TypeId=o.Id, TypeName=o.TypeName, FirmwareVersion = p!=null? p.Versions:"", SIMNumber = u.SIMNumber!=null?u.SIMNumber.ToString():"", IsDisabled = u.IsDisabled, StartTime = u.StartTime.ToString("yyyy-MM-dd"), AreaId = u.AreaId, OrganizationId = u.OrganizationId, }; IEnumerable
TerminalList = query.ToList(); int startIndex = (page - 1) * rows; int count = TerminalList.Count(); if (count > rows && rows != -1) { if ((startIndex + rows) > count) TerminalList = TerminalList.Skip(startIndex).Take(count - startIndex); else TerminalList = TerminalList.Skip(startIndex).Take(rows); } KeyValuePair
> kv = new KeyValuePair
>(count, TerminalList); return kv; }
public DtoResult
InsertTerminal(TerminalInsert model) { DtoResult
result = new DtoResult
() { Result = false }; IExtensionRepository
TerminalService = DIFactory.ObjectContainer.Resolve
>(); AIMS.Model.NJTerminal Terminal = TerminalService.GetModel().Where(u => u.SerialNum== model.SerialNum).FirstOrDefault(); if (Terminal != null) { result.Message = "该终端序列号已存在!"; return result; } Terminal = TerminalService.GetModel().Where(u => u.SIMNumber== model.SIMNumber).FirstOrDefault(); if (Terminal != null) { result.Message = "该SIM卡号已存在!"; return result; } else { Terminal = new AIMS.Model.NJTerminal() { Id= Guid.NewGuid(), SerialNum =model.SerialNum, TypeId=model.TypeId, SIMNumber=model.SIMNumber, //增加时间项,防止自动生成无效的时间 by:xyong CreateTime=DateTime.Now, StartTime=DateTime.Now, TokenTimesout=DateTime.Now, //end xyong }; } TerminalService.Insert(Terminal); result.Result = true; result.Message = "操作成功!"; return result; }
public TerminalInfo GetTerminalInfo(Guid terId)        {            TerminalInfo model = null;            IExtensionRepository
TerminalService = DIFactory.ObjectContainer.Resolve
>(); var Terminal = TerminalService.Find(terId); if (Terminal!=null) { model = new TerminalInfo(); model.Id = Terminal.Id; model.SerialNum = Terminal.SerialNum; model.TypeId = Terminal.TypeId; model.SIMNumber = Terminal.SIMNumber; } return model; }
///         ///修改终端(后台)(Zoe)        ///         ///         /// 
public DtoResult
UpdateTerminal(TerminalUpdate model) { DtoResult
result = new DtoResult
() { Result = false }; IExtensionRepository
TerminalService = DIFactory.ObjectContainer.Resolve
>(); AIMS.Model.NJTerminal Terminal = TerminalService.Find(model.Id); if (Terminal != null) { if (Terminal.SerialNum != model.SerialNum&&Terminal.Id!=model.Id) { AIMS.Model.NJTerminal item = TerminalService.GetModel().Where(u => u.SerialNum == model.SerialNum).FirstOrDefault(); if (item != null) { result.Message = "该终端序列号已存在!"; return result; } } if (Terminal.SIMNumber != model.SIMNumber && Terminal.Id != model.Id) { AIMS.Model.NJTerminal item = TerminalService.GetModel().Where(u => u.SIMNumber == model.SIMNumber).FirstOrDefault(); if (item != null) { result.Message = "该SIM卡号已存在!"; return result; } } Terminal.SerialNum = model.SerialNum; Terminal.TypeId = model.TypeId; Terminal.SIMNumber = model.SIMNumber; TerminalService.Update(Terminal); result.Result = true; result.Message = "操作成功!"; return result; } result.Message = "该终端不存在!"; return result; }
///         /// 删除终端(后台)(Zoe)        ///         ///         /// 
public DtoResult
DelTerminal(int id) { DtoResult
result = new DtoResult
() { Result = false }; IExtensionRepository
TerminalService = DIFactory.ObjectContainer.Resolve
>(); AIMS.Model.NJTerminal item = TerminalService.Find(id); if (item != null) { item.IsDeleted = true; TerminalService.Update(item); result.Result = true; result.Message = "操作成功!"; return result; } result.Message = "终端不存在,传入Id错误!"; return result; }
///         /// 启用或禁用终端(后台)(Zoe)        ///         ///         /// 
public DtoResult
SetTerminalEnabled(Guid id, bool enabled) { DtoResult
result = new DtoResult
() { Result = false }; IExtensionRepository
TerminalService = DIFactory.ObjectContainer.Resolve
>(); AIMS.Model.NJTerminal item = TerminalService.Find(id); if (item != null) { item.IsDisabled = enabled; TerminalService.Update(item); result.Result = true; result.Message = "操作成功!"; return result; } result.Message = "终端不存在,传入Id错误!"; return result; }

 

using AIMS.Bussiness.Application.Application.NJTerminalApp;using AIMS.Bussiness.ApplicationDto.Dto;using AIMS.Bussiness.ApplicationDto.NJWorkTasksDto;using AIMS.Bussiness.ApplicationDto.TerminalDto;using AIMS.Bussiness.Interface;using AIMS.Model;using AIMS.Web.Helper;using Common.BaseLibrary.Extension;using Newtonsoft.Json;using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Net.Http;using System.Text;using System.Web;using System.Web.Http;namespace AIMS.Web.Api{    ///     /// 终端控制器(Zoe)    ///     public class NJTerminalController : ApiBaseController    {        private INJTerminalAppService iNJTerminalAppService = null;        public NJTerminalController(INJTerminalAppService njerminalAppService, IAIMSOrganizationService organizationService)            : base(organizationService)        {            this.iNJTerminalAppService = njerminalAppService;        }        //===================================展示终端列表============================================================        ///         /// 展示终端列表(后台)        ///         /// 终端序列号        /// 行数        /// 页码        /// 
[HttpGet] [Route("api/api/NJTerminal/GetTerminalList")] public DtoResult
>> GetTerminalList(string SerialNum, int rows, int page) { KeyValuePair
> modelList = iNJTerminalAppService.GetTerminalList(SerialNum, rows, page); GridDto
> dto = new GridDto
>(); dto.Total = modelList.Key; dto.Rows = modelList.Value.ToList(); return DtoResultHelper
>>.RetDtoResult((int)HttpStatusCode.OK, "成功", true, dto); } ///
/// 展示终端列表(前台)管理员版本 /// ///
///
///
///
///
///
[HttpGet] [Route("api/api/NJTerminal/ReceptionGetTerminalListM")] public DtoResult
>> ReceptionGetTerminalListM(string areaId, string serialNum, string nJNum, int rows, int page) { KeyValuePair
> modelList = iNJTerminalAppService.ReceptionGetTerminalListM( areaId, serialNum, nJNum, rows, page); GridDto
> dto = new GridDto
>(); dto.Total = modelList.Key; dto.Rows = modelList.Value.ToList(); return DtoResultHelper
>>.RetDtoResult((int)HttpStatusCode.OK, "成功", true, dto); }//------------------------------------------------------------------------------------------------------------------------------------ ///
/// 展示终端列表(前台)合作社版本 /// ///
///
///
///
///
///
[HttpGet] [Route("api/api/NJTerminal/ReceptionGetTerminalListH")] public DtoResult
>> ReceptionGetTerminalListH(Guid orgId, string serialNum, string nJNum, int rows, int page) { KeyValuePair
> modelList = iNJTerminalAppService.ReceptionGetTerminalListH(orgId, serialNum, nJNum, rows, page); GridDto
> dto = new GridDto
>(); dto.Total = modelList.Key; dto.Rows = modelList.Value.ToList(); return DtoResultHelper
>>.RetDtoResult((int)HttpStatusCode.OK, "成功", true, dto); } //======================================================================================================================= ///
/// 增加前展示通过终端序列号找农机车牌号(前台) /// ///
///
[HttpGet] [Route("api/api/NJTerminal/ReceptionInsertTerminalFromSerialNum")] public DtoResult
ReceptionInsertTerminalFromSerialNum(string serialNum) { var model = iNJTerminalAppService.ReceptionInsertTerminalFromSerialNum(serialNum); if (model != null) { return DtoResultHelper
.RetDtoResult((int)HttpStatusCode.OK, "成功", true, model); } return DtoResultHelper
.RetDtoResult((int)HttpStatusCode.NotFound, "没有找到对应车牌号", false, null); } ///
/// 增加前展示通过农机车牌号找终端序列号(前台) /// ///
///
[HttpGet] [Route("api/api/NJTerminal/ReceptionInsertTerminalFromNJNum")] public DtoResult
ReceptionInsertTerminalFromNJNum(string nJNum) { var model = iNJTerminalAppService.ReceptionInsertTerminalFromNJNum(nJNum); if (model != null) { return DtoResultHelper
.RetDtoResult((int)HttpStatusCode.OK, "成功", true, model); } return DtoResultHelper
.RetDtoResult((int)HttpStatusCode.NotFound, "没有找到对应终端序列号", false, null); } //=====================================新增终端====================================================== ///
/// 新增终端(后台) /// ///
///
[HttpPost] [Route("api/api/NJTerminal/InsertTerminal")] public DtoResult
InsertTerminal([FromBody]TerminalInsert model) { DtoResult
dtoResult = iNJTerminalAppService.InsertTerminal(model); dtoResult.Code = ((int)(HttpStatusCode.OK)).ToString(); return dtoResult; } ///
/// 新增终端(前台) /// ///
///
[HttpPost] [Route("api/api/NJTerminal/ReceptionInsertTerminal")] public DtoResult
ReceptionInsertTerminal([FromBody]ReceptionTerminalInsert model) { DtoResult
dtoResult = iNJTerminalAppService.ReceptionInsertTerminal(model); dtoResult.Code = ((int)(HttpStatusCode.OK)).ToString(); return dtoResult; } //=================================修改前展示终端列表========================================================== ///
/// 修改前展示终端(后台) /// ///
///
[HttpGet] [Route("api/api/NJTerminal/GetTerminalInfo")] public DtoResult
GetTerminalInfo(string terId) { var id = Guid.Parse(terId); var model = iNJTerminalAppService.GetTerminalInfo(id); if (model != null) { return DtoResultHelper
.RetDtoResult((int)HttpStatusCode.OK, "成功", true, model); } return DtoResultHelper
.RetDtoResult((int)HttpStatusCode.NotFound, "没有找到对应终端", false, null); } ///
/// 修改前展示终端列表(前台) /// ///
///
[HttpGet] [Route("api/api/NJTerminal/GetReceptionTerminalInfo")] public DtoResult
GetReceptionTerminalInfo(string terId) { var id = Guid.Parse(terId); var model = iNJTerminalAppService.GetReceptionTerminalInfo(id); if (model != null) { return DtoResultHelper
.RetDtoResult((int)HttpStatusCode.OK, "成功", true, model); } return DtoResultHelper
.RetDtoResult((int)HttpStatusCode.NotFound, "没有找到对应终端", false, null); } //======================================更改终端=============================================================== ///
/// 更改终端(后台) /// ///
///
[HttpPost] [Route("api/api/NJTerminal/UpdateTerminal")] public DtoResult
UpdateTerminal([FromBody]TerminalUpdate model) { DtoResult
dtoResult = iNJTerminalAppService.UpdateTerminal(model); dtoResult.Code = ((int)(HttpStatusCode.OK)).ToString(); return dtoResult; } ///
/// 更改终端(绑定农机)(前台) /// ///
///
[HttpPost] [Route("api/api/NJTerminal/ReceptionUpdateTerminal")] public DtoResult
ReceptionUpdateTerminal([FromBody]ReceptionTerminalUpdate model) { DtoResult
dtoResult = iNJTerminalAppService.ReceptionUpdateTerminal(model); dtoResult.Code = ((int)(HttpStatusCode.OK)).ToString(); return dtoResult; } //=======================================删除终端======================================================== ///
/// 删除终端(后台) /// ///
///
[HttpPost] [Route("api/api/NJTerminal/DelTerminal")] public DtoResult
DelTerminal([FromBody]int id) { DtoResult
dtoResult = iNJTerminalAppService.DelTerminal(id); dtoResult.Code = ((int)(HttpStatusCode.OK)).ToString(); return dtoResult; } ///
/// 删除终端(前台) /// ///
///
[HttpPost] [Route("api/api/NJTerminal/ReceptionDelTerminal")] public DtoResult
ReceptionDelTerminal([FromBody]int id) { DtoResult
dtoResult = iNJTerminalAppService.ReceptionDelTerminal(id); dtoResult.Code = ((int)(HttpStatusCode.OK)).ToString(); return dtoResult; } //===========================================启用或禁用终端========================================================== ///
/// 启用或禁用终端(后台) /// ///
参数{id:终端Id,enabled:是否启用} ///
[HttpPost] [Route("api/api/NJTerminal/SetTerminalEnabled")] public DtoResult
SetTerminalEnabled([FromBody]TerminalEnableModel model) { DtoResult
dtoResult = iNJTerminalAppService.SetTerminalEnabled(Guid.Parse(model.id), model.enabled); dtoResult.Code = ((int)(HttpStatusCode.OK)).ToString(); return dtoResult; } //=================================================解绑农机(前台)============================================================================ ///
/// 解绑农机(前台) /// ///
///
[HttpPost] [Route("api/api/NJTerminal/ReceptionUnbindTerminal")] public DtoResult
ReceptionUnbindTerminal([FromBody]string serialNum) { DtoResult
dtoResult = iNJTerminalAppService.ReceptionUnbindTerminal(serialNum); dtoResult.Code = ((int)(HttpStatusCode.OK)).ToString(); return dtoResult; } ///
/// 通过用户Id,初次加载树,展开第一层节点 /// ///
用户Id guid ///
[HttpGet] [Route("api/api/NJTerminal/LoadAreaTreeNodeByUserId")] public DtoResult
> LoadAreaTreeNodeByUserId(Guid userId) { List
treeNodelList = iNJTerminalAppService.LoadAreaTreeNodeByUserId(userId); return DtoResultHelper
>.RetDtoResult((int)HttpStatusCode.OK, "成功", true, treeNodelList); } ///
///通过区域Id展开树下层节点 /// ///
区域Id ///
[HttpGet] [Route("api/api/NJTerminal/GetAreaTreeNode")] public DtoResult
> GetAreaTreeNode(string code) { List
treeNodelList = iNJTerminalAppService.GetAreaTreeNode(code); return DtoResultHelper
>.RetDtoResult((int)HttpStatusCode.OK, "成功", true, treeNodelList); } } ///
/// IsTerminalDisabled的参数 /// public class TerminalEnableModel { ///
/// 终端Id /// public string id { get; set; } ///
/// 是否启用 /// public bool enabled { get; set; } } }

 

转载于:https://www.cnblogs.com/zhengqian/p/7880256.html

你可能感兴趣的文章
(15)-思科交换机端口镜像配置
查看>>
RecyclerView的使用方法与如何设置点击监听
查看>>
物联网五条建议助力医疗结构发展
查看>>
数据库Event
查看>>
vue 百度地图 + 定位
查看>>
Silverlight实用窍门系列:58.Silverlight中的Binding使用(三)-数据集合绑定
查看>>
Vue-cli实现Markdown解析为Html以及highlight高亮代码块
查看>>
Shell程序及Linux中默认的Shell程序Bash的特性
查看>>
Java Sound Technology
查看>>
发送短信的2种方法
查看>>
angularJS
查看>>
当python2和python3都安装的时候,如何通过pip安装库以及TensorFlow
查看>>
iSurround:虚拟声卡均衡器优化插件驱动,让声音更动听
查看>>
MyBatis(一)-----ssm的整合 跑起来
查看>>
Maven 使用profiles 时 值无法替换问题
查看>>
Edraw Office Viewer component教程(三):将MS Word、Excel、PowerPoint嵌入到WPF应用程序中...
查看>>
Photon:轻量级专用于容器的Linux发行版
查看>>
Rancher第二季在线培训完美收官!
查看>>
NIO-Selector类详解
查看>>
开启HTTPS全网加密新时代 亚洲诚信与中科三方签约战略合作
查看>>