示例#1
0
        public JsonResult EditLine(GridLineBusModel model)
        {
            using (var logic = new LineLogic())
            {
                switch ((GridOperation)Enum.Parse(typeof(GridOperation), model.Oper, true))
                {
                //case GridOperation.add:
                //    logic.SaveLine(model.ToDbModel());
                //    break;
                case GridOperation.edit:
                    var existingLine = logic.GetLine(model.Id);
                    if (existingLine != null)
                    {
                        //model.UpdateDbModel(existingLine);
                        //logic.SaveChanges();
                        logic.UpdateBusToLine(model.Id, model.Bus);
                    }
                    break;

                case GridOperation.del:
                    logic.DeleteLine(model.Id);
                    break;
                }
            }
            return(new JsonResult {
                Data = true
            });
        }
示例#2
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);
        }
示例#3
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 List <StationToLineModel> PostSaveGeometry(SaveGeometryModel model)
        {
            var res = new List <StationToLineModel>();

            using (var logic = new LineLogic())
            {
                var line = logic.GetLine(model.Id);
                if (line != null)
                {
                    line.PathGeometry = model.Data;
                    logic.SaveChanges();

                    string         fs = "0:0";
                    StationsToLine st = null;
                    st = line.Direction == 0 ? line.StationsToLines.OrderBy(s => s.Position).Last() : line.StationsToLines.OrderBy(s => s.Position).First();
                    if (line.StationsToLines.Select(l => l.ArrivalDate).Max() > st.ArrivalDate && line.Direction == 0)
                    {
                        st.ArrivalDate = line.StationsToLines.Select(l => l.ArrivalDate).Max();
                    }
                    fs = st.ArrivalDate.Hours + ":" + st.ArrivalDate.Minutes;
                    var data = new SaveDurationsModel
                    {
                        LineId       = model.Id,
                        Durations    = model.Durations,
                        FirstStation = fs
                    };
                    var ln = logic.ReCalcTimeTable(data);
                    if (ln != null)
                    {
                        res = ln.StationsToLines
                              .OrderBy(z => z.Position)
                              .Select(z => new StationToLineModel(z))
                              .ToList();
                    }
                }
            }
            return(res);
        }
        public JsonResult EditLine(GridLineModel model)
        {
            int LineIdToAutoCorrect = -1;

            using (var logic = new LineLogic()) {
                switch ((GridOperation)Enum.Parse(typeof(GridOperation), model.Oper, true))
                {
                case GridOperation.edit:
                    var existingLine = logic.GetLine(model.Id);
                    if (existingLine != null)
                    {
                        model.UpdateDbModel(existingLine);
                        logic.SaveChanges();
                        using (var busesToLinesLogic = new BusToLineLogic()) {
                            busesToLinesLogic.UpdateBusToLine(model.Id, model.Bus);
                        }
                        LineIdToAutoCorrect = existingLine.Id;
                    }
                    break;

                case GridOperation.del:
                    logic.DeleteLine(model.Id);
                    break;
                }
            }
            if (LineIdToAutoCorrect != -1)
            {
                var weekStart = DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek);
                using (var l = new tblScheduleLogic()) {
                    l.AutoCorrectLineSchedules(LineIdToAutoCorrect, weekStart, weekStart.AddDays(7));
                }
            }
            return(new JsonResult {
                Data = true
            });
        }
示例#6
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);
        }