Ejemplo n.º 1
0
        public void FavouriteClickHandler(TestCardItemUC sender)
        {
            string responseJson;

            if (sender.isFavorite)
            {
                responseJson = ApiRequests.TestFavoriteDelete(getTestCardByItem(sender).testID);
            }
            else
            {
                responseJson = ApiRequests.TestFavoritePost(getTestCardByItem(sender).testID);
            }

            if (Parser.ResultParse(responseJson))
            {
                sender.switchFavorite();
            }
            else
            {
                MessageBox.Show("Что-то пошло не так", "Ошибка", MessageBoxButtons.OK);
            }
        }
Ejemplo n.º 2
0
        private void showCards()
        {
            getTestsDelegate getTests     = null;
            string           lastResponse = "";
            string           fieldName    = "testCards";

            switch (activeTab)
            {
            case 1:
                activeCards     = testCardsCreated;
                activeCardItems = testCardItemsCreated;
                getTests        = ApiRequests.CreatedTestsGet;
                lastResponse    = lastResponseCreated;
                fieldName       = "personalTestCards";
                break;

            case 2:
                activeCards     = testCardsPassed;
                activeCardItems = testCardItemsPassed;
                getTests        = ApiRequests.PassedTestsGet;
                lastResponse    = lastResponsePassed;
                break;

            case 3:
                activeCards     = testCardsFavorite;
                activeCardItems = testCardItemsFavorite;
                getTests        = ApiRequests.FavoriteTestsGet;
                lastResponse    = lastResponseFavorite;
                break;
            }

            string responseJson = getTests();

            if (Parser.ResultParse(responseJson))
            {
                if (!lastResponse.Equals(responseJson))  // update cache
                {
                    lastResponse = responseJson;

                    switch (activeTab)
                    {
                    case 1:
                        lastResponseCreated = lastResponse;
                        break;

                    case 2:
                        lastResponsePassed = lastResponse;
                        break;

                    case 3:
                        lastResponseFavorite = lastResponse;
                        break;
                    }

                    activeCards.Clear();
                    activeCards.AddRange(Parser.FieldParse <List <TestCard> >(responseJson, fieldName));


                    activeCardItems.Clear();
                    foreach (TestCard testCard in activeCards)
                    {
                        var item = new TestCardItemUC(testCard, this);
                        if (activeTab.Equals(3))
                        {
                            item.switchFavorite();
                        }
                        if (activeTab.Equals(1) && !testCard.isPublished)
                        {
                            item.unPublished();
                        }
                        activeCardItems.Add(item);
                    }
                }

                flowLayoutPanel1.Controls.Clear();
                flowLayoutPanel1.Controls.AddRange(activeCardItems.ToArray());

                if (flowLayoutPanel1.Controls.Count.Equals(0))
                {
                    flowLayoutPanel1.AutoScroll = false;
                }
                else
                {
                    flowLayoutPanel1.AutoScroll = true;
                }

                flowLayoutPanel1.Focus();
            }
            else
            {
                MessageBox.Show("Во время получения тестов произошла ошибка", "Ошибка", MessageBoxButtons.OK);
            }
        }