public MapStateModel GetState() { var res = new MapStateModel(); using (var logic = new LineLogic()) { res.Lines = logic.GetList().Select(z => new LineModel(z)).ToList(); foreach (var line in res.Lines) { line.Stations = logic.GetStations(line.Id) .OrderBy(z => z.Position) .Select(z => new StationToLineModel(z)) .ToList(); } } using (var logic = new StationsLogic()) { res.Stations = logic.GetList().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 tblStudentLogic()) { res.Students = logic.GetActiveStudents() .Select(z => new StudentShortInfo(z)) .ToList(); } return(res); }
public JsonResult PostSave(StationModel model) { double lat = 0; double lng = 0; double.TryParse(StringHelper.FixDecimalSeparator(model.StrLat), out lat); double.TryParse(StringHelper.FixDecimalSeparator(model.StrLng), out lng); var station = new Station { Id = model.Id, color = model.Color, StationName = model.Name, Lattitude = lat.ToString(CultureInfo.InvariantCulture), Longitude = lng.ToString(CultureInfo.InvariantCulture), StationType = model.Type, Address = model.Address }; var res = new SaveStationResultModel(); using (var logic = new StationsLogic()) { var stRes = logic.Save(station); res.Station = stRes == null ? null : new StationModel(stRes); if (res.Station != null) { res.Station.Students = logic.GetStudents(station.Id) .Select(z => new StudentToLineModel(z)) .ToList(); using (var logic2 = new LineLogic()) { res.Lines = logic2.GetLinesForStation(res.Station.Id) .Select(z => new LineModel(z)).ToList(); foreach (var line in res.Lines) { line.Stations = logic2.GetStations(line.Id) .OrderBy(z => z.Position) .Select(z => new StationToLineModel(z)) .ToList(); } } } } return(new JsonResult { Data = res }); }
public SaveStationToLineResult PostAddToLine(AddStationToLineModel model) { var positionMode = 0; if (model.StrAlwaysFirst == "on") { positionMode = 1; } if (model.StrAlwaysLast == "on") { positionMode = 2; } var ts = new TimeSpan(model.Hours, model.Minutes, 0); var res = new SaveStationToLineResult(); using (var logic = new StationsLogic()) { res.Done = logic.AddToLine( model.StationId, model.LineId, ts, model.Position, positionMode, model.ChangeColor); res.Station = new StationModel(logic.GetStation(model.StationId)); res.Station.Students = logic.GetStudents(model.StationId) .Select(z => new StudentToLineModel(z)) .ToList(); } using (var logic = new LineLogic()) { res.Line = new LineModel(logic.GetLine(model.LineId)); res.Line.Stations = logic.GetStations(model.LineId) .OrderBy(z => z.Position) .Select(z => new StationToLineModel(z)) .ToList(); } using (var logic = new tblStudentLogic()) { res.Students = logic.GetStudentsForStation(model.StationId) .Select(z => new StudentShortInfo(z)) .ToList(); } 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 EditLineResultModel PostSaveLine(LineModel data) { var res = new EditLineResultModel(); using (var logic = new LineLogic()) { res.Line = new LineModel( logic.SaveLine( data.Id, data.LineNumber, data.Name, data.Color, data.Direction)); res.Line.Stations = logic.GetStations(res.Line.Id) .OrderBy(z => z.Position) .Select(z => new StationToLineModel(z)) .ToList(); } using (var logic = new StationsLogic()) { res.Stations = logic.GetStationForLine(res.Line.Id) .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 tblStudentLogic()) { res.Students = logic.GetStudentsForLine(res.Line.Id) .Select(z => new StudentShortInfo(z)) .ToList(); } return(res); }
public SaveStationToLineResult PostDeleteFomLine(AddStationToLineModel model) { var res = new SaveStationToLineResult(); using (var logic = new StationsLogic()) { logic.DeleteFromLine(model.StationId, model.LineId); res.Station = new StationModel { Id = model.StationId }; } using (var logic = new LineLogic()) { res.Line = new LineModel(logic.GetLine(model.LineId)) { Stations = logic.GetStations(model.LineId) .OrderBy(z => z.Position) .Select(z => new StationToLineModel(z)) .ToList() }; } 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); }