Beispiel #1
0
        public ActionResult RegisterStudent()
        {
            ViewBag.User = (User)Session["User"];
            User user = (User)Session["User"];

            ViewBag.Teacher = TeacherMethods.GetCourses(user.TeacherId);
            return(View("AddStudent"));
        }
Beispiel #2
0
        public ActionResult ListCourses()
        {
            ViewBag.User = (User)Session["User"];
            User         user   = (User)Session["User"];
            TeacherModel model  = new TeacherModel();
            var          result = TeacherMethods.GetCourses(user.TeacherId);

            if (result != null)
            {
                model.teach = result;
            }
            return(View("ListCourses", model));
        }
 public void FillDB()
 {
     String[] ArrayOfNames =
     {
         "Chayndunth, Lord Of The Brown",
         "Gayzzur, The White",
         "Bimroi, The Taker Of Life",
         "Qonnu, The Dead",
         "Churso, The Fast One",
         "Baethe, The Bunny Killer",
         "Chuvoa, The Protective",
         "Ovnanoal, The Protective",
         "Dunneintei, The Grumpy",
         "Peorlirrath, The Bright",
         "Dundeonth, The Squeeler",
         "Sedath, The Redeemer",
         "Zeovae, The Barbarian",
         "Deirma, Champion Of The Brown",
         "Golryr, The Victorious",
         "Cygiorth, Lord Of Ice",
         "Dundit, Destroyer Of Life",
         "Quvurriet, The Strong Minded",
         "Aezzyrun, Champion Of The Skies",
         "Eoludoalth, Protector Of The Forest",
         "Ilrie, The Puny",
         "Ziassut, The Calm",
         "Qeidraylth, Braveheart",
         "Diarleith, Giver Of Life",
         "Eige, The Fierce",
         "Fryzzoal, The Rabbit Slayer",
         "Todruss, The Grumpy",
         "Zeovniassaet, The Strong",
         "Arsonieth, The Hungry",
         "Qayveiral, The Evil One",
         "Ierrath, Eater Of All",
         "Naylass, Lord Of The White",
         "Oldrun, The Jealous One",
         "Xeiphael, The Dark One",
         "Tiolraylth, The Firestarter",
         "Vizyth, Champion Of The Green",
         "Uzzog, The Tall",
         "Nandrunioss, The Eternal",
         "Sunnoidurth, Champion Of The Skies",
         "Moanoarroanth, The Dark",
         "Caghad, The Clean",
         "Rayghianth, The Puny",
         "Tiallienth, The White One",
         "Aevraynth, The Kind",
         "Mayllerth, The Gifted",
         "Sumath, The Taker Of Life",
         "Ova, Lord Of The Black",
         "Qurmuryt, Redeemer Of Men",
         "Xuziedait, The Brave",
         "Pemorriolth, The Creep"
     };
     String[] array_of_addresses =
     {
         "663 East Hilltop Road Webster, NY 14580",
         "690 Highland St. Garden City, NY 11530",
         "36 Central Ave. Pueblo, CO 81001",
         "544 Halifax Ave. Amityville, NY 11701",
         "653 Sunnyslope Road Erlanger, KY 41018",
         "876 Harvey Dr. Fremont, OH 43420",
         "21 Longfellow Ave.Kansas City, MO 64151",
         "7975 Spruce Road Danbury, CT 06810",
         "414 Pulaski St. Hyde Park, MA 02136",
         "8800 Acacia Street Lake Zurich, IL 60047",
         "39 Manor Dr. Evanston, IL 60201",
         "304 Ryan Drive Lansdowne, PA 19050",
         "4 Briarwood Street Palos Verdes Peninsula, CA 90274",
         "8165 Buttonwood St. Mount Holly, NJ 08060",
         "9057 Brewery Lane Staunton, VA 24401",
         "7355 Mayfield Ave. Irwin, PA 15642",
         "9 South Cherry Hill Street East Elmhurst, NY 11369",
         "15 Wild Rose Dr. Florence, SC 29501",
         "7288 Sheffield St. Stow, OH 44224",
         "375 Arcadia St. Cranberry Twp, PA 16066",
         "895 Brickyard Court Reisterstown, MD 21136",
         "626 Tarkiln Hill Lane Buckeye, AZ 85326",
         "9437 Ryan Rd. Elkhart, IN 46514",
         "461 Central Court Brockton, MA 02301",
         "27 Cedar Lane Waltham, MA 02453",
         "55 Bohemia St. Goshen, IN 46526",
         "900 Oakwood Street Algonquin, IL 60102",
         "88 Beacon St. Roselle, IL 60172",
         "754 Cooper Drive Loxahatchee, FL 33470",
         "7754 Cedarwood Ave. Coram, NY 11727",
         "8813 Clark Court Lake Mary, FL 32746",
         "29 Cherry Hill Court Sacramento, CA 95820",
         "375 Tunnel Dr. Livingston, NJ 07039",
         "9015 Buttonwood Court Coram, NY 11727",
         "799 Elizabeth Drive Parlin, NJ 08859",
         "79 Old York Ave. Largo, FL 33771",
         "451 Cedar St. Benton Harbor, MI 49022",
         "9612 Bridle Lane Peachtree City, GA 30269",
         "8 Belmont St. Hopkinsville, KY 42240",
         "7 Arnold Ave. Merrillville, IN 46410",
         "956 SW. Oklahoma St. Howard Beach, NY 11414",
         "35 Miles Avenue Mableton, GA 30126",
         "85 North Overlook Dr. Raeford, NC 28376",
         "727 Orange Drive El Paso, TX 79930",
         "76 Golf Dr. El Paso, TX 79930",
         "9261 Myrtle Lane Eden Prairie, MN 55347",
         "36 Morris Street Murrells Inlet, SC 29576",
         "9069 Plymouth St.Randallstown, MD 21133",
         "28 Taylor Lane Enfield, CT 06082",
         "54 Rocky River St. Goose Creek, SC 29445"
     };
     String[] course_name_arr =
     {
         "Terraforming",
         "Alien Environmental Development",
         "Alien Finance",
         "Alien Anthropology",
         "Alien Martial Arts",
         "Audiology",
         "Planetary Survival",
         "Small Forces Strategy",
         "Alchemy",
         "Alien Biosecurity",
         "Galactic Diplomacy",
         "Foreign Life Science",
         "Alien Sociology",
         "Physical Science",
         "Divining",
         "Alien Social Studies",
         "Elemental Magic",
         "Alien Life Science",
         "Foreign Criminal Justice",
         "Planetary Oceanography",
         "Space Travel",
         "Planetary Chemistry",
         "Nutrition",
         "Alien Medical Physics",
         "Alien Nutrition",
         "Enhanced Therapy",
         "Foreign Social Studies",
         "Planetary Chemistry",
         "Alien P.E.",
         "Foreign Dance",
         "Magic Law",
         "Earth Science",
         "Alien Ethics",
         "Alien Statistics",
         "Charm Casting",
         "Monster Hunting",
         "Curse Creation",
         "Terraforming",
         "Alien Family Psychology",
         "Alien Musical Arts"
     };
     for (var i = 0; i < 50; i++)
     {
         Random rnd  = new Random();
         User   user = new User();
         user.FullName    = ArrayOfNames[rnd.Next(0, 50)];
         user.Adress      = array_of_addresses[rnd.Next(0, 50)];
         user.UserID      = Guid.NewGuid();
         user.StudentID   = Guid.NewGuid();
         user.Password    = "******" + rnd.Next(0, 500);
         user.Mail        = rnd.Next(0, 500) + "@mail.com";
         user.Username    = "******" + rnd.Next(0, 500);
         user.PhoneNumber = "" + rnd.Next(100000000, 999999999);
         Student stu = new Student();
         stu.StudentId = (Guid)user.StudentID;
         stu.GPA       = 0;
         Transcript trans = new Transcript();
         trans.cid      = 1;
         trans.GPA      = 0;
         trans.Semester = "2018 Fall";
         stu.Transcript.Add(trans);
         user.Student = stu;
         UserMethods.AddUser(user);
     }
     for (var i = 0; i < 50; i++)
     {
         Random rnd  = new Random();
         User   user = new User();
         user.FullName    = ArrayOfNames[rnd.Next(0, 50)];
         user.Adress      = array_of_addresses[rnd.Next(0, 50)];
         user.UserID      = Guid.NewGuid();
         user.EmployeeID  = Guid.NewGuid();
         user.Password    = "******" + rnd.Next(500, 1000);
         user.Mail        = rnd.Next(500, 1000) + "@mail.com";
         user.Username    = "******" + rnd.Next(500, 1000);
         user.PhoneNumber = "" + rnd.Next(100000000, 999999999);
         Employee employee = new Employee();
         employee.Salary     = rnd.Next(5000, 10000);
         employee.CompanyId  = Guid.Parse("7895cf05-aced-494b-9889-b42b0bf761ca");
         employee.EmployeeId = (Guid)user.EmployeeID;
         Insurence insurence = new Insurence();
         insurence.InsuranceType = "Full";
         insurence.Status        = "Active";
         insurence.StartDate     = DateTime.Today;
         insurence.InsuranceID   = Guid.NewGuid();
         employee.Insurence.Add(insurence);
         user.Employee = employee;
         UserMethods.AddUser(user);
     }
     for (int i = 0; i < 40; i++)
     {
         Random rnd    = new Random();
         Course course = new Course();
         course.cid        = i + 2;
         course.TeacherId  = Guid.Parse("c6e66151-6b4f-4b43-a7e1-bfdb2bcbe246");
         course.CourseName = course_name_arr[i];
         TeacherMethods.AddCourse(course);
     }
 }
        static async void BotOnMessageReceived(object sender, MessageEventArgs MessageEventArgs)
        {
            Telegram.Bot.Types.Message msg = MessageEventArgs.Message;
            if (msg == null || msg.Type != MessageType.Text)
            {
                return;
            }

            string Answer = "Server Error";

            if (System.DateTime.UtcNow.Subtract(msg.Date).TotalMinutes > 3)
            {
                await BOT.SendTextMessageAsync(msg.Chat.Id, Answer);

                return;
            }

            if (UserList.ContainsKey(msg.Chat.Id))
            {
                UserList[msg.Chat.Id].LastAccess = DateTime.Now;
            }

            if (!IsRegistered(msg.Chat.Id))
            {
                if (!UserList.ContainsKey(msg.Chat.Id))
                {
                    UserList.Add(msg.Chat.Id, new User());
                }
                Answer = Registration(msg);      //регистрация студента
            }//prev command was /findteacher
            else if (UserList[msg.Chat.Id].ident == 4)
            {
                if (!NameMatches.ContainsKey(msg.Chat.Id))
                {
                    var lst = ReturnTeachersId(msg.Text);
                    if (lst.Length == 1)
                    {
                        Answer = LessonTechToStr(TeacherMethods.GetCurrentLesson(lst[0].id), true);
                        UserList[msg.Chat.Id].ident = 3;
                    }
                    else if (lst.Length > 1)
                    {
                        NameMatches.Add(msg.Chat.Id, lst);
                        var s = $"Найдено несколько совпадений:\n";
                        for (var i = 0; i < lst.Length; i++)
                        {
                            s = s + $"{i + 1}) {lst[i].name}\n";
                        }
                        s      = s + "Ввведи номер выбранного преподавателя.";
                        Answer = s;
                    }
                    else
                    {
                        Answer = "Ошибка, преподаватель не найден! Попробуй ещё раз.";
                    }
                }
                else
                {
                    if (int.TryParse(msg.Text, out int n) && n - 1 < NameMatches[msg.Chat.Id].Length && n - 1 >= 0)
                    {
                        var LCG = TeacherMethods.GetCurrentLesson(NameMatches[msg.Chat.Id][n - 1].id);
                        Answer = LessonTechToStr(LCG, true);
                        UserList[msg.Chat.Id].ident = 3;
                        NameMatches.Remove(msg.Chat.Id);
                    }
                    else
                    {
                        Answer = "Ошибка, введён некорректный номер.";
                    }
                }
            }
            else if (UserList[msg.Chat.Id].ident == 5)
            {
                bool onOrOff = msg.Text.ToLower() == "включить";
                UserList[msg.Chat.Id].eveningNotify = onOrOff;
                UserList[msg.Chat.Id].ident         = 3;
                Json_Data.WriteData();
                string onOrOffMsg = onOrOff ? "включено" : "выключено";
                Answer = $"Вечернее уведомление *{onOrOffMsg}*.";
            }
            else if (UserList[msg.Chat.Id].ident == 6)
            {
                bool onOrOff = msg.Text.ToLower() == "включить";
                UserList[msg.Chat.Id].preLessonNotify = onOrOff;
                UserList[msg.Chat.Id].ident           = 3;
                Json_Data.WriteData();
                string onOrOffMsg = onOrOff ? "включено" : "выключено";
                Answer = $"Уведомление за 15 минут до первой пары *{onOrOffMsg}*.";
            }
            else
            {
                try
                {
                    switch (msg.Text.ToLower())             // Обработка команд боту
                    {
                    case "/next":
                    case "ближайшая пара":
                        if (UserList[msg.Chat.Id].Info != User.UserInfo.teacher)
                        {
                            Answer = LessonToStr(StudentMethods.GetCurrentLesson(UserList[msg.Chat.Id].groupid), true);
                        }
                        else
                        {
                            Answer = LessonTechToStr(TeacherMethods.GetCurrentLesson(UserList[msg.Chat.Id].teacherId), true);
                        }
                        break;

                    case "/findteacher":
                    case "найти преподавателя":
                        Answer = "Введи фамилию преподавателя";
                        UserList[msg.Chat.Id].ident = 4;
                        break;

                    case "/week":
                    case "расписание на неделю":
                        if (UserList[msg.Chat.Id].Info != User.UserInfo.teacher)
                        {
                            Answer = WeekSchToStr(StudentMethods.GetWeekSchedule(UserList[msg.Chat.Id].groupid));
                        }
                        else
                        {
                            Answer = WeekSchTechToStr(TeacherMethods.GetWeekSchedule(UserList[msg.Chat.Id].teacherId));
                        }
                        break;

                    case "/today":
                    case "расписание на сегодня":
                        if (UserList[msg.Chat.Id].Info != User.UserInfo.teacher)
                        {
                            Answer = DaySchToStr(StudentMethods.GetTodaySchedule(UserList[msg.Chat.Id].groupid));
                        }
                        else
                        {
                            Answer = DaySchTechToStr(TeacherMethods.GetTodaySchedule(UserList[msg.Chat.Id].teacherId));
                        }
                        break;

                    case "/tomorrow":
                    case "расписание на завтра":
                        if (UserList[msg.Chat.Id].Info != User.UserInfo.teacher)
                        {
                            Answer = DaySchToStr(StudentMethods.GetTomorrowSchedule(UserList[msg.Chat.Id].groupid));
                        }
                        else
                        {
                            Answer = DaySchTechToStr(TeacherMethods.GetTomorrowSchedule(UserList[msg.Chat.Id].teacherId));
                        }
                        break;

                    case "/knowme":
                    case "знаешь меня?":
                        if (UserList[msg.Chat.Id].Info == User.UserInfo.teacher)
                        {
                            Answer = $"Вы {TeacherList[UserList[msg.Chat.Id].teacherId].name}";         //База старая, так что выводим только ФИО!!!
                        }
                        else
                        {
                            Answer = $"Вы {msg.Chat.FirstName.Replace("`","").Replace("_","").Replace("*","")} из группы {StudentMethods.groupIDToCourseGroup(UserList[msg.Chat.Id].groupid)}";
                        }
                        break;

                    case "/eveningnotify":
                        Answer = $"Сейчас вечернее уведомление о завтрашней первой паре *{(UserList[msg.Chat.Id].eveningNotify? "включено" : "выключено")}*. \nНастройте его.";
                        UserList[msg.Chat.Id].ident = 5;
                        await BOT.SendTextMessageAsync(msg.Chat.Id, Answer, ParseMode.Markdown, replyMarkup : notifierKeyboard);

                        return;

                    case "/prelessonnotify":
                        Answer = $"Сейчас уведомление за 15 минут до первой пары *{(UserList[msg.Chat.Id].preLessonNotify ? "включено" : "выключено")}*. \nНастройте его.";
                        UserList[msg.Chat.Id].ident = 6;
                        await BOT.SendTextMessageAsync(msg.Chat.Id, Answer, ParseMode.Markdown, replyMarkup : notifierKeyboard);

                        return;


                    case "/forget":
                    case "забудь меня":
                        UserList.Remove(msg.Chat.Id);
                        Json_Data.WriteData();
                        Answer = "Я вас забыл! Для повторной регистрации пиши /start";
                        await BOT.SendTextMessageAsync(msg.Chat.Id, Answer, replyMarkup : new ReplyKeyboardRemove());

                        return;

                    case "помощь":
                    case "/help":
                        Answer = _help;
                        break;

                    case "/info":
                    case "информация":
                        Answer = "Меня создали Миша, Дима, Дима, Глеб, Никита, Ира, Максим в рамках проектной деятельности на ФИиИТ в 2018-2019 уч. году.\n" +
                                 "Я предоставляю доступ к интерактивному расписанию мехмата через платформу ботов Telegram.\n" +
                                 "Если обнаружили ошибку в расписании, проверьте, совпадает ли оно с указанным на schedule.sfedu.ru. " +
                                 "При сопададении, для исправления обратитесь в деканат, либо напишите на [email protected], в противном случае напишите [Михаилу](tg://user?id=61026374).";
                        break;

                    case "/optionalcourses":
                    case "факультативы":
                        Answer = electivesStr;
                        break;

                    case "/curweek":
                        Answer = $"Сейчас *{CurrentSubject.GetCurrentWeek().ToString()}* неделя.";
                        break;

                    case "/forceupdate":
                        logger.Info($"Запрошено принудительное обновление расписаний, ID: {msg.Chat.Id}, @{msg.Chat.Username}.");
                        TeachersInit(false);
                        GradeInit(false);
                        GroupShedListInit(false);
                        TeachersShedInit(false);
                        WeekInit(false);
                        logger.Info($"Завершено принудительное обновление расписаний, ID: {msg.Chat.Id}, @{msg.Chat.Username}.");
                        Answer = "Данные расписаний обновлены!";
                        break;

                    default:
                        Answer = "Введены неверные данные, повторите попытку.";
                        break;
                    }
                }
                catch (System.Net.WebException e)
                {
                    logger.Error(e, "Catched exeption:");
                    Answer = "Ошибка! Вероятно, сервер интерактивного расписания недоступен. Пожалуйста, попробуйте повторить запрос позднее.";
                }
            }
            try
            {
                if (IsRegistered(msg.Chat.Id))
                {
                    await BOT.SendTextMessageAsync(msg.Chat.Id, Answer, ParseMode.Markdown, replyMarkup : UserList[msg.Chat.Id].Info == User.UserInfo.teacher?teacherKeyboard : studentKeyboard);
                }
                else if (UserList[msg.Chat.Id].ident == 1)
                {
                    await BOT.SendTextMessageAsync(msg.Chat.Id, Answer, replyMarkup : registrationKeyboard);
                }
                else
                {
                    await BOT.SendTextMessageAsync(msg.Chat.Id, Answer);
                }
            }
            catch (Exception ex) when(ex is System.Net.Http.HttpRequestException && ex.Message.Contains("429"))
            {
                logger.Warn(ex, $"Сетевая ошибка при ответе @{msg.Chat.Username}");
            }
        }