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);
        }
Exemple #2
0
 public JsonResult ChangeStationPosition(int stationId, int lineId, int newPosition)
 {
     using (var l = new StationsLogic())
     {
         var result = l.ChangeStationPosition(stationId, lineId, newPosition);
         return(new JsonResult {
             Data = result
         });
     }
 }
Exemple #3
0
        public JsonResult PostDelete(int id)
        {
            bool res;

            using (var logic = new StationsLogic())
            {
                res = logic.Delete(id);
            }
            return(new JsonResult {
                Data = res
            });
        }
Exemple #4
0
        public List <StationModel> GetList()
        {
            var res = new List <StationModel>();

            using (var logic = new StationsLogic())
            {
                var lst = logic.GetList();
                foreach (var st in lst)
                {
                    res.Add(new StationModel(st));
                }
            }
            return(res);
        }
Exemple #5
0
        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
            });
        }
Exemple #6
0
        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);
        }
Exemple #7
0
 //[Authorize]
 //public JsonResult regPay1(string h)
 //{
 //    return Json(JsonRequestBehavior.AllowGet);
 //}
 //------------------------------------//
 // GET: tblStudent
 public ActionResult Index()
 {
     using (var logic = new tblStudentLogic())
     {
         ViewBag.Classes       = logic.Classes();
         ViewBag.Shicvas       = logic.Shicvas();
         ViewBag.DefaultCityId = logic.DefaultCityId;
     }
     if (ViewBag.DefaultCityId > 0)
     {
         using (var logic5 = new tblStreetsLogic())
         {
             ViewBag.DefaultCity = logic5.GetCityById(ViewBag.DefaultCityId);
         }
     }
     using (var logic2 = new LineLogic())
     {
         ViewBag.Lines = logic2.GetList();
     }
     using (var logic3 = new StationsLogic())
     {
         ViewBag.Stations = logic3.GetList();
     }
     using (var logic4 = new tblFamilyLogic())
     {
         ViewBag.Families = JsonConvert.SerializeObject(logic4.GetAll().Select(z => new
         {
             Id   = z.familyId,
             Name = z.parent1FirstName + " " + z.parent1LastName +
                    (z.oneParentOnly ? "" : " / " + z.parent2FirstName + " " + z.parent2LastName)
         }));
     }
     using (var logic5 = new tblSchoolLogic())
     {
         ViewBag.Schools = JsonConvert.SerializeObject(logic5.GetList().Select(z => new
         {
             Id   = z.id,
             Name = z.name
         }));
     }
     return(View());
 }
Exemple #8
0
        public StudentToLineModel PostUpdateAttachStudent(AttachStudentModel model)
        {
            StudentToLineModel res = null;

            if (model.Id == 0) //update distance
            {
                using (var logic = new StationsLogic())
                {
                    if (logic.UpdateDistance(model.StudentId, model.StationId, model.Distance))
                    {
                        var att = logic.GetAttachInfo(model.StudentId, model.StationId);
                        if (att.Count > 0)
                        {
                            res = new StudentToLineModel(att[0]);
                        }
                    }
                }
            }
            return(res);
        }
Exemple #9
0
        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);
        }
Exemple #11
0
        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);
        }
Exemple #12
0
        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);
        }