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 }); }