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 TdevDevicePartController : BaseController { public ILogger _logger { get; } private readonly ITdevDevicePartService _TdevDevicePartService; /// /// 构造函数 /// /// /// public TdevDevicePartController(ITdevDevicePartService TdevDevicePartService, ILogger logger) { _TdevDevicePartService = TdevDevicePartService; _logger = logger; } /// /// 通过id获取设备零配件信息 /// /// /// [HttpGet("GetDevicePartAsync/{id}")] public async Task GetDevicePartAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { var content = await _TdevDevicePartService.GetConditionAsync(new TdevDevicePartSearchModel { C_ID = id }); return new ApiResult(content.FirstOrDefault()); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取所有设备零配件 /// /// [HttpGet("GetDevicePartsAsync")] public async Task GetDevicePartsAsync() { try { var contentList = await _TdevDevicePartService.GetAllAsync(); return new ApiResult>(contentList); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 通过设备零配件名称条件查询 /// /// /// [HttpPost("GetDevicePartsByAsync")] public async Task GetDevicePartsByAsync(TdevDevicePartSearchModel searchModel) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } searchModel.IsPagination = false; try { var contentList = await _TdevDevicePartService.GetConditionAsync(searchModel); return new ApiResult>(new PagesModel(contentList, searchModel)); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 创建设备零配件 /// /// /// [HttpPost("CreateDevicePartAsync")] public async Task CreateDevicePartAsync(TdevDevicePartViewModel content) { if (content == null) { return new ApiResult(ReturnCode.ArgsError); } try { await _TdevDevicePartService.CreateOneAsync(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 删除设备零配件 /// /// /// [HttpDelete("DeleteDevicePartAsync/{id}")] public async Task DeleteDevicePartAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _TdevDevicePartService.DeleteAsync(id); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 更新设备零配件 /// /// /// /// [HttpPut("UpdateDevicePartAsync/{id}")] public async Task UpdateDevicePartAsync(string id, TdevDevicePartUpdateModel updateModel) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _TdevDevicePartService.UpdateAsync(id, updateModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } } }