using log4net;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Ropin.Inspection.Api.Common;
using Ropin.Inspection.Model.SearchModel.LGS;
using Ropin.Inspection.Model.ViewModel.LGS;
using Ropin.Inspection.Model;
using Ropin.Inspection.Service.LGS.Interface;
using System.Threading.Tasks;
using System;
namespace Ropin.Inspection.Api.Controllers.LGS
{
public class LargeScreenEventController : BaseController
{
private readonly ILargeScreenEventService _repository;
private static readonly ILog log = LogManager.GetLogger(typeof(LargeScreenEventController));
///
/// 构造函数
///
///
public LargeScreenEventController(ILargeScreenEventService repository)
{
_repository = repository;
}
///
/// 创建大屏控件事件
///
///
///
[HttpPost("CreateLargeScreenEventAsync")]
public async Task CreateLargeScreenEventAsync(LargeScreenEventViewModel content)
{
if (content == null)
{
return new ApiResult(ReturnCode.ArgsError);
}
try
{
await _repository.CreateOneAsync(content);
}
catch (Exception ex)
{
return new ApiResult(ReturnCode.GeneralError, ex.Message);
}
return new ApiResult(ReturnCode.Success);
}
///
/// 删除大屏控件事件
///
///
///
[HttpDelete("DeleteLargeScreenEventAsync/{id}")]
public async Task DeleteLargeScreenEventAsync(string id)
{
if (string.IsNullOrEmpty(id))
{
return new ApiResult(ReturnCode.GeneralError);
}
try
{
await _repository.DeleteAsync(id);
}
catch (Exception ex)
{
return new ApiResult(ReturnCode.GeneralError, ex.Message);
}
return new ApiResult(ReturnCode.Success);
}
///
/// 更新大屏控件事件
///
///
///
///
[HttpPut("UpdateLargeScreenEventAsync/{id}")]
[AllowAnonymous]
public async Task UpdateLargeScreenEventAsync(string id, LargeScreenEventViewModel updateModel)
{
if (string.IsNullOrEmpty(id))
{
return new ApiResult(ReturnCode.GeneralError);
}
try
{
await _repository.UpdateAsync(updateModel, id);
}
catch (Exception ex)
{
return new ApiResult(ReturnCode.GeneralError, ex.Message);
}
return new ApiResult(ReturnCode.Success);
}
///
/// 获取大屏控件事件列表
///
///
[HttpPost("GetLargeScreenEventAsync")]
[AllowAnonymous]
public async Task GetLargeScreenEventAsync(LargeScreenEventSearch searchModel)
{
if (searchModel == null)
{
return new ApiResult(ReturnCode.ArgsError);
}
try
{
var contentList = await _repository.GetConditionAsync(searchModel);
return new ApiResult>(new PagesModel(contentList, searchModel));
}
catch (Exception ex)
{
return new ApiResult(ReturnCode.GeneralError, ex.Message);
}
}
///
/// 通过id获取大屏控件事件详情
///
///
[HttpGet("GetLargeScreenEventByIDAsync")]
[AllowAnonymous]
public async Task GetLargeScreenEventByIDAsync(string Id)
{
if (string.IsNullOrEmpty(Id))
{
return new ApiResult(ReturnCode.ArgsError);
}
try
{
LargeScreenEventViewModel data = await _repository.GetByIdAsync(Id);
return new ApiResult(data);
}
catch (Exception ex)
{
return new ApiResult(ReturnCode.GeneralError, ex.Message);
}
}
}
}