demo20230512/Controllers/Api/RiskAssmt/SignificanceAssmtController.cs
2023-05-12 10:20:28 +08:00

105 lines
3.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Weee.Models;
using Weee.Service;
using Weee.ViewModels.DataTransferObject;
using Weee.ViewModels.Lca.LCARiskAssmtSurveyForm;
namespace Weee.Controllers.Api.RiskAssmt
{
public class SignificanceAssmtController : ApiControllerBase
{
private readonly SignificanceAssmtDataService service;
public SignificanceAssmtController(
SignificanceAssmtDataService d) : base(d)
{
service = d;
}
[Route("api/SignificanceAssmt/GetByLcaId/{LCAID}")]
//[Filter.ApiMultilanguage]disable obsolete warning, not sure OK or not
public object GetByLcaId(int LCAID, int lifeCycleStage)
{
//var type = service.GetLCAType(LCAID);
var query = service.GetList(LCAID);
query = query.OrderBy(x => x.LifeCycleStage).ThenBy(x => x.ID);
if (lifeCycleStage > 0)
{
query = query.Where(x => x.LifeCycleStage == lifeCycleStage);
}
query = query.OrderBy(x => x.LifeCycleStage).ThenBy(x => x.ID);
var assmtFactors = service.GetAssmtFactors(LCAID).ToList().Select(x =>
new { x.ID, x.FactorName, FactorScores = x.FactorScores.Select(s => new { s.OptionScore, OptionDescription = $"{s.OptionScore}{s.OptionDescription}" }) });
var lca = service.GetLCA(LCAID);
var ret = new
{
Significances = query.ToList(),
StageOptions = CScommon.ProgramConstants.lifeCycleStages,
AssmtFactors = assmtFactors,
GradingScore = lca.GradingScore,
ListDefaultPurpose = lca.ListDefaultPurpose,
//OptionsTwo = parameterservice.GetNonYearlyParameterOptions(Categories.Refrigerant),
//SheetHeader = service.GetSheetHeader(LCAID, Categories.Refrigerant)
};
return ret;
}
[Route("api/SignificanceAssmt/Sync/{LCAID}")]
[HttpPost]
public IHttpActionResult Sync(int LCAID)
{
service.Sync(LCAID);
return Ok();
}
[Route("api/SignificanceAssmt/UpdateGradingScore/{LCAID}/{GradingScore}")]
[HttpPost]
public IHttpActionResult UpdateGradingScore(int LCAID, int GradingScore)
{
service.UpdateGradingScore(LCAID, GradingScore);
return Ok();
}
[Route("api/SignificanceAssmt/UpdateListDefaultPurpose/{LCAID}/{ListDefaultPurpose}")]
[HttpPost]
public IHttpActionResult UpdateListDefaultPurpose(int LCAID, string ListDefaultPurpose)
{
service.UpdateListDefaultPurpose(LCAID, ListDefaultPurpose);
return Ok();
}
[Route("api/SignificanceAssmt/Save/{LCAID}/{id}")]
[HttpPost]
public object Save(int LCAID, int id, LCARiskAssmtSurveyForm_SignificanceAssmtQuery ToBeSave)
{
if (!ModelState.IsValid)
return BadRequest();
if (id != ToBeSave.ID || LCAID != ToBeSave.LCAID)
return BadRequest();
string json = CScommon.JsonUtl.fromT(ToBeSave);
LCARiskAssmtSurveyForm_SignificanceAssmt rec =
CScommon.JsonUtl.toT<LCARiskAssmtSurveyForm_SignificanceAssmt>(json);
service.Save(rec);// ToBeSave);
return ToBeSave;
}
[Route("api/SignificanceAssmt/Delete/{ID}")]
[HttpDelete]
public IHttpActionResult Delete(int ID)
{
service.Delete(ID);
return Ok();
}
}
}