private static void AddNewRowToTimetable(TeachersBookEntities2 ctx, int rowCounter, TimeTables timetabelDb, TtSubjectsRow timetablerow) { try { TimeTableRows newRowDb = new TimeTableRows(); newRowDb.id = Guid.NewGuid(); newRowDb.rowNo = rowCounter; newRowDb.timetable = timetabelDb.id; var startEnd = timetablerow.subjects[0].description.Split('-'); newRowDb.start = startEnd[0].Trim(); newRowDb.end = startEnd.Length > 1 ? startEnd[1].Trim() : ""; ctx.TimeTableRows.Add(newRowDb); } catch (Exception ex) { Console.WriteLine("Error"); } }
private static void AddAllSubjectsOfNewRowToTimetable(TimeTableRows newRow, TeachersBookEntities2 ctx, int rowCounter, TtSubjectsRow timetablerow) { int counter = 0; foreach (var subject in timetablerow.subjects) { if (counter > 1) { TimeTableIItems newTimetableItem = new TimeTableIItems(); newTimetableItem.id = Guid.NewGuid(); newTimetableItem.day = counter; newTimetableItem.type = "subject"; SubjectToTimeTableHours newTimetableItemDetails = new SubjectToTimeTableHours(); newTimetableItemDetails.timetableId = newTimetableItem.id; newTimetableItemDetails.subjectId = Guid.Parse(subject.lesson.id); newRow.TimeTableIItems.Add(newTimetableItem); counter++; } } }
public IHttpActionResult GetComplete(string schoolYear) { using (var ctx = new TeachersBookEntities2()) { var identity = (ClaimsIdentity)User.Identity; var id = ((ClaimsIdentity)User.Identity).FindFirst("id"); var userQuery = from u in ctx.UserData where u.id.ToString() == id.Value.ToString() select u; var user = userQuery.FirstOrDefault <UserData>(); var schoolYearsQuery = from sy in user.SchoolYears where sy.schoolYear.ToString() == schoolYear select sy; var _schoolYear = schoolYearsQuery.FirstOrDefault <SchoolYears>(); var timetabel = _schoolYear.TimeTables.FirstOrDefault <TimeTables>(); var returnObj = new Timetable(); foreach (var timetablerow in timetabel.TimeTableRows.OrderBy(x => x.rowNo)) { TtSubjectsRow newRow = new TtSubjectsRow(); newRow.id = timetablerow.id.ToString(); newRow.start = timetablerow.start; newRow.end = timetablerow.end; int currentRowNo = timetablerow.rowNo ?? default(int); TtSubjectsRowItem TeachersBookDescriptionItem = new TtSubjectsRowItem(); TeachersBookDescriptionItem.day = 0; TeachersBookDescriptionItem.hour = currentRowNo; TeachersBookDescriptionItem.description = timetablerow.start + " - " + timetablerow.end; newRow.subjects.Add(TeachersBookDescriptionItem); var items = timetablerow.TimeTableIItems.ToList <TimeTableIItems>(); foreach (TimeTableIItems item in items) { if (item.type == "subject") { newRow.rowType = "subject"; TtSubjectsRowItem newRowItem = new TtSubjectsRowItem(); newRowItem.day = item.day ?? default(int); newRowItem.hour = currentRowNo; newRowItem.description = item.description; newRowItem.id = item.id.ToString(); TtLesson newLesson = new TtLesson(); newLesson.id = item.SubjectToTimeTableHours.Subjects.id.ToString(); newLesson.name = item.SubjectToTimeTableHours.Subjects.description; newLesson.color = item.SubjectToTimeTableHours.Subjects.color; TtClass newClass = new TtClass(); newClass.id = item.SubjectToTimeTableHours.Subjects.Classes.id.ToString(); newClass.name = item.SubjectToTimeTableHours.Subjects.Classes.name; newLesson.TtClass = newClass; newRowItem.lesson = newLesson; newRow.subjects.Add(newRowItem); } else { newRow.rowType = "break"; TtSubjectsRowItem newRowItem = new TtSubjectsRowItem(); newRowItem.id = item.id.ToString(); newRowItem.day = item.day ?? default(int); newRowItem.hour = currentRowNo; newRowItem.description = item.description; newRow.subjects.Add(newRowItem); } } returnObj.rows.Add(newRow); } return(Ok(returnObj)); } }