DongYing/DongYingAPI/Controllers/api/GetEssentialInformationCont...

80 lines
3.2 KiB
C#

using DataServer.api;
using Microsoft.Ajax.Utilities;
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.Http;
namespace DongYingAPI.Controllers.api
{
/// <summary>
/// 基本信息
/// </summary>
public class GetEssentialInformationController : ApiController
{
DataServer.BLL.electrotherapy_room bll = new DataServer.BLL.electrotherapy_room();
public HttpResponseMessage Post([FromBody] select_switching_name room)
{
var res = new get_essential_information();
try
{
if (!string.IsNullOrEmpty(room.name))
{
var data = new List<essential_informationData>();
var list=bll.GetModelList("").Where(x=>x.Reserve2== room.name).ToList();
foreach (var item in list)
{
var model1 = new essential_informationData();
model1.name = "设备名称";
model1.value = item.Reserve1;
data.Add(model1);
var model2 = new essential_informationData();
model2.name = "设备型号";
model2.value = item.UnitType;
data.Add(model2);
var model3 = new essential_informationData();
model3.name = "生产厂家";
model3.value = item.ManufactureFactory;
data.Add(model3);
var model4 = new essential_informationData();
model4.name = "额定容量";
model4.value = item.RatedCapacity;
data.Add(model4);
var model5 = new essential_informationData();
model5.name = "额定电压";
model5.value = item.NominalVoltage;
data.Add(model5);
var model6 = new essential_informationData();
model6.name = "投运日期";
model6.value = item.ManufactureDate;
data.Add(model6);
var model7 = new essential_informationData();
model7.name = "投运状态";
model7.value = item.OperationalCondition;
data.Add(model7);
}
var adata=data.DistinctBy(x=>x.name).ToList();
res.code = 200;
res.msg = "成功";
res.data = adata;
}
else
{
res.code = 201;
res.msg = "参数为空";
}
}
catch (Exception ex)
{
res.code = 500;
res.msg = "失败," + ex.Message;
}
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(res), Encoding.GetEncoding("UTF-8"), "application/json") };
return result;
}
}
}