Esempio n. 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
            });
        }
        public EditLineResultModel PostDeleteLine(int id)
        {
            var res = new EditLineResultModel();

            using (var logic = new LineLogic())
            {
                res.Done = logic.DeleteLine(id);
            }
            res.Line = new LineModel {
                Id = id
            };
            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
            });
        }