using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Ropin.Inspection.Api.Common;
using Ropin.Inspection.Model.ViewModel;
using Ropin.Inspection.Service.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Ropin.Inspection.Api.Controllers
{
///
/// 巡检点内容
///
public class TispSpotContentController : BaseController
{
public ILogger _logger { get; }
private readonly ITispSpotContentService _tispSpotContentService;
///
/// 构造函数
///
///
///
public TispSpotContentController(ITispSpotContentService tispSpotContentService, ILogger logger)
{
_tispSpotContentService = tispSpotContentService;
_logger = logger;
}
///
/// 通过ID获取巡检点内容信息
///
///
///
[HttpGet("GetSpotContentAsync/{id}")]
public async Task GetSpotContentAsync(Guid id)
{
if (Guid.Empty == id)
{
return new ApiResult(ReturnCode.GeneralError);
}
try
{
var content = await _tispSpotContentService.GetByIdAsync(id);
return new ApiResult(content);
}
catch (Exception ex)
{
return new ApiResult(ReturnCode.GeneralError, ex.Message);
}
}
///
/// 获取所有巡检点内容
///
///
[HttpGet("GetSpotContentsAsync")]
public async Task GetSpotContentsAsync()
{
try
{
var contentList = await _tispSpotContentService.GetAllAsync();
return new ApiResult>(contentList);
}
catch (Exception ex)
{
return new ApiResult(ReturnCode.GeneralError, ex.Message);
}
}
///
/// 创建巡检点内容
///
///
///
[Route("CreateSpotContentAsync")]
[HttpPost]
public async Task CreateSpotContentAsync([FromBody] TispSpotContentViewModel content)
{
if (content == null)
{
return new ApiResult(ReturnCode.ArgsError);
}
try
{
await _tispSpotContentService.CreateOneAsync(content);
}
catch (Exception ex)
{
return new ApiResult(ReturnCode.GeneralError, ex.Message);
}
return new ApiResult(ReturnCode.Success);
}
///
/// 删除巡检点内容
///
///
///
[HttpDelete("DeleteSpotContentAsync/{id}")]
public async Task DeleteSpotContentAsync(Guid id)
{
if (Guid.Empty == id)
{
return new ApiResult(ReturnCode.GeneralError);
}
try
{
await _tispSpotContentService.DeleteAsync(id);
}
catch (Exception ex)
{
return new ApiResult(ReturnCode.GeneralError, ex.Message);
}
return new ApiResult(ReturnCode.Success);
}
///
/// 更新巡检点内容
///
///
///
///
[HttpPut("UpdateSpotContentAsync/{id}")]
public async Task UpdateSpotContentAsync(Guid id, TispSpotContentUpdateViewModel updateModel)
{
if (Guid.Empty == id)
{
return new ApiResult(ReturnCode.GeneralError);
}
try
{
await _tispSpotContentService.UpdateAsync(id, updateModel);
}
catch (Exception ex)
{
return new ApiResult(ReturnCode.GeneralError, ex.Message);
}
return new ApiResult(ReturnCode.Success);
}
}
}