mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 11:53:12 +00:00
69 lines
1.7 KiB
C#
69 lines
1.7 KiB
C#
using Api.SeaHavenIndustries.DTOs;
|
|
using Data.SeaHavenIndustries;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
[ApiController]
|
|
[Route("api/PMSchedule")]
|
|
public class PMScheduleController : ControllerBase
|
|
{
|
|
private readonly ApplicationDbContext _db;
|
|
|
|
public PMScheduleController(ApplicationDbContext db)
|
|
{
|
|
_db = db;
|
|
}
|
|
|
|
[HttpGet("GetList")]
|
|
public IActionResult GetList()
|
|
{
|
|
var data = _db.PMSchedules
|
|
.Include(x => x.Asset)
|
|
.Include(x => x.Location)
|
|
.OrderByDescending(x => x.Id)
|
|
.Select(x => new
|
|
{
|
|
x.Id,
|
|
x.Name,
|
|
x.Frequency,
|
|
x.StartDate,
|
|
x.IsActive,
|
|
Asset = x.Asset != null ? x.Asset.Name : null,
|
|
Location = x.Location != null ? x.Location.Name : null
|
|
})
|
|
.ToList();
|
|
|
|
return Ok(data);
|
|
}
|
|
|
|
[HttpPost("Save")]
|
|
public async Task<IActionResult> Save(PMSchedule_DTO dto)
|
|
{
|
|
PMSchedules model;
|
|
|
|
if (dto.Id == 0)
|
|
{
|
|
model = new PMSchedules
|
|
{
|
|
CreatedDate = DateTime.UtcNow
|
|
};
|
|
_db.PMSchedules.Add(model);
|
|
}
|
|
else
|
|
{
|
|
model = await _db.PMSchedules.FindAsync(dto.Id);
|
|
if (model == null) return NotFound();
|
|
model.LastModificationTime = DateTime.UtcNow;
|
|
}
|
|
|
|
model.Name = dto.Name;
|
|
model.Frequency = dto.Frequency;
|
|
model.StartDate = dto.StartDate;
|
|
model.IsActive = dto.IsActive;
|
|
model.AssetId = dto.AssetId;
|
|
model.LocationId = dto.LocationId;
|
|
|
|
await _db.SaveChangesAsync();
|
|
return Ok();
|
|
}
|
|
}
|