Exemple #1
0
        public void ShowGroupTimetable(Context context, Result result)
        {
            var user = context.SharedData.OfType <User>();

            context.SharedData.Remove(user);
            MessageTransfer msg = new MessageTransfer()
            {
                ChatId = user.Id
            };

            var group = result.Entities.OfType("groupName");
            var day   = result.Entities.OfType <DateEntity>(Sys.Date) ?? new DateEntity("", DateTime.Now);

            int groupId = -1;

            try
            {
                groupId = CistApi.GetGroupIdFromName(group.Value);
            }
            catch (Exception)
            {
                msg.Message = "Что-то я не нашел такой группы, попробуй ещё раз!";
                result.SendResponse(msg.ToJson());
                return;
            }

            DayTimetable timetable = CistApi.GetGroupTimetable(groupId, day.DateTime);

            msg.Message = timetable?.ToString() ?? $"В расписании нету пар на {day.DateTime.ToShortDateString()}";
            result.SendResponse(msg.ToJson());
        }
Exemple #2
0
        public void ShowNextDayTimetable(Context context, Result result)
        {
            var user = context.SharedData.OfType <User>();

            context.SharedData.Remove(user);
            MessageTransfer msg = new MessageTransfer()
            {
                ChatId = user.Id
            };

            var day = result.Entities.OfType <DateEntity>(Sys.Date);

            DayTimetable timetable = new DayTimetable();

            switch (user.Role)
            {
            case Role.Student:
                timetable = CistApi.GetGroupTimetable((user as Student).GroupId, day.DateTime);
                break;

            case Role.Teacher:
                timetable = CistApi.GetTeacherTimetable((user as Teacher).TeacherId, day.DateTime);
                break;

            default:
                break;
            }

            msg.Message = timetable?.ToString() ?? $"В расписании нету пар на {day.DateTime.ToShortDateString()}";
            result.SendResponse(msg.ToJson());
        }
Exemple #3
0
        public void ShowTodayTimetable(Context context, Result result)
        {
            var user = context.SharedData.OfType <User>();

            context.SharedData.Remove(user);
            MessageTransfer msg = new MessageTransfer()
            {
                ChatId = user.Id
            };

            DayTimetable timetable = new DayTimetable();

            switch (user.Role)
            {
            case Role.Student:
                timetable = CistApi.GetGroupTimetable((user as Student).GroupId, DateTime.Now);
                break;

            case Role.Teacher:
                timetable = CistApi.GetTeacherTimetable((user as Teacher).TeacherId, DateTime.Now);
                break;

            default:
                break;
            }

            msg.Message = timetable?.ToString() ?? "На сегодня пар нету!";
            result.SendResponse(msg.ToJson());
        }
Exemple #4
0
        public void ShowTeacherTimetable(Context context, Result result)
        {
            var user = context.SharedData.OfType <User>();

            context.SharedData.Remove(user);
            MessageTransfer msg = new MessageTransfer()
            {
                ChatId = user.Id
            };

            var teacher   = result.Entities.OfType("teacherName");
            var day       = result.Entities.OfType <DateEntity>(Sys.Date);
            int teacherId = -1;

            try
            {
                teacherId = CistApi.GetTeacherIdFromName(teacher.Value);
            }
            catch (Exception)
            {
                msg.Message = "Что-то я не нашел такого преподователя, попробуй ещё раз!";
                result.SendResponse(msg.ToJson());
                return;
            }

            DayTimetable timetable = CistApi.GetTeacherTimetable(teacherId, day.DateTime);

            msg.Message = timetable?.ToString() ?? $"В расписании нету пар на {day.DateTime.ToShortDateString()}";
            result.SendResponse(msg.ToJson());
        }
        public static DayTimetable GetTeacherNearestTimetable(int id, DateTime from)
        {
            string json;

            using (WebClient webClient = new WebClient())
            {
                json =
                    webClient.DownloadString(
                        new Uri(ApiRoot + "P_API_EVENTS_TEACHER_JSON?" + $"p_id_teacher={id}&time_from={ConvertToUnixTimestamp(from.AddDays(-1))}"));
            }

            RootEventObject root;

            try
            {
                root = JsonConvert.DeserializeObject <RootEventObject>(json);
            }
            catch (Exception)
            {
                return(null);
            }


            return(DayTimetable.GetNearestTimeTable(root));
        }
Exemple #6
0
    public void addDay(DayTimetable day, bool editMode = false, int sibling_index = -1)
    {
        var _not_deleted_pairs = day.pairs.Where(x => !x.deleted).ToList();

        if (_not_deleted_pairs.Count == 0)
        {
            return;
        }
        var d = (Instantiate(Resources.Load("Prefabs/UI/schedule/Day")) as GameObject).GetComponent <TTDayScript>();

        d._day = day;
        d.transform.SetParent(daysContainer, false);
        d.transform.localScale    = Vector3.one;
        d.transform.localScale    = Vector3.one;
        d.transform.localRotation = Quaternion.identity;

        if (sibling_index != -1)
        {
            // set sibling index
            d.transform.SetSiblingIndex(sibling_index);
        }

        d.dayTitle.text = day.getTranslatedDay();
        d.date.text     = day.day.ToString("d MMM", System.Globalization.CultureInfo.GetCultureInfo("ru-RU"));

        var shadow = Instantiate(Resources.Load("Prefabs/UI/schedule/UnderShadow")) as GameObject;

        shadow.transform.SetParent(daysContainer);
        shadow.transform.localScale = Vector3.one;


        var timePairDict = new Dictionary <string, List <Pair> > ();

        foreach (var p in _not_deleted_pairs)
        {
            if (!timePairDict.ContainsKey(p.time))
            {
                timePairDict [p.time] = new List <Pair> ();
            }
            timePairDict [p.time].Add(p);
        }

        var i = 0;

        foreach (var t in timePairDict)
        {
            var lastTime = i == timePairDict.Count - 1;

            d.addTime(t.Key, t.Value, lastTime, editMode);
            i++;
        }
    }