using DataServer.api.EnergyEfficiency; 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.EnergyEfficiency { /// /// 获取电费电价接口 /// public class GetElectricityPriceController : ApiController { DataServer.BLL.electricity_price bll = new DataServer.BLL.electricity_price(); /// /// 获取电费电价接口 /// /// public HttpResponseMessage Get() { var res = new get_electricity_price_response(); try { var data=new List(); var list = bll.GetModelList("").OrderBy(x=>x.Month); foreach (var item in list) { var model = new electricity_price(); model.Cost = item.Cost; model.UnitPrice = item.UnitPrice; model.Month = item.Month + "月"; data.Add(model); } res.code = 200; res.msg = "成功"; res.data= data; } 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; } } }