เพิ่มฟิว เบอร ให้apiข้อมูลผู้สมัคร

This commit is contained in:
Kittapath 2023-03-24 13:38:26 +07:00
parent 7f792bb8fd
commit 44d18ff74c
4 changed files with 160 additions and 37 deletions

View file

@ -64,6 +64,9 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
CitizenDate = x.CitizenDate,
Email = x.Email,
CitizenId = x.CitizenId,
Telephone = x.Telephone,
MobilePhone = x.MobilePhone,
Knowledge = x.Knowledge,
})
.FirstOrDefaultAsync();
}
@ -295,6 +298,9 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
candidate.Email = updated.Email;
candidate.CitizenId = updated.CitizenId;
candidate.CitizenDate = updated.CitizenDate;
candidate.Telephone = updated.Telephone;
candidate.MobilePhone = updated.MobilePhone;
candidate.Knowledge = updated.Knowledge;
await _context.SaveChangesAsync();
}

View file

@ -1,4 +1,5 @@
using System.Security.Claims;
using BMA.EHR.Recurit.Exam.Service.Core;
using BMA.EHR.Recurit.Exam.Service.Data;
using BMA.EHR.Recurit.Exam.Service.Models;
using Microsoft.EntityFrameworkCore;
@ -48,51 +49,58 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
.ToListAsync();
}
public async Task<PeriodExam?> GetByIdAsync(Guid id)
public async Task<PeriodExam?> GetsExamAndCandidateAsync(string id, bool showAll = true)
{
return await _context.PeriodExams.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, PeriodExam updated)
{
var existData = await _context.PeriodExams.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
if (existData.Name != updated.Name)
{
existData.Name = updated.Name;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
if (existData.IsActive != updated.IsActive)
{
existData.IsActive = updated.IsActive;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
await _context.SaveChangesAsync();
}
return await _context.PeriodExams.FirstOrDefaultAsync(x => x.Id == Guid.Parse(id));
}
public async Task CreateAsync(PeriodExam inserted)
{
inserted.CreatedUserId = UserId ?? "";
inserted.CreatedFullName = FullName ?? "System Administrator";
inserted.CreatedAt = DateTime.Now;
inserted.LastUpdatedAt = DateTime.Now;
inserted.LastUpdateFullName = FullName ?? "System Administrator";
inserted.LastUpdateUserId = UserId ?? "";
var periodExam = new PeriodExam
{
//xxxxxxxxxxxxxxxxxxxxxxx
CreatedAt = DateTime.Now,
CreatedUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
LastUpdateUserId = UserId ?? "",
CreatedFullName = FullName ?? "",
LastUpdateFullName = FullName ?? "",
};
await _context.PeriodExams.AddAsync(inserted);
await _context.PeriodExams.AddAsync(periodExam);
await _context.SaveChangesAsync();
}
public async Task UpdateAsync(string examId, PeriodExam updated)
{
var periodExam = await _context.PeriodExams.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (periodExam == null)
throw new Exception(GlobalMessages.ExamNotFound);
//xxxxxxxxxxxxxxxxxxxxx
periodExam.IsActive = updated.IsActive;
periodExam.LastUpdatedAt = DateTime.Now;
periodExam.LastUpdateUserId = UserId ?? "";
periodExam.LastUpdateFullName = FullName ?? "";
await _context.SaveChangesAsync();
}
public async Task DeleteAsync(string examId)
{
var periodExam = await _context.PeriodExams.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (periodExam == null)
throw new Exception(GlobalMessages.ExamNotFound);
_context.PeriodExams.Remove(periodExam);
await _context.SaveChangesAsync();
}
#endregion
}
}