shoc-backend/Api.SeaHavenIndustries/Controllers/PMScheduleController.cs
Adam Moussa 60fc933da7 Add lowercase route aliases for all controllers
- services/api.js uses lowercase routes (/api/workorders, /api/employees, etc.)
- Add matching [Route] attributes to WorkOrder, Employee, Contact, Account, FollowUp, PMSchedule controllers
- Add [HttpGet("{id:int}")] to WorkOrderController for REST-style get by ID
2026-04-16 17:32:28 -04:00

70 lines
1.8 KiB
C#

using Api.SeaHavenIndustries.DTOs;
using Data.SeaHavenIndustries;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
[ApiController]
[Route("api/PMSchedule")]
[Route("api/pmschedules")]
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();
}
}