public JsonResult GetStateWeekly(Guid?dateId, Guid roomId, string date, string begin, string end) { var sDate = DateTime.Parse(date); var sBegin = TimeSpan.Parse(begin); var sEnd = TimeSpan.Parse(end); var room = Db.Rooms.SingleOrDefault(r => r.Id == roomId); var semester = SemesterService.GetSemester(DateTime.Today); var dayOfWeek = sDate.DayOfWeek; var dayList = new SemesterService().GetDays(semester.Id, dayOfWeek); var nCollisions = 0; foreach (var day in dayList) { var from = day.Add(sBegin); var until = day.Add(sEnd); nCollisions += room.Dates.Count(d => (d.End > @from && d.End <= until) || // Veranstaltung endet im Zeitraum (d.Begin >= @from && d.Begin < until) || // Veranstaltung beginnt im Zeitraum (d.Begin <= @from && d.End >= until) // Veranstaltung zieht sich über gesamten Zeitraum ); } var model = new RoomOccModel(); model.RoomId = roomId; if (nCollisions == 0) { model.State = "frei"; } else { model.State = String.Format("belegt (Anzahl Kollisionen {0})", nCollisions); } return(Json(model)); }
public JsonResult GetState(Guid?dateId, Guid roomId, string date, string begin, string end) { var sDate = DateTime.Parse(date); var sBegin = TimeSpan.Parse(begin); var sEnd = TimeSpan.Parse(end); var from = sDate.Add(sBegin); var until = sDate.Add(sEnd); var room = Db.Rooms.SingleOrDefault(r => r.Id == roomId); var dateList = room.Dates.Where(d => (d.End > @from && d.End <= until) || // Veranstaltung endet im Zeitraum (d.Begin >= @from && d.Begin < until) || // Veranstaltung beginnt im Zeitraum (d.Begin <= @from && d.End >= until) // Veranstaltung zieht sich über gesamten Zeitraum ).ToList(); var model = new RoomOccModel(); model.RoomId = roomId; if (dateList.Count == 0) { model.State = "frei"; } else if (dateList.Count == 1) { if (dateId.HasValue && dateList.Any(d => d.Id == dateId.Value)) { model.State = "selbst"; } else { model.State = "belegt"; } } else { model.State = "mehrfach belegt"; } return(Json(model)); }