DongYing/DongYingAPI/Controllers/api/GetCarbonReductionControlle...

51 lines
1.7 KiB
C#

using DataServer.api;
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 GetCarbonReductionController : ApiController
{
public HttpResponseMessage Get()
{
var res = new get_carbon_reduction();
try
{
var data = new List<carbon_reductionData>();
var model=new carbon_reductionData();
//总量
model.Aount =742.81;
var blist=new List<carbon_reduction>();
var bmodel=new carbon_reduction();
//空调
bmodel.AirConditioner =Convert.ToDouble(Math.Round(Convert.ToDouble( 742.81*44.99/100),3));
//照明
bmodel.Illumination =Convert.ToDouble(Math.Round(Convert.ToDouble(742.81*13.68/100),3));
//其它
bmodel.Other =Convert.ToDouble(Math.Round(Convert.ToDouble(742.81*(35.71+7.61)/100),3));
blist.Add(bmodel);
model.list = blist;
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;
}
}
}