public AttachStudentResultModel PostAddress(StudentAddressViewModel data) { var res = new AttachStudentResultModel { Done = false, Lines = new List <LineModel>(), Stations = new List <StationModel>() }; try { using (var logic = new tblStudentLogic()) { var st = logic.getStudentByPk(data.StudentId); if (st != null) { if (st.cityId != data.CityId || st.streetId != data.StreetId || st.houseNumber != data.HouseNumber) { st.street = data.Street; st.streetId = data.StreetId; st.city = data.City; st.cityId = data.CityId; st.houseNumber = data.HouseNumber; st.Lat = null; st.Lng = null; tblStudentLogic.update(st); //disconnect from all lines var detachResult = logic.RemoveStudentFromAllStations(st.pk); res.Student = new StudentShortInfo(st); res.Stations = detachResult.Stations.Select(d => new StationModel(d)).ToList(); res.Lines = detachResult.Lines.Select(d => new LineModel(d)).ToList(); res.Done = true; } } } } catch (Exception ex) { res.Done = false; } return(res); }
public AttachStudentResultModel PostDeleteAttachStudent(int id) { var res = new AttachStudentResultModel { Stations = new List <StationModel>(), Lines = new List <LineModel>() }; using (var logic = new StationsLogic()) { var itm = logic.GetAttachInfo(id); if (itm != null) { var stId = itm.StationId; var lnId = itm.LineId; res.Done = logic.DeleteAttach(id); if (lnId != -1) { using (var logic2 = new LineLogic()) { var ln = new LineModel(logic2.GetLine(lnId)) { Stations = logic2.GetStations(lnId) .Select(z => new StationToLineModel(z)) .ToList() }; res.Lines.Add(ln); } } var st = new StationModel(logic.GetStation(stId)) { Students = logic.GetStudents(stId) .Select(z => new StudentToLineModel(z)) .ToList() }; res.Stations.Add(st); } } return(res); }
public AttachStudentResultModel PostAttachStudent(AttachStudentModel model) { var res = new AttachStudentResultModel(); List <int> stations; List <int> lines; DateTime? date = null; if (!string.IsNullOrEmpty(model.StrDate)) { var dtList = model.StrDate.Split('/'); if (dtList.Length == 3) { date = new DateTime( int.Parse(dtList[2]), int.Parse(dtList[0]), int.Parse(dtList[1]), model.Hours, model.Minutes, 0); } } var wd = new WeekDays { Monday = model.Mon == "on", Tuesday = model.Tue == "on", Wednesday = model.Wed == "on", Thursday = model.Thu == "on", Friday = model.Fri == "on", Saturday = model.Sat == "on", Sunday = model.Sun == "on" }; using (var logic = new tblStudentLogic()) { var oldList = logic.GetAttachInfo(model.StudentId); stations = oldList.Select(z => z.StationId).ToList(); lines = oldList.Where(z => z.LineId != -1).Select(z => z.LineId).ToList(); } using (var logic = new StationsLogic()) { res.Done = logic.AttachStudent( model.StudentId, model.StationId, model.LineId, model.Distance, (ColorMode)model.UseColor, date, model.ConflictAction, wd); } using (var logic = new tblStudentLogic()) { var newList = logic.GetAttachInfo(model.StudentId); stations.AddRange(newList.Select(z => z.StationId).ToList()); lines.AddRange(newList.Where(z => z.LineId != -1).Select(z => z.LineId).ToList()); res.Student = new StudentShortInfo(logic.getStudentByPk(model.StudentId)); } using (var logic = new StationsLogic()) { res.Stations = logic.GetStations(stations) .Select(z => new StationModel(z)).ToList(); foreach (var station in res.Stations) { station.Students = logic.GetStudents(station.Id) .Select(z => new StudentToLineModel(z)) .ToList(); } } using (var logic = new LineLogic()) { res.Lines = logic.GetLines(lines).Select(z => new LineModel(z)).ToList(); foreach (var line in res.Lines) { line.Stations = logic.GetStations(line.Id) .Select(z => new StationToLineModel(z)) .ToList(); } } return(res); }