Esempio n. 1
0
        public async void ChangeHomework(HomeworkItem homeworkItem)
        {
            var filter = Builders <BsonDocument> .Filter.Eq("_id", new ObjectId(homeworkItem.Id));

            var collection = Db.GetCollection <BsonDocument>("Homework");
            await collection.ReplaceOneAsync(filter, homeworkItem.ToBsonDocument());
        }
Esempio n. 2
0
        private static SubjectCoords GetSubjectCoords(HomeworkItem homework, ScheduleItem schedule)
        {
            SubjectCoords coords = new SubjectCoords();

            for (int i = 0; i < schedule.Schedule.Count; i++)
            {
                for (int j = 0; j < schedule.Schedule[i].Count; j++)
                {
                    if (homework.Week % 2 != 0)
                    {
                        if (schedule.Schedule[i][j][0] == homework.Subject)
                        {
                            coords.DayOfWeek     = i;
                            coords.SubjectNumber = j;
                            coords.WeekType      = 0;
                            return(coords);
                        }
                    }
                    else
                    {
                        if (schedule.Schedule[i][j][1] == homework.Subject)
                        {
                            coords.DayOfWeek     = i;
                            coords.SubjectNumber = j;
                            coords.WeekType      = 1;
                            return(coords);
                        }
                    }
                }
            }
            return(coords);
        }
