mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-01 12:13:13 +00:00
80 lines
2.3 KiB
C#
80 lines
2.3 KiB
C#
using Api.SeaHavenIndustries.DTOs;
|
|
using Data.SeaHavenIndustries;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SeaHaven.Services.Interfaces;
|
|
using SeaHaven.Services.DTOs;
|
|
|
|
[ApiController]
|
|
[Route("api/PMSchedule")]
|
|
[Route("api/pmschedules")]
|
|
public class PMScheduleController : ControllerBase
|
|
{
|
|
private readonly IPMScheduleService _pmScheduleService;
|
|
|
|
public PMScheduleController(IPMScheduleService pmScheduleService)
|
|
{
|
|
_pmScheduleService = pmScheduleService;
|
|
}
|
|
|
|
[HttpGet("GetList")]
|
|
public async Task<IActionResult> GetList()
|
|
{
|
|
var items = await _pmScheduleService.GetAllPMSchedulesAsync();
|
|
|
|
var data = items.Select(x => new
|
|
{
|
|
Id = x.Id,
|
|
Name = x.Name,
|
|
Frequency = x.Frequency,
|
|
StartDate = x.StartDate,
|
|
IsActive = x.IsActive,
|
|
Asset = x.AssetName,
|
|
Location = x.LocationName
|
|
});
|
|
|
|
return Ok(data);
|
|
}
|
|
|
|
[HttpPost("Save")]
|
|
public async Task<IActionResult> Save(PMSchedule_DTO dto)
|
|
{
|
|
try
|
|
{
|
|
var userId = User.Identity?.Name ?? "system";
|
|
|
|
if (dto.Id == 0)
|
|
{
|
|
var createDto = new CreatePMScheduleDTO
|
|
{
|
|
Name = dto.Name,
|
|
Frequency = dto.Frequency,
|
|
StartDate = dto.StartDate,
|
|
IsActive = dto.IsActive,
|
|
AssetId = dto.AssetId,
|
|
LocationId = dto.LocationId
|
|
};
|
|
await _pmScheduleService.CreatePMScheduleAsync(createDto, userId);
|
|
}
|
|
else
|
|
{
|
|
var updateDto = new UpdatePMScheduleDTO
|
|
{
|
|
Name = dto.Name,
|
|
Frequency = dto.Frequency,
|
|
StartDate = dto.StartDate,
|
|
IsActive = dto.IsActive,
|
|
AssetId = dto.AssetId,
|
|
LocationId = dto.LocationId
|
|
};
|
|
await _pmScheduleService.UpdatePMScheduleAsync(dto.Id, updateDto, userId);
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BadRequest(new { Message = ex.Message });
|
|
}
|
|
}
|
|
}
|