public Groups Create(int DivisionId, string name, int?ClassroomId, TimeSpans timeSpan) { //provera da li je ucionica slobodna u to vreme if (ClassroomId != null) { this.CheckIfClassroomIsAvailable(ClassroomId.Value, timeSpan); } if (timeSpan != null) { _context.TimeSpans.Add(timeSpan); } _context.SaveChanges(); Groups g = new Groups { DivisionId = DivisionId, Name = name, ClassroomId = ClassroomId, }; if (timeSpan != null) { g.TimeSpanId = timeSpan.TimeSpanId; } _context.Groups.Add(g); _context.SaveChanges(); return(g); }
/// <summary> /// Proverava da li je Student slobodan u to vreme. /// </summary> /// <param Name="StudentId"></param> /// <param Name="ts"></param> /// <param Name="GroupId">Groupa ciji ce se cas izuzeti pri proveri</param> /// <returns></returns> public bool CheckIfAvailable(int StudentId, TimeSpans ts, int?GroupId = null) { List <int> Groups = _context.GroupsStudents .Where(a => a.StudentId == StudentId && (GroupId == null || a.GroupId != GroupId) && TimeSpan.DatesOverlap(a.Group.Division.Beginning, a.Group.Division.Ending, ts.StartDate, ts.EndDate)) //provera da li raspodela kojoj grupa pripada i dalje vazi .Select(a => a.GroupId).ToList(); var GroupsSchedulePom = _context.Groups.Where(a => Groups.Contains(a.GroupId)).ToList(); List <TimeSpans> GroupsSchedule = GroupsSchedulePom.Where(a => a.TimeSpan != null && groupService.IsActive(a.GroupId, ts)).Select(a => a.TimeSpan).ToList(); List <int> activities = _context.StudentsActivities.Where(a => a.StudentId == StudentId && a.Ignore != true).Select(a => a.ActivityId).ToList(); List <TimeSpans> activitiesSchedule = _context.Activities.Where( a => activities.Contains(a.ActivityId) || (a.GroupId != null && a.Cancelling == false && Groups.Contains(a.GroupId.Value))) .Select(a => a.TimeSpan) .ToList(); List <TimeSpans> schedule = GroupsSchedule.Concat(activitiesSchedule).ToList(); return(ts == null || schedule.All(timeSpan => !Server.Services.TimeSpan.Overlap(timeSpan, ts))); }
//prebaceno je ovde zbog circular dependancy public void UpdateGroup(int GroupId, string name, int?ClassroomId, TimeSpans TimeSpan) { //provera da li je ucionica slobodna u to vreme, bacice exeption ako nije if (ClassroomId != null && TimeSpan != null) { groupService.CheckIfClassroomIsAvailable(ClassroomId.Value, TimeSpan, GroupId); } //provera da li su svi Studenti slobodni u to vreme, bacice exeption ako nisu var studs = _context.GroupsStudents.Where(a => a.GroupId == GroupId).Select(a => a.StudentId).ToList(); this.CheckIfAvailable(TimeSpan, studs, GroupId); Groups g = _context.Groups.First(a => a.GroupId == GroupId); if (name != null) { g.Name = name; } if (ClassroomId != null) { g.ClassroomId = ClassroomId; } if (TimeSpan != null) { g.TimeSpan = TimeSpan; } _context.SaveChanges(); }
// provera da li studend moze biti dodan u grupu public void TryAddToGroup(int StudentId, int GroupId) { //proveri da li dolazi do nekonzistentnosti raspodele //provera da li Student vec postoji u toj grupi var otherStuds = _context.GroupsStudents.Where(a => a.GroupId == GroupId).Select(a => a.StudentId).ToList(); if (otherStuds.Contains(StudentId)) { throw new InconsistentDivisionException("Student već pripada toj grupi."); } //proverva konzistentnost sa ostalim grupama, bacice exeption ako nije groupService.CheckConsistencyWithOtherGroups(GroupId, new List <int>() { StudentId }); //provera da li je Student slobodan u vreme kada ta grupa ima cas TimeSpans GroupTs = _context.Groups.Where(a => a.GroupId == GroupId).Select(a => a.TimeSpan).First(); if (GroupTs != null && !CheckIfAvailable(StudentId, GroupTs)) { string Name = GetStudentName(StudentId); string message = "Student (" + Name + ") nije slobodan u vreme kada grupa ima cas"; message += " (" + TimeSpan.ToString(GroupTs) + " )."; throw new InconsistentDivisionException(message); } }
public void AddActivity(int StudentId, int?GroupId, int?ClassroomId, TimeSpans TimeSpan, string Place, string Title, string content) { _context.TimeSpans.Add(TimeSpan); Activities act = new Activities { GroupId = GroupId, TimeSpanId = TimeSpan.TimeSpanId, ClassroomId = ClassroomId, Place = Place, Title = Title, ActivityContent = content, Cancelling = false, }; _context.Activities.Add(act); StudentsActivities sa = new StudentsActivities { StudentId = StudentId, ActivityId = act.ActivityId, Ignore = false, Alert = false }; _context.StudentsActivities.Add(sa); _context.SaveChanges(); }
//pretvara iz timespana ili formata[dayOfWeek, Period, timeStart, timeEnd] u timespan public static TimeSpans getTimeSpan(GroupsController.TimeSpanBinding bind) { if (bind == null) { return(null); } TimeSpans ts = new TimeSpans(); if (bind.Period == 0) { ts.Period = bind.Period; ts.StartDate = bind.StartDate.Value; ts.EndDate = bind.EndDate.Value; return(ts); } else { //nedelja je 0 if (bind.Period == 0) { bind.Period = 7; } DateTime mon = DateTime.Now.StartOfWeek(); ts.StartDate = mon.AddDays(bind.DayOfWeek.Value - 1); ts.EndDate = ts.StartDate; ts.StartDate = ts.StartDate.Add(convertHM(bind.TimeStart)); ts.EndDate = ts.EndDate.Add(convertHM(bind.TimeEnd)); ts.Period = bind.Period; } return(ts); }
public static bool Overlap(TimeSpans paramA, TimeSpans paramB) { if (paramA == null || paramB == null) { return(false); } //moram da kopiram jer se prenosi po referenci TimeSpans a = Copy(paramA); TimeSpans b = Copy(paramB); if (a.Period == null && b.Period == null) { return(DatesOverlap(a.StartDate, a.EndDate, b.StartDate, b.EndDate)); } if (a.Period != null && a.Period > 0) { a.StartDate = a.StartDate.DayOfReferencedWeek(b.StartDate, a.Period.Value); a.EndDate = a.EndDate.DayOfReferencedWeek(b.EndDate, a.Period.Value); } if (b.Period != null && b.Period > 0) { b.StartDate = b.StartDate.DayOfReferencedWeek(a.StartDate, b.Period.Value); b.EndDate = b.EndDate.DayOfReferencedWeek(a.EndDate, b.Period.Value); } return(TimeSpanOverlap(a, b)); }
// moze lepse da se organizuje funkcija public static string ToString(TimeSpans ts) { var ret = ""; if (ts == null) { return(""); } if (ts.Period != 1) { ret += ts.StartDate.ToStr(); if (ts.StartDate.Date != ts.EndDate.Date) { ret += " - " + ts.EndDate.ToStr(); } else { ret += " - " + ts.EndDate.ToString("HH:mm"); } return(ret); } else { ret += ts.StartDate.DayOfWeek.ToStr() + " "; ret += ts.StartDate.ToString("HH:mm"); ret += " - " + ts.EndDate.ToString("HH:mm"); } return(ret); }
//GroupId je grupa ciji cas treba zanemariti (grupa koja menja ucionicu public bool CheckIfAvailable(int ClassroomId, TimeSpans ts, int?GroupId = null) { List <TimeSpans> groupsSchedule = _context.Groups .Where(a => a.ClassroomId == ClassroomId && (GroupId == null || a.GroupId != GroupId) && // da ne uzme u obzir trenutni ts grupe, posto se ionako menja TimeSpan.DatesOverlap(a.Division.Beginning, a.Division.Ending, ts.StartDate, ts.EndDate) && groupsService.IsActive(a.GroupId, ts)) //provera da li raspodela kojoj grupa pripada i dalje vazi_ .Select(a => a.TimeSpan).ToList(); List <TimeSpans> activitiesSchedule = _context.Activities.Where(a => a.ClassroomId == ClassroomId && !groupsService.IsStudentActivity(a.ActivityId)) .Select(a => a.TimeSpan).ToList(); List <TimeSpans> schedule = groupsSchedule.Concat(activitiesSchedule).ToList(); if (schedule.Any(TimeSpan => Services.TimeSpan.Overlap(TimeSpan, ts))) { string ClassroomNumber = _context.Classrooms.First(a => a.ClassroomId == ClassroomId).Number; throw new InconsistentDivisionException("Ucionica (" + ClassroomNumber + ") nije slobodna u to vreme (" + TimeSpan.ToString(ts) + ")."); } ; return(true); }
public TimeSpan ShouldReturnMaximumTimeSpan(TimeSpan first, TimeSpan second) { // when var max = TimeSpans.Max(first, second); // then return(max); }
public TimeSpan ShouldReturnMinimumTimeSpan(TimeSpan first, TimeSpan second) { // when var min = TimeSpans.Min(first, second); // then return(min); }
public TimeSpan ShouldReturnAbsoluteTimeSpan(TimeSpan timespan) { // when var abs = TimeSpans.Abs(timespan); // then return(abs); }
public void SwitchTimeSpans(TimeSpans span) { AddTimeSpanButton.Trigger(); TimeManager.FlashPause(); ViewButton.SelectItem(TimeSpanMenuItemDictionary[span]); //CurrentViewType = viewType; }
public bool IsActive(int GroupId, TimeSpans tsNow) { bool canceled = _context.Activities.Any(ac => !ac.StudentsActivities.Any() && // nece ako se ovde direktno ispita ac.GroupId == GroupId && ac.Cancelling == true && TimeSpan.TimeSpanOverlap(ac.TimeSpan, tsNow)); return(!canceled); }
public static TimeSpans Copy(TimeSpans a) { return(new TimeSpans { StartDate = a.StartDate, EndDate = a.EndDate, Period = a.Period }); }
public IEnumerable GetSchedule(int assistantID, int weeksFromNow = 0) { DateTime now = DateTime.Now.AddDays(7 * weeksFromNow); TimeSpans tsNow = new TimeSpans { StartDate = now.StartOfWeek(), EndDate = now.EndOfWeek() }; List <int> groups = _context.Groups .Where(a => a.AssistantId == assistantID && TimeSpan.DatesOverlap(a.Division.Beginning, a.Division.Ending, tsNow.StartDate, tsNow.EndDate)) //provera da li raspodela kojoj grupa pripada i dalje vazi .Select(a => a.GroupId).ToList(); List <ScheduleDTO> groupsSchedule = _context.Groups.Where(a => groups.Contains(a.GroupId) && TimeSpan.Overlap(a.TimeSpan, tsNow)) .Select(a => new ScheduleDTO { Day = ((DateTime)a.TimeSpan.StartDate).DayOfWeek, StartMinutes = (int)((DateTime)a.TimeSpan.StartDate).TimeOfDay.TotalMinutes, DurationMinutes = (int)(((DateTime)a.TimeSpan.EndDate).Subtract(((DateTime)a.TimeSpan.StartDate))).TotalMinutes, ClassName = a.Division.Course.Name, Abbr = a.Division.Course.Alias, Classroom = a.Classroom.Number, Assistant = groupService.GetAssistant(a.Assistant), Type = a.Division.DivisionType.Type, Color = groupService.GetNextColor(a.Division.Course.Name), IsClass = true, GroupId = a.GroupId, }).ToList(); groupsSchedule.ForEach(a => a.Active = groupService.IsActive(a.GroupId, tsNow)); groupsSchedule.ForEach(a => a.Notifications = groupService.GetNotifications(a.GroupId, tsNow)); List <ScheduleDTO> activitiesSchedule = _context.Activities.Where(a => ((a.AssistantId == assistantID || (a.GroupId != null && a.Cancelling == false && groups.Contains(a.GroupId.Value)) || (!a.StudentsActivities.Any() && a.GroupId == null)) && TimeSpan.Overlap(a.TimeSpan, tsNow))) .Select(a => new ScheduleDTO { Day = ((DateTime)a.TimeSpan.StartDate).DayOfWeek, StartMinutes = (int)((DateTime)a.TimeSpan.StartDate).TimeOfDay.TotalMinutes, DurationMinutes = (int)(((DateTime)a.TimeSpan.EndDate).Subtract(((DateTime)a.TimeSpan.StartDate))).TotalMinutes, Active = true, Color = groupService.GetNextColor(a.Title), ActivityTitle = a.Title, ActivityContent = a.ActivityContent, IsClass = false, ActivityId = a.ActivityId, Assistant = groupService.GetAssistant(a.Assistant), Classroom = a.Classroom.Number, Place = a.Place }).ToList(); List <ScheduleDTO> returnValue = groupsSchedule.Concat(activitiesSchedule).ToList(); return(scheduleService.Convert(returnValue)); }
private int GetPhaseIndex(string phase) { if (!_indices.ContainsKey(phase)) { _indices.Add(phase, AllPhases.Count); AllPhases.Add(phase); TimeSpans.Add(new TimeSpan()); } return(_indices[phase]); }
public IEnumerable GetSchedule(int ClassroomId, int weeksFromNow = 0) { DateTime now = DateTime.Now.AddDays(7 * weeksFromNow); TimeSpans tsNow = new TimeSpans { StartDate = now.StartOfWeek(), EndDate = now.EndOfWeek() }; List <int> groups = _context.Groups .Where(a => a.ClassroomId == ClassroomId && TimeSpan.DatesOverlap(a.Division.Beginning, a.Division.Ending, tsNow.StartDate, tsNow.EndDate)) //provera da li raspodela kojoj grupa pripada i dalje vazi .Select(a => a.GroupId).ToList(); List <ScheduleDTO> groupsSchedule = _context.Groups.Where(a => groups.Contains(a.GroupId) && TimeSpan.Overlap(a.TimeSpan, tsNow)) .Select(a => new ScheduleDTO { Day = a.TimeSpan.StartDate.DayOfWeek, StartMinutes = (int)a.TimeSpan.StartDate.TimeOfDay.TotalMinutes, DurationMinutes = (int)(a.TimeSpan.EndDate.Subtract(a.TimeSpan.StartDate)).TotalMinutes, ClassName = a.Division.Course.Name + " " + a.Name, Abbr = a.Name + " " + a.Division.Course.Alias, Classroom = a.Classroom.Number, Assistant = this.GetAssistant(a.GroupId), Type = a.Division.DivisionType.Type, Active = this.IsActive(a.GroupId, tsNow), Color = this.GetNextColor(a.Division.Course.Name), IsClass = true, }).ToList(); List <ScheduleDTO> activitiesSchedule = _context.Activities.Where(a => a.ClassroomId == ClassroomId && !this.IsStudentActivity(a.ActivityId) && // ne uzima studentove aktivnosti TimeSpan.Overlap(a.TimeSpan, tsNow)) .Select(a => new ScheduleDTO { Day = a.TimeSpan.StartDate.DayOfWeek, StartMinutes = (int)a.TimeSpan.StartDate.TimeOfDay.TotalMinutes, DurationMinutes = (int)(a.TimeSpan.EndDate.Subtract(a.TimeSpan.StartDate)).TotalMinutes, Active = true, Color = this.GetNextColor(a.Title), ActivityTitle = a.Title, ActivityContent = a.ActivityContent, IsClass = false, }).ToList(); List <ScheduleDTO> returnValue = groupsSchedule.Concat(activitiesSchedule).ToList(); return(scheduleService.Convert(returnValue)); }
public IActionResult MassGroupEdit([FromBody] MassGroupEditBinding obj) { //if (!HttpContext.Session.IsAssistant()) return Unauthorized(); if (obj?.groups == null) { return(Ok(new { status = "parameter error" })); } try { foreach (GroupEditBinding group in obj.groups) { if (group.timespan != null) { if (group.timespan.Period == null) { return(Ok(new { status = "parameter error" })); } // nzm zasto ovo nece if (group.timespan.StartDate == null) { return(Ok(new { status = "parameter error" })); } if (group.timespan.EndDate == null) { return(Ok(new { status = "parameter error" })); } if (group.timespan.Period.Value != 0 && (group.timespan.TimeStart == null || group.timespan.TimeEnd == null || group.timespan.DayOfWeek == null)) { return(Ok(new { status = "parameter error" })); } } //konvertovanje u timeSpan TimeSpans ts = Services.TimeSpan.getTimeSpan(group.timespan); studentService.Update(group.groupID.Value, null, group.classroomID, ts); } return(Ok(new { status = "uspelo" })); } catch (InconsistentDivisionException ex) { return(Ok(new { status = "inconsistent division", message = ex.Message })); } catch (Exception ex) { return(Ok(new { status = "neuspelo", message = ex.Message })); } }
public void DeleteActivity(int activityId) { // brisanje TimeSpana Activities act = _context.Activities.Include(a => a.TimeSpan).First(a => a.ActivityId == activityId); TimeSpans ts = act.TimeSpan; // brisanje same grupe _context.Activities.Remove(act); _context.SaveChanges(); if (ts != null) { _context.TimeSpans.Remove(ts); } _context.SaveChanges(); }
public void RemoveGroup(int groupId) { // brisanje TimeSpana Groups group = _context.Groups.Include(a => a.TimeSpan).First(a => a.GroupId == groupId); TimeSpans ts = group.TimeSpan; // brisanje same grupe _context.Groups.Remove(@group); _context.SaveChanges(); if (ts != null) { _context.TimeSpans.Remove(ts); } _context.SaveChanges(); }
public List <NotificationDTO> GetNotifications(int GroupId, TimeSpans ts) { List <NotificationDTO> groupsNotifications = _context.Activities.Where(ac => !ac.StudentsActivities.Any() && // nece ako se ovde direktno ispita ac.GroupId == GroupId && TimeSpan.TimeSpanOverlap(ac.TimeSpan, ts)) .Select(ac => new NotificationDTO { ActivityId = ac.ActivityId, ActivityContent = ac.ActivityContent, Title = ac.Title, ClassroomId = ac.ClassroomId, Place = ac.Place }).ToList(); return(groupsNotifications); }
public void AddActivity(int assistantId, int?groupId, int?classroomId, TimeSpans timeSpan, string place, string title, string content) { _context.TimeSpans.Add(timeSpan); Activities act = new Activities { TimeSpanId = timeSpan.TimeSpanId, ClassroomId = classroomId, Place = place, Title = title, ActivityContent = content, GroupId = groupId, Cancelling = false, AssistantId = assistantId, }; _context.Activities.Add(act); _context.SaveChanges(); }
public void SerializeTimeSpansAsTicksAndStrings() { var timeSpans = new TimeSpans(TimeSpan.FromSeconds(902312)); var client = new ElasticClient(); var json = client.RequestResponseSerializer.SerializeToString(timeSpans); json.Should() .Be("{\"default\":9023120000000,\"defaultNullable\":9023120000000,\"string\":\"10.10:38:32\",\"stringNullable\":\"10.10:38:32\"}"); TimeSpans deserialized; using (var stream = client.ConnectionSettings.MemoryStreamFactory.Create(Encoding.UTF8.GetBytes(json))) deserialized = client.RequestResponseSerializer.Deserialize <TimeSpans>(stream); timeSpans.Default.Should().Be(deserialized.Default); timeSpans.DefaultNullable.Should().Be(deserialized.DefaultNullable); timeSpans.String.Should().Be(deserialized.String); timeSpans.StringNullable.Should().Be(deserialized.StringNullable); }
public void SerializeMaxTimeSpansAsTicksAndStrings() { var timeSpans = new TimeSpans(TimeSpan.MaxValue); var client = new ElasticClient(); var json = client.RequestResponseSerializer.SerializeToString(timeSpans); json.Should() .Be("{\"default\":9223372036854775807,\"defaultNullable\":9223372036854775807,\"string\":\"10675199.02:48:05.4775807\",\"stringNullable\":\"10675199.02:48:05.4775807\"}"); TimeSpans deserialized; using (var stream = client.ConnectionSettings.MemoryStreamFactory.Create(Encoding.UTF8.GetBytes(json))) deserialized = client.RequestResponseSerializer.Deserialize <TimeSpans>(stream); timeSpans.Default.Should().Be(deserialized.Default); timeSpans.DefaultNullable.Should().Be(deserialized.DefaultNullable); timeSpans.String.Should().Be(deserialized.String); timeSpans.StringNullable.Should().Be(deserialized.StringNullable); }
public void CancelClass(int groupId, string title, string content, TimeSpans timeSpan) { if (!IsActive(groupId, timeSpan)) { throw new Exception("Čas je već otkazan."); } _context.TimeSpans.Add(timeSpan); Activities act = new Activities { Title = title, ActivityContent = content, GroupId = groupId, Cancelling = true, TimeSpanId = timeSpan.TimeSpanId }; _context.Activities.Add(act); _context.SaveChanges(); }
public IEnumerable GetSchedule(int departmentId, int weeksFromNow = 0) { DateTime now = DateTime.Now.AddDays(7 * weeksFromNow); TimeSpans tsNow = new TimeSpans { StartDate = now.StartOfWeek(), EndDate = now.EndOfWeek() }; List <int> groups = _context.Groups .Where(g => g.Division.DepartmentId == departmentId && TimeSpan.DatesOverlap(g.Division.Beginning, g.Division.Ending, tsNow.StartDate, tsNow.EndDate)) .Select(g => g.GroupId).ToList(); if (groups.Count == 0) { return(null); } List <ScheduleDTO> returnValue = _context.Groups.Where(a => groups.Contains(a.GroupId) && TimeSpan.Overlap(a.TimeSpan, tsNow)) .Select(a => new ScheduleDTO { Day = ((DateTime)a.TimeSpan.StartDate).DayOfWeek, StartMinutes = (int)((DateTime)a.TimeSpan.StartDate).TimeOfDay.TotalMinutes, DurationMinutes = (int)(((DateTime)a.TimeSpan.EndDate).Subtract(((DateTime)a.TimeSpan.StartDate))).TotalMinutes, ClassName = a.Division.Course.Name + " " + a.Name, Abbr = a.Name + " " + a.Division.Course.Alias, Classroom = a.Classroom.Number, Assistant = groupsService.GetAssistant(a.Assistant), Type = a.Division.DivisionType.Type, Color = groupsService.GetNextColor(a.Division.Course.Name), IsClass = true, GroupId = a.GroupId }).ToList(); returnValue.ForEach(a => a.Active = groupsService.IsActive(a.GroupId, tsNow)); return(scheduleService.Convert(returnValue)); }
public IActionResult AddActivity([FromBody] AddActivityBinding obj) { //if (!HttpContext.Session.IsStudent()) return Unauthorized(); if (obj.timeSpan == null) { return(Ok(new { status = "parameter error" })); } try { //konvertovanje u timeSpan TimeSpans ts = Services.TimeSpan.getTimeSpan(obj.timeSpan); studentService.AddActivity(HttpContext.User.GetId(), obj.groupID, obj.classroomID, ts, obj.place, obj.title, obj.content); return(Ok(new { status = "success" })); } catch (Exception ex) { return(Ok(new { status = "error", message = ex.Message })); } }
public bool CheckIfAvailable(TimeSpans ts, List <int> Students, int?GroupId = null) { if (ts == null) { return(true); } var unaveliable = _context.Students .Where(a => Students.Contains(a.StudentId) && !CheckIfAvailable(a.StudentId, ts, GroupId)) .Select(a => a.UniMembers.Name + " " + a.UniMembers.Surname).ToList(); if (unaveliable.Any()) { string exp = unaveliable.Count() > 1 ? "Studenti nisu slobodni u vreme kada grupa ima cas" : "Student nije slobodan u vreme kada grupa ima cas"; exp += " (" + TimeSpan.ToString(ts) + ").\n"; exp += String.Join("\n", unaveliable); throw new InconsistentDivisionException(exp); } return(true); }
// vraca vreme kAda grupa ima cas u naredne 4 nedelje public IEnumerable GetActivityTimes(int groupId) { TimeSpans groupTs = _context.Groups.Where(a => a.GroupId == groupId).Select(a => a.TimeSpan).First(); if (groupTs == null) { return(null); } int period = groupTs.Period ?? 1; List <TimeSpans> returnValue = new List <TimeSpans>(); for (int i = 0; i < 4; i++) { TimeSpans ts = new TimeSpans { StartDate = groupTs.StartDate.DayOfReferencedWeek(DateTime.Now.AddDays(7 * i), period), EndDate = groupTs.EndDate.DayOfReferencedWeek(DateTime.Now.AddDays(7 * i), period) }; returnValue.Add(ts); } return(returnValue); }