WIP
This commit is contained in:
@@ -4,4 +4,7 @@ namespace ROLAC.API.Services;
|
||||
public interface IMinistryService
|
||||
{
|
||||
Task<List<MinistryDto>> GetAllAsync(bool includeInactive);
|
||||
Task<int> CreateAsync(CreateMinistryRequest request);
|
||||
Task UpdateAsync(int id, UpdateMinistryRequest request);
|
||||
Task DeactivateAsync(int id); // soft-disable: IsActive = false
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ROLAC.API.Data;
|
||||
using ROLAC.API.DTOs.Ministry;
|
||||
using ROLAC.API.Entities;
|
||||
|
||||
namespace ROLAC.API.Services;
|
||||
|
||||
@@ -18,8 +19,40 @@ public class MinistryService : IMinistryService
|
||||
.Select(m => new MinistryDto
|
||||
{
|
||||
Id = m.Id, Name_en = m.Name_en, Name_zh = m.Name_zh,
|
||||
Description_en = m.Description_en, Description_zh = m.Description_zh,
|
||||
SortOrder = m.SortOrder, IsActive = m.IsActive,
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<int> CreateAsync(CreateMinistryRequest r)
|
||||
{
|
||||
var entity = new Ministry
|
||||
{
|
||||
Name_en = r.Name_en, Name_zh = r.Name_zh,
|
||||
Description_en = r.Description_en, Description_zh = r.Description_zh,
|
||||
SortOrder = r.SortOrder, IsActive = true,
|
||||
};
|
||||
_db.Ministries.Add(entity);
|
||||
await _db.SaveChangesAsync();
|
||||
return entity.Id;
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(int id, UpdateMinistryRequest r)
|
||||
{
|
||||
var m = await _db.Ministries.FindAsync(id)
|
||||
?? throw new KeyNotFoundException($"Ministry {id} not found.");
|
||||
m.Name_en = r.Name_en; m.Name_zh = r.Name_zh;
|
||||
m.Description_en = r.Description_en; m.Description_zh = r.Description_zh;
|
||||
m.IsActive = r.IsActive; m.SortOrder = r.SortOrder;
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task DeactivateAsync(int id)
|
||||
{
|
||||
var m = await _db.Ministries.FindAsync(id)
|
||||
?? throw new KeyNotFoundException($"Ministry {id} not found.");
|
||||
m.IsActive = false;
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user