public Trinity.DAL.DBContext.Queue InsertQueueNumberFromDO(string UserID, string station, string userCreateQueue) { var timeslot = GetTimeSlotEmpty(); if (timeslot == null) { throw new Trinity.Common.ExceptionArgs("Unable get queue.<br/>All time slots are close today."); } else { var listStation = EnumStation.GetListStation(); var generateQNo = Trinity.Common.CommonUtil.GetQueueNumber(_localUnitOfWork.DataContext.Membership_Users.Find(UserID).NRIC); Trinity.DAL.DBContext.Queue dataInsert = new Trinity.DAL.DBContext.Queue() { Queue_ID = Guid.NewGuid(), UserId = UserID, Timeslot_ID = timeslot.Timeslot_ID, CurrentStation = station, Outcome = EnumQueueOutcomeText.GetQueue, CreatedTime = DateTime.Now, QueuedNumber = generateQNo, Created_By = userCreateQueue }; List <Trinity.DAL.DBContext.QueueDetail> arrayQueueDetail = new List <Trinity.DAL.DBContext.QueueDetail>(); foreach (var item in listStation) { var queueDetails = new Trinity.DAL.DBContext.QueueDetail { Queue_ID = dataInsert.Queue_ID, Station = item, Status = EnumQueueStatuses.Waiting }; if (queueDetails.Station == EnumStation.APS) { queueDetails.Status = EnumQueueStatuses.Finished; } arrayQueueDetail.Add(queueDetails); } _localUnitOfWork.GetRepository <Trinity.DAL.DBContext.Queue>().Add(dataInsert); _localUnitOfWork.GetRepository <Trinity.DAL.DBContext.QueueDetail>().AddRange(arrayQueueDetail); _localUnitOfWork.Save(); return(dataInsert); } }
public Trinity.DAL.DBContext.Queue InsertQueueNumber(Guid appointmentID, string userId, string station, string userCreateQueue) { var generateQNo = Trinity.Common.CommonUtil.GetQueueNumber(_localUnitOfWork.DataContext.Membership_Users.Find(userId).NRIC); var listStation = EnumStation.GetListStation(); var today = DateTime.Now; var appointment = _localUnitOfWork.DataContext.Appointments.FirstOrDefault(d => d.ID == appointmentID); var timeslot = GetTimeSlotEmpty(); string timeslotID = string.Empty; if (string.IsNullOrEmpty(appointment.Timeslot_ID) && timeslot != null) { timeslotID = timeslot.Timeslot_ID; } else if (!string.IsNullOrEmpty(appointment.Timeslot_ID)) { if (timeslot != null && timeslot.EndTime < appointment.Timeslot.EndTime) { timeslotID = timeslot.Timeslot_ID; } else if (appointment.Timeslot.EndTime > DateTime.Now.TimeOfDay) { timeslotID = appointment.Timeslot_ID; } else if (timeslot != null && appointment.Timeslot.EndTime < DateTime.Now.TimeOfDay) { timeslotID = timeslot.Timeslot_ID; } } if (string.IsNullOrEmpty(timeslotID)) { throw new Trinity.Common.ExceptionArgs("Unable get queue.<br/>All time slots are close today."); } Trinity.DAL.DBContext.Queue dataInsert = new Trinity.DAL.DBContext.Queue() { Queue_ID = Guid.NewGuid(), UserId = userId, Timeslot_ID = timeslotID, Appointment_ID = appointmentID, CurrentStation = station, Outcome = EnumQueueOutcomeText.Processing, CreatedTime = DateTime.Now, QueuedNumber = generateQNo, Created_By = userCreateQueue }; //insert to queue details List <Trinity.DAL.DBContext.QueueDetail> arrayQueueDetail = new List <Trinity.DAL.DBContext.QueueDetail>(); foreach (var item in listStation) { var queueDetails = new Trinity.DAL.DBContext.QueueDetail { Queue_ID = dataInsert.Queue_ID, Station = item, Status = EnumQueueStatuses.Waiting }; if (queueDetails.Station == EnumStation.APS) { queueDetails.Status = EnumQueueStatuses.Finished; } arrayQueueDetail.Add(queueDetails); } _localUnitOfWork.GetRepository <Trinity.DAL.DBContext.Queue>().Add(dataInsert); _localUnitOfWork.GetRepository <Trinity.DAL.DBContext.QueueDetail>().AddRange(arrayQueueDetail); if (string.IsNullOrEmpty(appointment.Timeslot_ID)) { appointment.Timeslot_ID = timeslotID; } appointment.Status = EnumAppointmentStatuses.Reported; appointment.ReportTime = DateTime.Now; _localUnitOfWork.GetRepository <Trinity.DAL.DBContext.Appointment>().Update(appointment); _localUnitOfWork.Save(); return(dataInsert); }