From 9182892dd72ca152bcdac83c9049b01d7482e635 Mon Sep 17 00:00:00 2001 From: anhdtn2403 Date: Mon, 22 Jul 2024 01:35:41 +0700 Subject: [PATCH] fix: Schedules View, Create, --- .../Controllers/SchedulesController.cs | 31 ++++++++-- .../Manager/Views/Schedules/Create.cshtml | 61 +++++++++++++++---- .../Areas/Manager/Views/Schedules/Edit.cshtml | 8 --- .../Manager/Views/Schedules/Index.cshtml | 16 ----- 4 files changed, 76 insertions(+), 40 deletions(-) diff --git a/Dental_Clinic_System/Dental_Clinic_System/Areas/Manager/Controllers/SchedulesController.cs b/Dental_Clinic_System/Dental_Clinic_System/Areas/Manager/Controllers/SchedulesController.cs index 5b6639ba..2b80de22 100644 --- a/Dental_Clinic_System/Dental_Clinic_System/Areas/Manager/Controllers/SchedulesController.cs +++ b/Dental_Clinic_System/Dental_Clinic_System/Areas/Manager/Controllers/SchedulesController.cs @@ -293,7 +293,7 @@ private List GenerateTimeSlots(int workTimeId) // Retrieve the matching TimeSlots return _context.TimeSlots - .Where(ts => ts.StartTime >= startTime && ts.EndTime <= endTime).ToList(); + .Where(ts => ts.StartTime >= startTime && ts.EndTime <= endTime && ts.ID != 1 && ts.ID != 2).ToList(); } #endregion @@ -521,6 +521,17 @@ public IActionResult Create() { // Check if session has expired, log out return RedirectToAction("Logout", "ManagerAccount", new { area = "Manager" }); } + //--------------------------------------------------- + //Generate 2 list timeSlot dựa trên WorkTime Sáng vs Chiều + var clinic = _context.Clinics.Include(c => c.AmWorkTimes).Include(c => c.PmWorkTimes).FirstOrDefault(m => m.ID == clinicId); + var amID = clinic.AmWorkTimeID; + var pmID = clinic.PmWorkTimeID; + List amTimeSlots = GenerateTimeSlots(amID); + List pmTimeSlots = GenerateTimeSlots(pmID); + ViewBag.AmTimeSlots = amTimeSlots; + ViewBag.PmTimeSlots = pmTimeSlots; + + //-------------------------------------------------- var dentists = _context.Dentists .Join(_context.Accounts, dentist => dentist.AccountID, @@ -564,8 +575,18 @@ public async Task Create([Bind("DentistIDs, Dates, TimeSlots")] S .ToList(); ViewData["DentistID"] = new SelectList(dentists.Where(d => d.ClinicID == clinicId && d.Status == "Hoạt Động"), "DentistID", "FullName"); - //--------------------------------------------------------------------------------------------------------------------------------------- - if (schedule.DentistIDs.Count == 0) + //--------------------------------------------------- + //Generate 2 list timeSlot dựa trên WorkTime Sáng vs Chiều + var clinic = _context.Clinics.Include(c => c.AmWorkTimes).Include(c => c.PmWorkTimes).FirstOrDefault(m => m.ID == clinicId); + var amID = clinic.AmWorkTimeID; + var pmID = clinic.PmWorkTimeID; + List amTimeSlots = GenerateTimeSlots(amID); + List pmTimeSlots = GenerateTimeSlots(pmID); + ViewBag.AmTimeSlots = amTimeSlots; + ViewBag.PmTimeSlots = pmTimeSlots; + + //----------------------------------------------------------------------------- + if (schedule.DentistIDs.Count == 0) { TempData["ToastMessageFailTempData"] = "Bạn chưa chọn nha sĩ nào."; return View(schedule); @@ -591,7 +612,7 @@ public async Task Create([Bind("DentistIDs, Dates, TimeSlots")] S foreach (var slot in schedule.TimeSlots) { var existSchedule = await _context.Schedules.FirstOrDefaultAsync( - a => a.DentistID == dentist && a.Date == date && a.TimeSlotID == slot); + a => a.DentistID == dentist && a.Date == date && a.TimeSlotID == slot && a.ScheduleStatus != "Đã Hủy"); if (existSchedule == null) { @@ -727,7 +748,7 @@ public async Task EditStatusTo_ConTrong(int? dentistId, DateOnly? public async Task Delete(int? dentistId, DateTime? date) { var scheduleSubList = _context.Schedules.Where(p => - p.DentistID == dentistId && p.Date == DateOnly.FromDateTime(date.Value) && p.ScheduleStatus != "Đã Đặt" && p.ScheduleStatus != "Đã Hủy" && p.TimeSlotID != 31); + p.DentistID == dentistId && p.Date == DateOnly.FromDateTime(date.Value) && p.ScheduleStatus != "Đã Đặt" && p.ScheduleStatus != "Đã Hủy" && p.TimeSlotID != 32); if (scheduleSubList.Any()) { _context.Schedules.RemoveRange(scheduleSubList); diff --git a/Dental_Clinic_System/Dental_Clinic_System/Areas/Manager/Views/Schedules/Create.cshtml b/Dental_Clinic_System/Dental_Clinic_System/Areas/Manager/Views/Schedules/Create.cshtml index 3ac75a30..3dc006b4 100644 --- a/Dental_Clinic_System/Dental_Clinic_System/Areas/Manager/Views/Schedules/Create.cshtml +++ b/Dental_Clinic_System/Dental_Clinic_System/Areas/Manager/Views/Schedules/Create.cshtml @@ -168,19 +168,58 @@
+
- - - -
@* List TimeSlots đc lưu trong checkbox.name=TimeSlots *@ + +
+ +
+ @{ + var sangSlots = ViewBag.AmTimeSlots; + } + @for (int i = 0; i < sangSlots.Count; i += 3) + { +
+ @for (int j = i; j < i + 3 && j < sangSlots.Count; j++) + { + + var slot = sangSlots[j]; + var isChecked = Model.TimeSlots != null && Model.TimeSlots.Contains(slot.ID); +
+ + +
+ } +
+ } +
+ +
+ @{ + var chieuSlots = ViewBag.PmTimeSlots; + } + @for (int i = 0; i < chieuSlots.Count; i += 3) + { +
+ @for (int j = i; j < i + 3 && j < chieuSlots.Count; j++) + { + + var slot = chieuSlots[j]; + var isChecked = Model.TimeSlots != null && Model.TimeSlots.Contains(slot.ID); +
+ + +
+ } +
+ } +
@@ -190,7 +229,7 @@
@section Scripts { - + @* *@ diff --git a/Dental_Clinic_System/Dental_Clinic_System/Areas/Manager/Views/Schedules/Edit.cshtml b/Dental_Clinic_System/Dental_Clinic_System/Areas/Manager/Views/Schedules/Edit.cshtml index 597295b2..1b6d8656 100644 --- a/Dental_Clinic_System/Dental_Clinic_System/Areas/Manager/Views/Schedules/Edit.cshtml +++ b/Dental_Clinic_System/Dental_Clinic_System/Areas/Manager/Views/Schedules/Edit.cshtml @@ -199,14 +199,6 @@ { list.Add(slot.ID, ("Đã Đặt", time)); } - else if (slotIDs_Nghi.Contains(slot.ID)) - { - list.Add(slot.ID, ("Nghỉ", time)); - } - else if (slotIDs_ConTrong.Contains(slot.ID)) - { - list.Add(slot.ID, ("Còn Trống", time)); - } } } } diff --git a/Dental_Clinic_System/Dental_Clinic_System/Areas/Manager/Views/Schedules/Index.cshtml b/Dental_Clinic_System/Dental_Clinic_System/Areas/Manager/Views/Schedules/Index.cshtml index c622b3b0..b5efb5b4 100644 --- a/Dental_Clinic_System/Dental_Clinic_System/Areas/Manager/Views/Schedules/Index.cshtml +++ b/Dental_Clinic_System/Dental_Clinic_System/Areas/Manager/Views/Schedules/Index.cshtml @@ -345,14 +345,6 @@ {

@slot.StartTime.ToString("HH:mm") - @slot.EndTime.ToString("HH:mm")

} - else if (slotIDs_Nghi.Contains(slot.ID)) - { -

@slot.StartTime.ToString("HH:mm") - @slot.EndTime.ToString("HH:mm")

- } - else if (slotIDs_ConTrong.Contains(slot.ID)) - { -

@slot.StartTime.ToString("HH:mm") - @slot.EndTime.ToString("HH:mm")

- } } } } @@ -384,14 +376,6 @@

@slot.StartTime.ToString("HH:mm") - @slot.EndTime.ToString("HH:mm")

} } - else - { - if (!slotIDs_DaDat.Contains(slot.ID) && !slotIDs_Nghi.Contains(slot.ID) - && (slotIDs_ConTrong.Contains(slot.ID))) - { -

@slot.StartTime.ToString("HH:mm") - @slot.EndTime.ToString("HH:mm")

- } - } } } }