แก้ api เพิ่มเติมการ upload image and document
This commit is contained in:
parent
86ec5de116
commit
6acd497afe
23 changed files with 4081 additions and 53 deletions
|
|
@ -336,6 +336,10 @@ namespace BMA.EHR.Recruit.Service.Controllers
|
|||
try
|
||||
{
|
||||
var data = await _context.RecruitImports.AsQueryable()
|
||||
.Include(x => x.RecruitImages)
|
||||
.ThenInclude(x => x.Document)
|
||||
.Include(x => x.RecruitDocuments)
|
||||
.ThenInclude(x => x.Document)
|
||||
.Include(x => x.ImportFile)
|
||||
.Include(x => x.Recruits)
|
||||
.ThenInclude(x => x.Addresses)
|
||||
|
|
@ -352,7 +356,34 @@ namespace BMA.EHR.Recruit.Service.Controllers
|
|||
.ThenInclude(x => x.DocumentFile)
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
return Success(data);
|
||||
var new_image = new List<dynamic>();
|
||||
foreach (var p in data.RecruitImages)
|
||||
{
|
||||
new_image.Add(new
|
||||
{
|
||||
p.Id,
|
||||
p.Document.FileName,
|
||||
p.Document.FileSize,
|
||||
p.Document.FileType,
|
||||
detail = _minioService.GetFilePath(p.Document.Id).Result,
|
||||
});
|
||||
}
|
||||
|
||||
// re create doc list
|
||||
var new_doc = new List<dynamic>();
|
||||
foreach (var p in data.RecruitDocuments)
|
||||
{
|
||||
new_doc.Add(new
|
||||
{
|
||||
p.Id,
|
||||
p.Document.FileName,
|
||||
p.Document.FileSize,
|
||||
p.Document.FileType,
|
||||
detail = _minioService.GetFilePath(p.Document.Id).Result,
|
||||
});
|
||||
}
|
||||
|
||||
return Success(new { periods = data, images = new_image, files = new_doc });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -382,7 +413,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
|
|||
if (req == null)
|
||||
return Error(GlobalMessages.InvalidRequestParam, (int)HttpStatusCode.BadRequest);
|
||||
|
||||
await _context.RecruitImports.AddAsync(new RecruitImport
|
||||
var import = new RecruitImport
|
||||
{
|
||||
Year = req.Year,
|
||||
Name = req.Name,
|
||||
|
|
@ -398,11 +429,12 @@ namespace BMA.EHR.Recruit.Service.Controllers
|
|||
PaymentEndDate = req.PaymentEndDate,
|
||||
Note = req.Note,
|
||||
AnnouncementDate = req.AnnouncementDate,
|
||||
});
|
||||
};
|
||||
await _context.RecruitImports.AddAsync(import);
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
return Success(import);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -451,7 +483,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
|
|||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
return Success(data);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -1462,33 +1494,82 @@ namespace BMA.EHR.Recruit.Service.Controllers
|
|||
{
|
||||
try
|
||||
{
|
||||
var periods = _context.RecruitImports.AsQueryable()
|
||||
.Where(x => x.Year.ToCeYear() == DateTime.Now.Year.ToCeYear())
|
||||
.Select(r => new
|
||||
{
|
||||
id = r.Id,
|
||||
title = $"{r.Name} ครั้งที่ {r.Order}/{r.Year.ToThaiYear()}",
|
||||
category = "สำนักงาน ก.ก.",
|
||||
category_id = 1,
|
||||
announcement_startDate = r.AnnouncementStartDate == null ? "" : r.AnnouncementStartDate.Value.ToString("yyyy-mm-dd"),
|
||||
announcement_endDate = r.AnnouncementEndDate == null ? "" : r.AnnouncementEndDate.Value.ToString("yyyy-MM-dd"),
|
||||
announcementExam = true,
|
||||
register_startDate = r.RegisterStartDate == null ? "" : r.RegisterStartDate.Value.ToString("yyyy-MM-dd"),
|
||||
register_endDate = r.RegisterEndDate == null ? "" : r.RegisterEndDate.Value.ToString("yyyy-MM-dd"),
|
||||
payment_startDate = r.PaymentStartDate == null ? "" : r.PaymentStartDate.Value.ToString("yyyy-MM-dd"),
|
||||
payment_endDate = r.PaymentEndDate == null ? "" : r.PaymentEndDate.Value.ToString("yyyy-MM-dd"),
|
||||
exam_date = r.ExamDate == null ? "" : r.ExamDate.Value.ToString("yyyy-MM-dd")
|
||||
var this_year = DateTime.Now.Year.ToCeYear();
|
||||
|
||||
var periods = (from r in _context.RecruitImports.AsQueryable().Include(x => x.RecruitImages)
|
||||
where r.Year == this_year
|
||||
orderby r.AnnouncementStartDate descending
|
||||
select new
|
||||
{
|
||||
id = r.Id,
|
||||
title = $"{r.Name} ครั้งที่ {r.Order}/{r.Year.ToThaiYear()}",
|
||||
category = "สำนักงาน ก.ก.",
|
||||
category_id = 1,
|
||||
announcement_startDate = r.AnnouncementStartDate == null ? "" : r.AnnouncementStartDate.Value.ToString("yyyy-mm-dd"),
|
||||
announcement_endDate = r.AnnouncementEndDate == null ? "" : r.AnnouncementEndDate.Value.ToString("yyyy-MM-dd"),
|
||||
announcementExam = true,
|
||||
register_startDate = r.RegisterStartDate == null ? "" : r.RegisterStartDate.Value.ToString("yyyy-MM-dd"),
|
||||
register_endDate = r.RegisterEndDate == null ? "" : r.RegisterEndDate.Value.ToString("yyyy-MM-dd"),
|
||||
payment_startDate = r.PaymentStartDate == null ? "" : r.PaymentStartDate.Value.ToString("yyyy-MM-dd"),
|
||||
payment_endDate = r.PaymentEndDate == null ? "" : r.PaymentEndDate.Value.ToString("yyyy-MM-dd"),
|
||||
exam_date = r.ExamDate == null ? "" : r.ExamDate.Value.ToString("yyyy-MM-dd"),
|
||||
image = r.RecruitImages.OrderBy(o => o.CreatedAt).FirstOrDefault() == null ? "" :
|
||||
r.RecruitImages.OrderBy(o => o.CreatedAt).FirstOrDefault().Document.Id.ToString("D")
|
||||
})
|
||||
|
||||
.ToList();
|
||||
|
||||
|
||||
//var periods = _context.RecruitImports.AsQueryable()
|
||||
// .Where(x => x.Year == this_year)
|
||||
// .Include(x => x.RecruitImages)
|
||||
// .Select(r => new
|
||||
// {
|
||||
// id = r.Id,
|
||||
// title = $"{r.Name} ครั้งที่ {r.Order}/{r.Year.ToThaiYear()}",
|
||||
// category = "สำนักงาน ก.ก.",
|
||||
// category_id = 1,
|
||||
// announcement_startDate = r.AnnouncementStartDate == null ? "" : r.AnnouncementStartDate.Value.ToString("yyyy-mm-dd"),
|
||||
// announcement_endDate = r.AnnouncementEndDate == null ? "" : r.AnnouncementEndDate.Value.ToString("yyyy-MM-dd"),
|
||||
// announcementExam = true,
|
||||
// register_startDate = r.RegisterStartDate == null ? "" : r.RegisterStartDate.Value.ToString("yyyy-MM-dd"),
|
||||
// register_endDate = r.RegisterEndDate == null ? "" : r.RegisterEndDate.Value.ToString("yyyy-MM-dd"),
|
||||
// payment_startDate = r.PaymentStartDate == null ? "" : r.PaymentStartDate.Value.ToString("yyyy-MM-dd"),
|
||||
// payment_endDate = r.PaymentEndDate == null ? "" : r.PaymentEndDate.Value.ToString("yyyy-MM-dd"),
|
||||
// exam_date = r.ExamDate == null ? "" : r.ExamDate.Value.ToString("yyyy-MM-dd"),
|
||||
// image = r.RecruitImages.OrderBy(o => o.CreatedAt).FirstOrDefault() == null ? "" :
|
||||
// r.RecruitImages.OrderBy(o => o.CreatedAt).FirstOrDefault().Document.Id.ToString("D")
|
||||
// })
|
||||
// .OrderByDescending(x => x.announcement_startDate)
|
||||
// .ToList();
|
||||
|
||||
});
|
||||
|
||||
|
||||
if (limit > 0)
|
||||
periods = periods.Take(limit);
|
||||
periods = periods.Take(limit).ToList();
|
||||
|
||||
periods = periods.AsQueryable()
|
||||
.OrderByDescending(x => x.announcement_startDate);
|
||||
|
||||
return Ok(periods.ToList());
|
||||
var result = new List<dynamic>();
|
||||
foreach (var p in periods)
|
||||
{
|
||||
result.Add(new
|
||||
{
|
||||
p.id,
|
||||
p.title,
|
||||
p.category,
|
||||
p.category_id,
|
||||
p.announcementExam,
|
||||
p.announcement_startDate,
|
||||
p.announcement_endDate,
|
||||
p.register_endDate,
|
||||
p.register_startDate,
|
||||
p.payment_startDate,
|
||||
p.payment_endDate,
|
||||
p.exam_date,
|
||||
image = p.image == "" ? "" : _minioService.GetFilePath(Guid.Parse(p.image)).Result,
|
||||
});
|
||||
}
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -1502,29 +1583,86 @@ namespace BMA.EHR.Recruit.Service.Controllers
|
|||
{
|
||||
try
|
||||
{
|
||||
var periods = _context.RecruitImports.AsQueryable()
|
||||
.Where(x => x.Id == id)
|
||||
.Select(r => new
|
||||
{
|
||||
id = r.Id,
|
||||
title = $"{r.Name} ครั้งที่ {r.Order}/{r.Year.ToThaiYear()}",
|
||||
detail = r.Detail,
|
||||
category = "สำนักงาน ก.ก.",
|
||||
category_id = 1,
|
||||
announcement_startDate = r.AnnouncementStartDate == null ? "" : r.AnnouncementStartDate.Value.ToString("yyyy-mm-dd"),
|
||||
announcement_endDate = r.AnnouncementEndDate == null ? "" : r.AnnouncementEndDate.Value.ToString("yyyy-MM-dd"),
|
||||
start = r.AnnouncementStartDate == null ? "" : r.AnnouncementStartDate.Value.ToString("yyyy-mm-dd"),
|
||||
end = r.AnnouncementEndDate == null ? "" : r.AnnouncementEndDate.Value.ToString("yyyy-MM-dd"),
|
||||
announcementExam = true,
|
||||
register_startDate = r.RegisterStartDate == null ? "" : r.RegisterStartDate.Value.ToString("yyyy-MM-dd"),
|
||||
register_endDate = r.RegisterEndDate == null ? "" : r.RegisterEndDate.Value.ToString("yyyy-MM-dd"),
|
||||
payment_startDate = r.PaymentStartDate == null ? "" : r.PaymentStartDate.Value.ToString("yyyy-MM-dd"),
|
||||
payment_endDate = r.PaymentEndDate == null ? "" : r.PaymentEndDate.Value.ToString("yyyy-MM-dd"),
|
||||
examDate = r.ExamDate == null ? "" : r.ExamDate.Value.ToString("yyyy-MM-dd")
|
||||
|
||||
});
|
||||
var periods = (from r in _context.RecruitImports.AsQueryable()
|
||||
.Include(x => x.RecruitDocuments)
|
||||
.ThenInclude(x => x.Document)
|
||||
.Include(x => x.RecruitImages)
|
||||
.ThenInclude(x => x.Document)
|
||||
where r.Id == id
|
||||
select new
|
||||
{
|
||||
id = r.Id,
|
||||
title = $"{r.Name} ครั้งที่ {r.Order}/{r.Year.ToThaiYear()}",
|
||||
detail = r.Detail,
|
||||
category = "สำนักงาน ก.ก.",
|
||||
category_id = 1,
|
||||
announcement_startDate = r.AnnouncementStartDate == null ? "" : r.AnnouncementStartDate.Value.ToString("yyyy-mm-dd"),
|
||||
announcement_endDate = r.AnnouncementEndDate == null ? "" : r.AnnouncementEndDate.Value.ToString("yyyy-MM-dd"),
|
||||
start = r.AnnouncementStartDate == null ? "" : r.AnnouncementStartDate.Value.ToString("yyyy-mm-dd"),
|
||||
end = r.AnnouncementEndDate == null ? "" : r.AnnouncementEndDate.Value.ToString("yyyy-MM-dd"),
|
||||
announcementExam = true,
|
||||
register_startDate = r.RegisterStartDate == null ? "" : r.RegisterStartDate.Value.ToString("yyyy-MM-dd"),
|
||||
register_endDate = r.RegisterEndDate == null ? "" : r.RegisterEndDate.Value.ToString("yyyy-MM-dd"),
|
||||
payment_startDate = r.PaymentStartDate == null ? "" : r.PaymentStartDate.Value.ToString("yyyy-MM-dd"),
|
||||
payment_endDate = r.PaymentEndDate == null ? "" : r.PaymentEndDate.Value.ToString("yyyy-MM-dd"),
|
||||
examDate = r.ExamDate == null ? "" : r.ExamDate.Value.ToString("yyyy-MM-dd"),
|
||||
Images = r.RecruitImages.OrderBy(x => x.CreatedAt).Select(s => new
|
||||
{
|
||||
Title = s.Document.FileName,
|
||||
Url = s.Document.Id.ToString("D")
|
||||
}).ToList(),
|
||||
Files = r.RecruitDocuments.OrderBy(x => x.CreatedAt).Select(s => new
|
||||
{
|
||||
Title = s.Document.FileName,
|
||||
Url = s.Document.Id.ToString("D")
|
||||
}).ToList(),
|
||||
}).FirstOrDefault();
|
||||
|
||||
return Ok(periods.FirstOrDefault());
|
||||
// re create image list
|
||||
var new_image = new List<dynamic>();
|
||||
foreach (var p in periods.Images)
|
||||
{
|
||||
new_image.Add(new
|
||||
{
|
||||
Title = p.Title,
|
||||
Url = _minioService.GetFilePath(Guid.Parse(p.Url)).Result,
|
||||
});
|
||||
}
|
||||
|
||||
// re create doc list
|
||||
var new_doc = new List<dynamic>();
|
||||
foreach (var p in periods.Files)
|
||||
{
|
||||
new_doc.Add(new
|
||||
{
|
||||
Title = p.Title,
|
||||
Url = _minioService.GetFilePath(Guid.Parse(p.Url)).Result,
|
||||
});
|
||||
}
|
||||
|
||||
var result = new
|
||||
{
|
||||
periods.id,
|
||||
periods.title,
|
||||
periods.detail,
|
||||
periods.category,
|
||||
periods.category_id,
|
||||
periods.announcement_endDate,
|
||||
periods.announcement_startDate,
|
||||
periods.start,
|
||||
periods.end,
|
||||
periods.announcementExam,
|
||||
periods.register_endDate,
|
||||
periods.register_startDate,
|
||||
periods.payment_endDate,
|
||||
periods.payment_startDate,
|
||||
periods.examDate,
|
||||
images = new_image,
|
||||
files = new_doc
|
||||
};
|
||||
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -1825,6 +1963,81 @@ namespace BMA.EHR.Recruit.Service.Controllers
|
|||
|
||||
#endregion
|
||||
|
||||
#region " Image and Document "
|
||||
|
||||
/// <summary>
|
||||
/// Upload Image หรือ เอกสารในรอบการสอบ
|
||||
/// </summary>
|
||||
/// <param name="type">ประเภทเอกสาร</param>
|
||||
/// <param name="importId">รหัสรอบสมัคร</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">เมื่อทำการอ่านข้อมูลรอบการสมัครสอบ และ คนสมัครสอบในรอบสำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("{type}/{importId:length(36)}"), DisableRequestSizeLimit]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> UpdateDocAsync(string type, Guid importId)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Request.Form.Files == null || Request.Form.Files.Count == 0)
|
||||
{
|
||||
return Error(GlobalMessages.NoFileToUpload);
|
||||
}
|
||||
|
||||
var files = Request.Form.Files;
|
||||
if (type == "img")
|
||||
{
|
||||
await _recruitService.UpdateImageAsync(importId, files);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _recruitService.UpdateDocAsync(importId, files);
|
||||
}
|
||||
|
||||
return Success();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ลบ Image หรือ เอกสารในรอบการสอบ
|
||||
/// </summary>
|
||||
/// <param name="type">ประเภทเอกสาร</param>
|
||||
/// <param name="docId">รหัสไฟล์</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpDelete("{type}/{docId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> DeleteDocAsync(string type, Guid docId)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (type == "img")
|
||||
{
|
||||
await _recruitService.DeleteImageAsync(docId);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _recruitService.DeleteDocAsync(docId);
|
||||
}
|
||||
|
||||
return Success();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Error(ex, "ไม่สามารถลบไฟล์ได้");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue