コード例 #1
0
        public IActionResult ClearTimeTable()
        {
            var clearTimeTable = TimeTableProvider.getTimeTable();

            clearTimeTable.ClearTimeTable();
            return(RedirectToAction("ClearTimeTableComplete"));
        }
コード例 #2
0
        public ActionResult Remove(string table, string item)
        {
            var timeTable = TimeTableProvider.getTimeTable();
            var dataTable = timeTable.GetDataTable(table);

            dataTable.Remove(item);
            return(RedirectToAction("Index", new { table }));
        }
コード例 #3
0
        public IActionResult Index(string table)
        {
            var timeTable = TimeTableProvider.getTimeTable();

            return(View(table != null
                                ? timeTable.GetDataTable(table)
                                : timeTable.dataTables.FirstOrDefault()
                        ));
        }
コード例 #4
0
        public IActionResult Index(string room, int slot, DayOfWeek day)
        {
            var timeTable = TimeTableProvider.getTimeTable();

            ViewData["Room"] = room;
            ViewData["Slot"] = slot;
            ViewData["Day"]  = day;

            return(View(timeTable));
        }
コード例 #5
0
        public IActionResult Load(string data = null)
        {
            var timeTable = TimeTableProvider.getTimeTable();

            if (data != null)
            {
                timeTable.ClearTimeTable();
                var dataObject = JObject.Parse(data);
                var rooms      = dataObject["rooms"];
                var groups     = dataObject["groups"];
                var classes    = dataObject["classes"];
                var teachers   = dataObject["teachers"];

                foreach (var value in rooms)
                {
                    timeTable.rooms.Add(value.Value <string>());
                }
                foreach (var value in groups)
                {
                    timeTable.groups.Add(value.Value <string>());
                }
                foreach (var value in classes)
                {
                    timeTable.classes.Add(value.Value <string>());
                }
                foreach (var value in teachers)
                {
                    timeTable.teachers.Add(value.Value <string>());
                }

                var activities = dataObject["activities"];
                foreach (var value in activities)
                {
                    var room     = value["room"].Value <string>();
                    var slot     = value["slot"].Value <int>();
                    var day      = (DayOfWeek)value["day"].Value <int>();
                    var activity = new TimeTable.Activity(room, slot, day)
                    {
                        group     = value["group"].Value <string>(),
                        className = value["class"].Value <string>(),
                        teacher   = value["teacher"].Value <string>()
                    };
                    timeTable.activities.Add(activity);
                }

                return(RedirectToAction("Index", "Room"));
            }
            else
            {
                return(View(timeTable));
            }
        }
コード例 #6
0
        public IActionResult Index(string room)
        {
            var timeTable = TimeTableProvider.getTimeTable();

            if (timeTable.rooms.Contains(room))
            {
                ViewData["ActiveRoom"] = room;
            }
            else
            {
                ViewData["ActiveRoom"] = timeTable.rooms.FirstOrDefault();
            }
            return(View(timeTable));
        }
コード例 #7
0
        public IActionResult Save()
        {
            var timeTable = TimeTableProvider.getTimeTable();
            var json      = JsonConvert.SerializeObject(new
            {
                rooms      = timeTable.rooms,
                groups     = timeTable.groups,
                classes    = timeTable.classes,
                teachers   = timeTable.teachers,
                activities = timeTable.activities
            }, Formatting.Indented);

            ViewBag.JsonData = json;
            return(View(timeTable));
        }
コード例 #8
0
        public ActionResult Remove(string room, DayOfWeek day, int slot)
        {
            var timeTable = TimeTableProvider.getTimeTable();
            var activity  = timeTable.GetActivityByRoomSlotAndDay(room, slot, day);

            if (timeTable.activities.Remove(activity))
            {
                TempData["Error"] = null;
            }
            else
            {
                TempData["Error"] = $"An activity on {day}, {timeTable.GetSlotTimeValue(slot)}, in room '{room}' was not found";
            }
            return(RedirectToAction("Index", "Room", new { room }));
        }
