using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Ropin.Inspection.Api.Common; using Ropin.Inspection.Api.Controllers; using Ropin.Inspection.Model; using Ropin.Inspection.Service; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Ropin.Inspection.Api { public class TdevDeviceTempArchivesController : BaseController { public ILogger _logger { get; } private readonly ITdevDeviceTempArchivesService _TdevDeviceTempArchivesService; /// /// 构造函数 /// /// /// public TdevDeviceTempArchivesController(ITdevDeviceTempArchivesService TdevDeviceTempArchivesService, ILogger logger) { _TdevDeviceTempArchivesService = TdevDeviceTempArchivesService; _logger = logger; } /// /// 通过id获取设备模板档案信息 /// /// /// [HttpGet("GetDeviceTempArchivesAsync/{id}")] public async Task GetDeviceTempArchivesAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { var content = await _TdevDeviceTempArchivesService.GetConditionAsync(new TdevDeviceTempArchivesSearchModel { C_ID = id }); return new ApiResult(content.FirstOrDefault()); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取所有设备模板档案 /// /// [HttpGet("GetDeviceTempArchivessAsync")] public async Task GetDeviceTempArchivessAsync() { try { var contentList = await _TdevDeviceTempArchivesService.GetAllAsync(); return new ApiResult>(contentList); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 通过设备模板档案名称条件查询 /// /// /// [HttpPost("GetDeviceTempArchivessByAsync")] public async Task GetDeviceTempArchivessByAsync(TdevDeviceTempArchivesSearchModel searchModel) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } searchModel.IsPagination = false; try { var contentList = await _TdevDeviceTempArchivesService.GetConditionAsync(searchModel); return new ApiResult>(new PagesModel(contentList, searchModel)); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 创建设备模板档案 /// /// /// [HttpPost("CreateDeviceTempArchivesAsync")] public async Task CreateDeviceTempArchivesAsync(TdevDeviceTempArchivesViewModel content) { if (content == null) { return new ApiResult(ReturnCode.ArgsError); } try { await _TdevDeviceTempArchivesService.CreateOneAsync(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 删除设备模板档案 /// /// /// [HttpDelete("DeleteDeviceTempArchivesAsync/{id}")] public async Task DeleteDeviceTempArchivesAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _TdevDeviceTempArchivesService.DeleteAsync(id); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 更新设备模板档案 /// /// /// /// [HttpPut("UpdateDeviceTempArchivesAsync/{id}")] public async Task UpdateDeviceTempArchivesAsync(string id, TdevDeviceTempArchivesUpdateModel updateModel) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _TdevDeviceTempArchivesService.UpdateAsync(id, updateModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } } }