public IActionResult Generate(MetaInterval model) { List <Feedback> feedbacks = new List <Feedback>(); DateTime today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59, 59); DateTime def = new DateTime(DateTime.MinValue.Ticks); if (model.From == def && model.To == def) { feedbacks = db.Feedback.Where(f => f.IdParticipationNavigation.IdEventNavigation.TimeTo <= today).ToList(); } else if (model.From != def && model.To == def) { feedbacks = db.Feedback.Where(f => f.IdParticipationNavigation.IdEventNavigation.TimeFrom >= model.From && f.IdParticipationNavigation.IdEventNavigation.TimeTo <= today).ToList(); } else if (model.From == def && model.To != def) { feedbacks = db.Feedback.Where(f => f.IdParticipationNavigation.IdEventNavigation.TimeTo <= model.To.AddHours(20)).ToList(); } else { feedbacks = db.Feedback.Where(f => f.IdParticipationNavigation.IdEventNavigation.TimeFrom >= model.From && f.IdParticipationNavigation.IdEventNavigation.TimeTo <= model.To.AddHours(20)).ToList(); } string csv = csvConverter.Convert(feedbacks, db); string filename = string.Format("feedback.csv"); return(File(new System.Text.UTF8Encoding().GetBytes(csv), "text/csv", filename)); }
public IActionResult TutorList(MetaInterval model) { StatisticsTutor statistics = new StatisticsTutor(); List <Event> events = new List <Event>(); List <SscisUser> tutors = new List <SscisUser>(); DateTime today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59, 59); DateTime def = new DateTime(DateTime.MinValue.Ticks); if (model.From == def && model.To == def) { events = db.Event.Where(e => e.TimeTo <= today && e.IsAccepted == true).ToList(); } else if (model.From != def && model.To == def) { events = db.Event.Where(e => e.TimeFrom >= model.From && e.TimeTo <= today && e.IsAccepted == true).ToList(); } else if (model.From == def && model.To != def) { events = db.Event.Where(e => e.TimeTo <= model.To.AddHours(20) && e.IsAccepted == true).ToList(); } else { events = db.Event.Where(e => e.TimeFrom >= model.From && e.TimeTo <= model.To.AddHours(20) && e.IsAccepted == true).ToList(); } tutors = db.SscisUser.Where(t => t.IdRoleNavigation.Role.Equals(AuthorizationRoles.Tutor) || t.IdRoleNavigation.Role.Equals(AuthorizationRoles.Administrator)).ToList(); foreach (var tutor in tutors) { MetaTutor metaTutor = new MetaTutor(); metaTutor.Id = tutor.Id; metaTutor.IdTutorNavigation = tutor; if (statistics.Tutor == null) { statistics.Tutor = new List <MetaTutor>(); } statistics.Tutor.Add(metaTutor); } foreach (var item in events) { if (item.IsAccepted == true && item.IsCancelled != true) { foreach (var storedTutor in statistics.Tutor) { if (item.IdTutor == storedTutor.Id) { if (item.IdSubjectNavigation.Code.Equals("MAT")) { storedTutor.MathLessons++; } else if (item.IdSubjectNavigation.Code.Equals("INF")) { storedTutor.InfLessons++; } else if (item.IdSubjectNavigation.Code.Equals("MECH")) { storedTutor.MechLessons++; } int standartLessonLength = int.Parse(db.SscisParam.Where(p => p.ParamKey == SSCISParameters.STANDARTEVENTLENGTH).Single().ParamValue); if (standartLessonLength == 0) { standartLessonLength = 2; } storedTutor.Lessons = storedTutor.MathLessons + storedTutor.InfLessons + storedTutor.MechLessons; storedTutor.LessonsHours = storedTutor.Lessons * standartLessonLength; } } } } statistics.Tutor.Sort(delegate(MetaTutor x, MetaTutor y) { if (x.IdTutorNavigation.Login == null && y.IdTutorNavigation.Login == null) { return(0); } else if (x.IdTutorNavigation.Login == null) { return(-1); } else if (y.IdTutorNavigation.Login == null) { return(1); } else { return(x.IdTutorNavigation.Login.CompareTo(y.IdTutorNavigation.Login)); } }); return(View(statistics)); }
public IActionResult List(MetaInterval model) { Statistics statistics = new Statistics(); List <Event> events = new List <Event>(); DateTime today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59, 59); DateTime def = new DateTime(DateTime.MinValue.Ticks); if (model.From == def && model.To == def) { events = db.Event.Where(e => e.TimeTo <= today && e.IsAccepted == true && e.IsCancelled == false).ToList(); } else if (model.From != def && model.To == def) { events = db.Event.Where(e => e.TimeFrom >= model.From && e.TimeTo <= today && e.IsAccepted == true && e.IsCancelled == false).ToList(); } else if (model.From == def && model.To != def) { events = db.Event.Where(e => e.TimeTo <= model.To.AddHours(20) && e.IsAccepted == true && e.IsCancelled == false).ToList(); } else { events = db.Event.Where(e => e.TimeFrom >= model.From && e.TimeTo <= model.To.AddHours(20) && e.IsAccepted == true && e.IsCancelled == false).ToList(); } foreach (var item in events) { MetaStat meta = new MetaStat(); meta.IdSubjectNavigation = item.IdSubjectNavigation; statistics.Lessons++; if (item.IdSubjectNavigation.Code.Equals("MAT")) { statistics.MathLessons++; } else if (item.IdSubjectNavigation.Code.Equals("INF")) { statistics.InfLessons++; } else if (item.IdSubjectNavigation.Code.Equals("MECH")) { statistics.MechLessons++; } int standartLessonLength = int.Parse(db.SscisParam.Where(p => p.ParamKey == SSCISParameters.STANDARTEVENTLENGTH).Single().ParamValue); if (standartLessonLength == 0) { standartLessonLength = 2; } statistics.LessonsHours = statistics.Lessons * standartLessonLength; statistics.MathLessonsHours = statistics.MathLessons * standartLessonLength; statistics.InfLessonsHours = statistics.InfLessons * standartLessonLength; statistics.MechLessonsHours = statistics.MechLessons * standartLessonLength; meta.IdTutorNavigation = item.IdTutorNavigation; meta.TimeFrom = item.TimeFrom; meta.TimeTo = item.TimeTo; meta.Id = item.Id; meta.IdEventNavigation = item; int feedbackCount = db.Participation.Where(p => p.IdEvent == item.Id).Count(); meta.FeedbacksCount = feedbackCount; if (statistics.Event == null) { statistics.Event = new List <MetaStat>(); } statistics.Event.Add(meta); } if (statistics.Event != null) { statistics.Event.Sort(delegate(MetaStat x, MetaStat y) { if (x.TimeFrom == null && y.TimeFrom == null) { return(0); } else if (x.TimeFrom == null) { return(-1); } else if (y.TimeFrom == null) { return(1); } else { return(x.TimeFrom.CompareTo(y.TimeFrom)); } }); } return(View(statistics)); }