Esempio n. 3
0
        public static bool IsSubjectExistInWeek(HomeworkItem homework, ScheduleItem schedule)
        {
            foreach (var day in schedule.Schedule)
            {
                foreach (var subject in day)
                {
                    if (homework.Week % 2 != 0)
                    {
                        if (subject[0] == homework.Subject)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        if (subject[1] == homework.Subject)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Esempio n. 4
0
        public static int GetRemainedDays(UserInfoItem userInfo, HomeworkItem homework, ScheduleItem schedule)
        {
            int currentWeek = Utils.GetCurrentWeek(userInfo.StartDate);

            SubjectCoords coords = GetSubjectCoords(homework, schedule);

            int days  = 0;
            int today = (Convert.ToInt32(DateTime.Now.DayOfWeek) + 6) % 7;

            days = (homework.Week - currentWeek) * 7 + (coords.DayOfWeek - today);
            return(days);
        }
Esempio n. 5
0
        private void LoadFromModel(HomeworkItem model)
        {
            DirectoryId  = model.DirectoryId;
            Title        = model.Title;
            Description  = model.Description;
            SubmitOnline = model.SubmitOnline;
            MaxPoints    = model.MaxPoints;

            if (model.Directory != null)
            {
                Directory = new DirectoryModel(model.Directory);
            }
        }
        public JsonResult ChangeHomework([FromBody] HomeworkItem homeworkItem)
        {
            if (homeworkItem != null)
            {
                var scheduleFilter = Builders <ScheduleItem> .Filter.Eq("userId", homeworkItem.UserId);

                var scheduleResult = _databaseService.GetItemsByFilter("Schedule", scheduleFilter);
                try
                {
                    if (scheduleResult != null)
                    {
                        if (Utils.IsSubjectExistInWeek(homeworkItem, scheduleResult[0]))
                        {
                            _databaseService.ChangeHomework(homeworkItem);
                        }
                        else
                        {
                            return(new JsonResult(new
                            {
                                message = "На выбранной неделе нет выбранного предмета!",
                                status = 404
                            }));
                        }
                    }
                }
                catch (Exception e)
                {
                    return(new JsonResult(new
                    {
                        message = "Ошибка при изменении домашнего задания! " +
                                  "Попробуйте позже",
                        status = 502
                    }));
                }

                return(new JsonResult(new
                {
                    message = "Домашнее задание успешно изменено",
                    Status = 200
                }));
            }

            return(new JsonResult(new
            {
                status = 404
            }));
        }
        public JsonResult AddHomework([FromBody] HomeworkItem homeworkItem)
        {
            if (homeworkItem != null)
            {
                var scheduleFilter = Builders <ScheduleItem> .Filter.Eq("userId", homeworkItem.UserId);

                var userFilter = Builders <UserInfoItem> .Filter.Eq("userId", homeworkItem.UserId);

                var userResult     = _databaseService.GetItemsByFilter("UsersInfo", userFilter);
                var scheduleResult = _databaseService.GetItemsByFilter("Schedule", scheduleFilter);


                if (userResult == null)
                {
                    return(new JsonResult(new
                    {
                        message = "Заполните информацию о пользователе",
                        status = 404
                    }));
                }

                try
                {
                    if (scheduleResult != null)
                    {
                        if (Utils.IsSubjectExistInWeek(homeworkItem, scheduleResult[0]))
                        {
                            _databaseService.Add("Homework", homeworkItem);
                        }
                        else
                        {
                            return(new JsonResult(new
                            {
                                message = "На выбранной неделе нет выбранного предмета!",
                                status = 404
                            }));
                        }
                    }
                }
                catch (Exception e)
                {
                    return(new JsonResult(new
                    {
                        message = "Ошибка при добавлении домашнего задания!" +
                                  " Попробуйте позже",
                        status = 502
                    }));
                }

                return(new JsonResult(new
                {
                    message = "Домашнее задание успешно добавлено",
                    status = 200
                }));
            }

            return(new JsonResult(new
            {
                status = 404
            }));
        }
Esempio n. 8
0
        public void LoadViewControls()
        {
            CurrentContainer.Children.Clear();
            ReviewedContainer.Children.Clear();
            OverdueContainer.Children.Clear();
            UnderReviewContainer.Children.Clear();


            foreach (var homework in StudentHomeworks)
            {
                HomeworkItemViewModel vm = new HomeworkItemViewModel();
                vm.MainGrid = this.MainGrid;

                vm.StudentHomework = homework;
                vm.Content         = homework.Homework.Content;
                vm.SentAt          = homework.SentAt;
                vm.EndAt           = homework.Homework.LastDay;
                //vm.Subject = homework.Homework.Lesson.Subject.Name;

                var  point = homework.Points.FirstOrDefault(x => x.PointStatu.Status == "Homework");
                bool endsWith_txt = false, endsWith_pdf = false;

                if (homework.File.EndsWith(".txt"))
                {
                    endsWith_txt = true;
                }
                if (homework.File.EndsWith(".pdf"))
                {
                    endsWith_pdf = true;
                }

                if (point != null)
                {
                    vm.Point = point.Point1.Value;
                }

                if (homework.Homework.LastDay > DateTime.Now && point == null && !endsWith_pdf && !endsWith_txt)
                {
                    HomeworkItem uc = new HomeworkItem();
                    uc.DataContext = vm;
                    CurrentContainer.Children.Add(uc);
                }
                else if (homework.Homework.LastDay < DateTime.Now && point == null && !endsWith_pdf && !endsWith_txt)
                {
                    OverdueHomeworkItemUC uc = new OverdueHomeworkItemUC();
                    uc.DataContext = vm;
                    OverdueContainer.Children.Add(uc);
                }
                else if (endsWith_pdf || endsWith_txt && homework.Checked.Value && point != null)
                {
                    ReviewedHomeworkItemUC uc = new ReviewedHomeworkItemUC();
                    uc.DataContext = vm;
                    ReviewedContainer.Children.Add(uc);
                }
                else if (endsWith_pdf || endsWith_txt && !homework.Checked.Value)
                {
                    UnderReviewHomeworkItemUC uc = new UnderReviewHomeworkItemUC();
                    uc.DataContext = vm;
                    UnderReviewContainer.Children.Add(uc);
                }
            }
        }
Esempio n. 9
0
    public void Receive(JObject json)
    {
        Debug.Log(json);
        Character character;

        switch ((int)json["type"])
        {
        case NetworkProtocol.TipMessage:
            TipMessage((string)json["message"]);
            break;

        case NetworkProtocol.EnterWorld:
            myNo = (int)json["no"];
            SceneManager.LoadScene("Game");
            break;

        case NetworkProtocol.NewObject:
            if (!isPlayer(json))
            {
                // 새로운 객체 생성
                GameObject gameObject = Instantiate(Preset.objects.NewGameObject);
                gameObjects.Add((int)json["no"], gameObject.GetComponent <Character>());
            }
            character = GetGameObject(json);
            GameObject skin = Instantiate(Resources.Load("Object/" + (string)json["skin"]) as GameObject);
            // Debug.Log(skin);
            skin.transform.parent        = character.transform;
            skin.transform.localPosition = Vector3.zero;
            skin.transform.localRotation = Quaternion.identity;
            character.No                 = (int)json["no"];
            character.Name               = (string)json["name"];
            character.Group              = (string)json["group"];
            character.function           = (string)json["function"];
            character.transform.position = new Vector3((float)json["x"], (float)json["y"], (float)json["z"]);
            character.transform.rotation = Quaternion.Euler(0, (float)json["q"], 0);
            break;

        case NetworkProtocol.RemoveObject:
            character = GetGameObject(json);
            gameObjects.Remove((int)json["no"]);
            DestroyImmediate(character.gameObject);
            break;

        case NetworkProtocol.Move:
            character = GetGameObject(json);
            character.Move(new Vector4((float)json["x"], (float)json["y"], (float)json["z"], (float)json["q"]));
            break;

        case NetworkProtocol.Chat:
            string color = "FFFFFF";
            switch ((int)json["chattype"])
            {
            case ChatType.Notice:
                color = "DBA901";
                break;

            case ChatType.Whisper:
                color = "F781BE";
                break;

            case ChatType.System:
                color = "82FA58";
                break;

            case ChatType.Group:
                color = "A9BCF5";
                break;
            }
            string groupmessage = "";
            if ((string)json["group"] != null)
            {
                groupmessage = "[" + (string)json["group"] + "] ";
            }
            if (json["no"] != null)
            {
                if ((int)json["chattype"] != ChatType.NPC)
                {
                    Preset.objects.ChatBox.Add(string.Format("[" + color + "]{2}{0} : {1}[-]", json["sender"], json["message"], groupmessage));
                }
                GetGameObject(json).ChatMessage((string)json["message"]);
            }
            else
            {
                Preset.objects.ChatBox.Add(string.Format("[" + color + "]{1}{0}[-]", json["message"], groupmessage));
            }
            break;

        case NetworkProtocol.Post_Open:
            Preset.objects.PostItem_Reset();
            foreach (JObject arrayitem in (JArray)json["items"])
            {
                Preset.objects.PostItem_Add(arrayitem);
            }
            Preset.objects.PostItems.GetComponent <UIGrid>().repositionNow = true;
            Preset.objects.PostWindow.TabChange("List");
            Preset.objects.PostCount.text = "새로운 알림 (" + json["newcount"] + "/" + json["count"] + ")";
            ((PostWindow)Preset.objects.PostWindow).pagelabel.text = json["page"] + " / " + json["all_page"];
            ((PostWindow)Preset.objects.PostWindow).page           = (int)json["page"];
            Preset.objects.OpenPostWindow();
            break;

        case NetworkProtocol.Post_Detail:
            Preset.objects.PostWindow.TabChange("Read");
            Preset.objects.PostWindow.GetComponent <PostWindowDetail>().Set(json);
            Preset.objects.OpenPostWindow();
            break;

        case NetworkProtocol.CloseNewStudy:
            Preset.objects.NewStudyWindow.Close();
            break;

        case NetworkProtocol.Keyword_Open:
            Preset.objects.KeywordWindow.NewList((JArray)json["list"]);
            Preset.objects.KeywordWindow.Open();
            break;

        case NetworkProtocol.Inventory_Add:
            Preset.objects.InventoryWindow.Add(json);
            break;

        case NetworkProtocol.Inventory_Remove:
            Preset.objects.InventoryWindow.Remove((int)json["no"]);
            break;

        case NetworkProtocol.Study_SignUp:
            if ((bool)json["ui"])
            {
                Preset.objects.StudySignUpWindow.Open((string)json["name"]);
            }
            else
            {
                Preset.objects.StudySignUpWindow.Close();
            }
            break;

        case NetworkProtocol.Study_UI:
            Preset.objects.StudyWindow.key = (string)json["name"];
            Preset.objects.StudyWindow.TabChange(json);
            Preset.objects.StudyWindow.Open();
            break;

        case NetworkProtocol.Homework_Add:
            HomeworkItem homeworkItem = Instantiate(Preset.objects.HomeworkItem, Preset.objects.HomeworkGrid.transform);
            homeworkItem.Title.text = (string)json["title"];
            homeworkItem.Date.text  = ((DateTime)json["date"]).ToString("yyyy-MM-dd") + "까지";
            homeworkItem.time       = (DateTime)json["date"];
            Preset.objects.HomeworkGrid.repositionNow = true;
            break;
        }
    }
Esempio n. 10
0
 public HomeworkItemModel(HomeworkItem model) : base(model)
 {
     LoadFromModel(model);
 }