Пример #1
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);
        }