コード例 #9
0
        public ActionResult Append(string table, string item)
        {
            var timeTable = TimeTableProvider.getTimeTable();
            var dataTable = timeTable.GetDataTable(table);

            if (dataTable.Contains(item))
            {
                TempData["error"] = $"'{item}' already exists in '{table}'";
            }
            else
            {
                dataTable.Add(item);
                TempData["error"] = null;
            }
            return(RedirectToAction("Index", new { table }));
        }
コード例 #10
0
        public ActionResult Update(string room, int slot, DayOfWeek day, string group, string @class, string teacher)
        {
            var timeTable = TimeTableProvider.getTimeTable();
            var activity  = timeTable.GetActivityByRoomSlotAndDay(room, slot, day);

            if (activity != null)
            {
                activity.teacher   = teacher;
                activity.className = @class;
                activity.group     = group;
                TempData["Error"]  = null;
            }
            else
            {
                TempData["Error"] = $"An activity on {day}, {timeTable.GetSlotTimeValue(slot)}, in room '{room}' was not found";
            }
            return(RedirectToAction("Index", "Room", new { room }));
        }
コード例 #11
0
        public ActionResult Append(string room, int slot, DayOfWeek day, string group, string @class, string teacher)
        {
            var timeTable = TimeTableProvider.getTimeTable();
            var activity  = timeTable.GetActivityByRoomSlotAndDay(room, slot, day);

            if (activity == null)
            {
                activity           = new TimeTable.Activity(room, slot, day);
                activity.teacher   = teacher;
                activity.className = @class;
                activity.group     = group;

                timeTable.activities.Add(activity);

                TempData["Error"] = null;
                return(RedirectToAction("Index", "Room", new { room }));
            }
            else
            {
                TempData["Error"] = $"An activity already exists on {day}, {timeTable.GetSlotTimeValue(slot)}, in room '{room}'";
                return(RedirectToAction("Index", "Room", new { room }));
            }
        }
コード例 #12
0
        public async Task <IActionResult> UploadFile(IFormFile file)
        {
            var timeTable = TimeTableProvider.getTimeTable();

            if (file != null && file.Length > 0)
            {
                var data = new StringBuilder();
                using (var reader = new StreamReader(file.OpenReadStream()))
                {
                    while (reader.Peek() >= 0)
                    {
                        data.AppendLine(await reader.ReadLineAsync());
                    }
                }

                if (data != null)
                {
                    var dataObject = JObject.Parse(data.ToString());
                    if (dataObject.ContainsKey("rooms") && dataObject.ContainsKey("groups") && dataObject.ContainsKey("classes") && dataObject.ContainsKey("teachers") && dataObject.ContainsKey("activities"))
                    {
                        timeTable.ClearTimeTable();
                        var rooms    = dataObject["rooms"];
                        var groups   = dataObject["groups"];
                        var classes  = dataObject["classes"];
                        var teachers = dataObject["teachers"];

                        foreach (var value in rooms)
                        {
                            timeTable.rooms.Add(value.Value <string>());
                        }
                        foreach (var value in groups)
                        {
                            timeTable.groups.Add(value.Value <string>());
                        }
                        foreach (var value in classes)
                        {
                            timeTable.classes.Add(value.Value <string>());
                        }
                        foreach (var value in teachers)
                        {
                            timeTable.teachers.Add(value.Value <string>());
                        }

                        var activities = dataObject["activities"];
                        foreach (var value in activities)
                        {
                            var room     = value["room"].Value <string>();
                            var slot     = value["slot"].Value <int>();
                            var day      = (DayOfWeek)value["day"].Value <int>();
                            var activity = new TimeTable.Activity(room, slot, day)
                            {
                                group     = value["group"].Value <string>(),
                                className = value["className"].Value <string>(),
                                teacher   = value["teacher"].Value <string>()
                            };
                            timeTable.activities.Add(activity);
                        }

                        return(RedirectToAction("Index", "Room"));
                    }
                }
            }
            return(View(timeTable));
        }