public List <RollCall> GetInstructorFutureRollCalls(int InstructorID) { DateTime Today = DateTime.Now; StudySessionBusiness StuSesBO = new StudySessionBusiness(this.RollSystemDB); var TodaySession = StuSesBO.GetInstructorFutureSession(InstructorID); return(TodaySession.Select(ss => ss.RollCall).Distinct().ToList()); }
private void SyncCalendar(int InstructorID) { InstructorBusiness InsBO = new InstructorBusiness(); Instructor Ins = InsBO.GetInstructorByID(InstructorID); //Neu chua co teken thi ko lam gi het if (Ins.ApiToken == null) { return; } SimpleLog.Info("Begin Sync Calendar for Instructor " + Ins.Fullname + "."); try { String RefreshToken = Ins.ApiToken; var WrapperAPI = new GoogleCalendarAPIWrapper(RefreshToken); //Tim toan bo lich cua instructor var Calendars = WrapperAPI.GetCalendarList(); //Tim xem da co teaching calendar chua, chua co thi insert GoogleCalendar TeachingCalendar = Calendars.Items.SingleOrDefault(ca => ca.Summary.Equals("Teaching Calendar")); if (TeachingCalendar == null) { TeachingCalendar = WrapperAPI.InsertCalendar("Teaching Calendar"); } else { //Clear nhung ngay trong tuong lai WrapperAPI.ClearFutureDateCalendar(TeachingCalendar.ID); } //Bat dau lay event, ghi vao calendar. StudySessionBusiness StuSesBO = new StudySessionBusiness(); //Chi lay nhung event trong tuong lai, tiet kiem dung luong List <Event> Events = StuSesBO.GetCalendarEvent(InstructorID). Where(e => e.StartDate >= DateTime.Now).ToList(); foreach (var Event in Events) { WrapperAPI.InsertEvent(TeachingCalendar.ID, Event.title, Event.StartDate, Event.EndDate); } String Message = String.Format("Succesfull sync {0} events, from {1:dd-MM-yyyy} to {2:dd-MM-yyyy}", Events.Count, Events.First().StartDate, Events.Last().StartDate); SimpleLog.Info(Message); } catch (Exception e) { SimpleLog.Error("Error while trying to sync."); SimpleLog.Error(e.Message); } }
public bool Update(RollCall InRollCall) { StudySessionBusiness StuSesBO = new StudySessionBusiness(this.RollSystemDB); //Ko cho sua lop, chi cho sua instructor, thoi gian, ngay thang RollCall rollCall = GetRollCallByID(InRollCall.RollCallID); //Doi giao vien va thoi gian rollCall.InstructorID = InRollCall.InstructorID; rollCall.StartTime = InRollCall.StartTime; rollCall.EndTime = rollCall.StartTime. Add(TimeSpan.FromMinutes(90 * rollCall.Subject.NumberOfSlot)). Add(TimeSpan.FromMinutes(15 * (rollCall.Subject.NumberOfSlot - 1))); //Doi ngay thang rollCall.BeginDate = InRollCall.BeginDate; //VD: 20 slot se la 28 ngay. 15 slot la 21 ngay, 18 slot van 28 ngay int TotalDate = (int)Math.Ceiling((double)rollCall.Subject.NumberOfSession / 5) * 7; //Tru 1 ngay de ket thuc vao chu nhat rollCall.EndDate = rollCall.BeginDate.AddDays(TotalDate).AddDays(-1); //Xoa het studysesion cu foreach (var Session in rollCall.StudySessions.ToList()) { rollCall.StudySessions.Remove(Session); StuSesBO.Delete(Session); } //Them studysession moi DateTime SessionDate = rollCall.BeginDate; for (int i = 0; i < rollCall.Subject.NumberOfSession; i++) { StudySession StuSes = new StudySession() { InstructorID = rollCall.InstructorID, ClassID = rollCall.ClassID, StartTime = rollCall.StartTime, EndTime = rollCall.EndTime, SessionDate = SessionDate, Note = SessionDate.ToString("dd-MM-yyyy") + " : " }; rollCall.StudySessions.Add(StuSes); do { SessionDate = SessionDate.AddDays(1); } while (SessionDate.DayOfWeek == DayOfWeek.Saturday || SessionDate.DayOfWeek == DayOfWeek.Sunday); } base.Detach(rollCall); return(base.Update(rollCall)); }
public List <RollCall> GetInstructorCurrentRollCalls(int InstructorID) { DateTime Today = DateTime.Now; StudySessionBusiness StuSesBO = new StudySessionBusiness(this.RollSystemDB); var TodaySessions = StuSesBO.GetInstructorCurrentSession(InstructorID); var YesterdaySession = StuSesBO.GetInstructorYesterdaySession(InstructorID); if (TodaySessions == null && YesterdaySession == null) { return(null); } else { var TodayRollCall = new List <RollCall>(); foreach (var TodaySession in TodaySessions) { var NewRoll = TodaySession.RollCall.Clone(); NewRoll.StartTime = TodaySession.StartTime; NewRoll.EndTime = TodaySession.EndTime; NewRoll.SessionToCheckAttendance = TodaySession; TodayRollCall.Add(NewRoll); } foreach (var RollCall in YesterdaySession.Select(s => s.RollCall).ToList()) { if (TodayRollCall == null) { TodayRollCall = new List <RollCall>(); } if (!TodayRollCall.Any(roll => roll.RollCallID == RollCall.RollCallID)) { RollCall.StartTime = new TimeSpan(0, 0, 0); RollCall.EndTime = new TimeSpan(0, 0, 0); TodayRollCall.Add(RollCall); } } return(TodayRollCall.OrderBy(r => r.StartTime).ToList()); } }