Пример #1
0
        public IActionResult Add()
        {
            var model = new Flashcard();

            PopulateLanguageDropdownList();
            return(View(model));
        }
Пример #2
0
        public void CopyFlashcards(Guid fromUserId, Guid toUserId, Guid categoryId)
        {
            var user = UserController._users.First(x => x.Id == toUserId);

            if (user == null)
            {
                throw new Exception("User does not exists");
            }

            var fiszki = _fiszki.Where(x => x.UserId == fromUserId && x.CategoryId == categoryId).ToList();

            var kategoria = CategoryController._category.First(x => x.Id == categoryId);

            if (kategoria == null)
            {
                throw new Exception("category does not exists");
            }

            var nowaKategoria = new Category(kategoria.Name, toUserId);

            CategoryController._category.Add(nowaKategoria);

            foreach (var fiszka in fiszki)
            {
                var skopiowanaFiszka = new Flashcard(fiszka.Question, fiszka.Answer, nowaKategoria.Id, Guid.NewGuid(), toUserId);

                _fiszki.Add(skopiowanaFiszka);
            }
        }
Пример #3
0
 public ActionResult AddFlashcard(string name)
 {
     if (string.IsNullOrWhiteSpace(name))
     {
         AddError("Flashcard name is empty!");
     }
     else
     {
         name = name.ToLower();
         var flash = unit.FlashcardRepository.FirstOrDefault(f => f.Name.ToLower() == name);
         if (flash != null)
         {
             AddError("Flashcard with this name exists!");
         }
         else
         {
             flash = new Flashcard()
             {
                 Name = name.FirstUpper()
             };
             unit.FlashcardRepository.Add(flash);
             unit.FlashcardRepository.SaveChanges();
             // return EditFlashcard(flash.ID);
             return(RedirectToAction("EditFlashcard", "Management", new { flashcardID = flash.ID, languageSymbol = (string)null }));
         }
     }
     return(RedirectToAction(nameof(Index)));
 }
        public void FromTabSeparatedValues_WhenGivenRabbitThenNewLine_ShouldNotCrashButSetBackToEmptyString()
        {
            Flashcard flashcard = Flashcard.FromTabSeparatedValues("rabbit\n");
            string    result    = flashcard.ToString();

            Assert.That(result, Is.EqualTo("rabbit | "));
        }
Пример #5
0
        [HttpPut("UpdateFlashcard")] // PUT api/flashcards/updateflashcard
        public Boolean UpdateFlashcard([FromBody] Flashcard flashcard)
        {
            if (flashcard != null)
            {
                DBConnect  db     = new DBConnect();
                SqlCommand sqlCmd = new SqlCommand();

                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.CommandText = "TP_UpdateFlashcard";
                sqlCmd.Parameters.AddWithValue("@FlashcardID", flashcard.FlashcardID);
                sqlCmd.Parameters.AddWithValue("@FlashcardSet", flashcard.FlashcardSet);
                sqlCmd.Parameters.AddWithValue("@FlashcardSubject", flashcard.FlashcardSubject);
                sqlCmd.Parameters.AddWithValue("@FlashcardQuestion", flashcard.FlashcardQuestion);
                sqlCmd.Parameters.AddWithValue("@FlashcardAnswer", flashcard.FlashcardAnswer);
                sqlCmd.Parameters.AddWithValue("@FlashcardImage", flashcard.FlashcardImage);
                sqlCmd.Parameters.AddWithValue("@FlashcardUsername", flashcard.FlashcardUsername);

                int retval = db.DoUpdateUsingCmdObj(sqlCmd);
                if (retval > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
    /// <summary>
    /// Loads a new card and answer choices onto the tray. Choices consist of the answer to the card, and two randomly chosen answers from the other cards.
    /// </summary>
    /// <param name="c">Flashcard to load.</param>
    public void NewCard(Flashcard c)
    {
        choices.Clear();
        choicePool.Clear();
        for (int i = 0; i < currentFlashcardList.Count; i++)
        {
            if (currentFlashcardList[i] != c)
            {
                choicePool.Add(currentFlashcardList [i].definition);
            }
        }
        r = Random.Range(0, choicePool.Count);
        choices.Add(c.definition);

        choices.Add(choicePool[r]);

        choicePool.RemoveAt(r);
        r = Random.Range(0, choicePool.Count);

        choices.Add(choicePool[r]);

        r = Random.Range(0, choices.Count);

        //TODO: better shuffle choices

        swapChoice  = choices [0];
        choices [0] = choices [r];
        choices [r] = swapChoice;

        cardTextMesh.text    = c.term;
        choice0TextMesh.text = choices[0];
        choice1TextMesh.text = choices[1];
        choice2TextMesh.text = choices[2];
        currentCard          = c;
    }
Пример #7
0
    public void UpdateMostMissedCards(Flashcard toAdd)
    {
        if (!mostMissedCards.Contains(toAdd))
        {
            mostMissedCards.Add(toAdd);
        }
        //sorts missed flashcard list
        for (int i = 0; i < mostMissedCards.Count; i++)
        {
            for (int j = 0; j < mostMissedCards.Count - 1; j++)
            {
                if (mostMissedCards[j].misses < mostMissedCards[j + 1].misses)
                {
                    temp = mostMissedCards[j + 1];
                    mostMissedCards[j + 1] = mostMissedCards[j];
                    mostMissedCards[j]     = temp;
                }
            }
        }

        //trims the list down to the designated max length
        while (mostMissedCards.Count > mostMissedCardsMaxLength)
        {
            mostMissedCards.RemoveAt(mostMissedCards.Count - 1);
        }
    }
Пример #8
0
        public async Task <Flashcard> Create(int lessonId, Flashcard flashcard)
        {
            var lesson = _context.Lessons.FirstOrDefault(x => x.Id == lessonId);

            if (lesson == null)
            {
                _logger.LogWarning($"Lesson with given id { lessonId } does not exists");
                throw new LessonNotFoundException();
            }

            try
            {
                flashcard.DateCreated  = DateTime.Now;
                flashcard.DateModified = DateTime.Now;
                flashcard.LessonId     = lessonId;
                _context.Flashcards.Add(flashcard);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "An error occurred during add new flashcard to lesson");
                return(null);
            }

            return(flashcard);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Question,Answer,Catagory")] Flashcard flashcard)
        {
            if (id != flashcard.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(flashcard);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FlashcardExists(flashcard.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(flashcard));
        }
        public void FromTabSeparatedValues_WhenGivenTurtleThenTabThenFoxThenNewLine_ShouldHaveGoodToString()
        {
            Flashcard flashcard = Flashcard.FromTabSeparatedValues("turtle\tfox\n");
            string    result    = flashcard.ToString();

            Assert.That(result, Is.EqualTo("turtle | fox"));
        }
Пример #11
0
        public ActionResult Edit(int id)
        {
            //指定したidの値を取得
            Flashcard flashcards = db.Flashcards.Find(id);

            return(View(flashcards));
        }
        public void TabSeparatedValues_WhenBackAndFrontAreEmpty_ReturnsATabThenANewLine()
        {
            Flashcard flashcard = new Flashcard(string.Empty, string.Empty);
            string    result    = flashcard.TabSeparatedValues();

            Assert.That(result, Is.EqualTo("\t\n"));
        }
        public void TabSeparatedValues_WhenFrontIsTurtleAndBackIsFox_ReturnsTurtleThenATabThenFoxThenANewLine()
        {
            Flashcard flashcard = new Flashcard("turtle", "fox");
            string    result    = flashcard.TabSeparatedValues();

            Assert.That(result, Is.EqualTo("turtle\tfox\n"));
        }
        public void ShowBack_WhenBackSideIsAnEmptyString_ReturnsEmptyString()
        {
            Flashcard flashcard = new Flashcard("wh", string.Empty);
            string    result    = flashcard.ShowBack();

            Assert.That(result, Is.EqualTo(string.Empty));
        }
        public void ShowBack_WhenTheBackSideIsFive_ReturnsFive()
        {
            Flashcard flashcard = new Flashcard("", "five");
            string    result    = flashcard.ShowBack();

            Assert.That(result, Is.EqualTo("five"));
        }
        public void ShowFront_WhenTheFrontSideIsThree_ReturnsThree()
        {
            Flashcard flashcard = new Flashcard("three", "h");
            string    result    = flashcard.ShowFront();

            Assert.That(result, Is.EqualTo("three"));
        }
Пример #17
0
        [HttpDelete("DeleteSetOfFlashcards")] // route: DELETE api/flashcards/deleteSetOfflashcards
        public Boolean DeleteSetOfFlashcards([FromBody] Flashcard flashcard)
        {
            if (flashcard != null)
            {
                DBConnect  db     = new DBConnect();
                SqlCommand sqlCmd = new SqlCommand();

                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.CommandText = "TP_DeleteSetOfFlashcards";
                sqlCmd.Parameters.AddWithValue("@FlashcardSet", flashcard.FlashcardSet);

                int retval = db.DoUpdateUsingCmdObj(sqlCmd);
                if (retval > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
        public void FromTabSeparatedValues_WhenGivenRabbitThenTabThenSnailThenNewLine_ShouldHaveGoodToString()
        {
            Flashcard flashcard = Flashcard.FromTabSeparatedValues("rabbit\tsnail\n");
            string    result    = flashcard.ToString();

            Assert.That(result, Is.EqualTo("rabbit | snail"));
        }
Пример #19
0
        public List <Flashcard> GetFlashcardSet(String flashcard_set)
        {
            DBConnect  db     = new DBConnect();
            SqlCommand sqlCmd = new SqlCommand();

            sqlCmd.CommandType = CommandType.StoredProcedure;
            sqlCmd.CommandText = "TP_GetFlashcardSet";
            sqlCmd.Parameters.AddWithValue("FlashcardSet", flashcard_set);

            DataSet ds = db.GetDataSetUsingCmdObj(sqlCmd);

            List <Flashcard> set = new List <Flashcard>();
            Flashcard        flashcard;

            foreach (DataRow record in ds.Tables[0].Rows)
            {
                flashcard                   = new Flashcard();
                flashcard.FlashcardID       = int.Parse(record["Flashcard_ID"].ToString());
                flashcard.FlashcardSet      = record["Flashcard_Set"].ToString();
                flashcard.FlashcardSubject  = record["Subject"].ToString();
                flashcard.FlashcardQuestion = record["Question"].ToString();
                flashcard.FlashcardAnswer   = record["Answer"].ToString();
                flashcard.FlashcardImage    = record["Image"].ToString();
                flashcard.FlashcardUsername = record["Username"].ToString();
                set.Add(flashcard);
            }
            return(set);
        }
Пример #20
0
 private static void EnsureFlashcard(Flashcard flashcard)
 {
     if (flashcard == null)
     {
         throw new ArgumentException(nameof(flashcard));
     }
 }
        /// <summary>
        /// Swaps two Flashcard objects in the list box on the window via their index numbers.
        /// </summary>
        /// <param name="index1">The index in the list box to be swapped with index #2.</param>
        /// <param name="index2">The index in the list box to be swapped with index #1.</param>
        private void SwapFlashcards(int index1, int index2)
        {
            Flashcard tempFlashcard = (Flashcard)flashcardsSetListBox.Items[index1];

            flashcardsSetListBox.Items[index1] = flashcardsSetListBox.Items[index2];
            flashcardsSetListBox.Items[index2] = tempFlashcard;
        }
Пример #22
0
        public async Task <IActionResult> PostFlashcard([FromBody] Flashcard flashcard)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Flashcards.Add(flashcard);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (FlashcardExists(flashcard.Id))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }
            return(CreatedAtAction("GetFlashcards", new { id = flashcard.Id }, flashcard));
        }
Пример #23
0
        [HttpGet("GetFlashcardByID/{ID}")] // route: api/flashcards/getflashcardbyid/0
        public Flashcard GetFlashcardByID(int id)
        {
            DBConnect  db     = new DBConnect();
            SqlCommand sqlCmd = new SqlCommand();

            sqlCmd.CommandType = CommandType.StoredProcedure;
            sqlCmd.CommandText = "TP_GetFlashcardByID";
            sqlCmd.Parameters.AddWithValue("ID", id);

            DataSet   ds = db.GetDataSetUsingCmdObj(sqlCmd);
            DataRow   record;
            Flashcard flashcard = new Flashcard();

            if (ds.Tables[0].Rows.Count > 0)
            {
                record = ds.Tables[0].Rows[0];
                flashcard.FlashcardID       = int.Parse(record["Flashcard_ID"].ToString());
                flashcard.FlashcardSet      = record["Flashcard_Set"].ToString();
                flashcard.FlashcardSubject  = record["Subject"].ToString();
                flashcard.FlashcardQuestion = record["Question"].ToString();
                flashcard.FlashcardAnswer   = record["Answer"].ToString();
                flashcard.FlashcardImage    = record["Image"].ToString();
                flashcard.FlashcardUsername = record["Username"].ToString();
            }
            return(flashcard);
        }
Пример #24
0
        public async Task <IActionResult> PutFlashcard(string id, Flashcard flashcard)
        {
            if (id != flashcard.Flashcardid)
            {
                return(BadRequest());
            }

            _context.Entry(flashcard).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FlashcardExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        /// <summary>
        /// Updates the UI area where the user can interact with the flashcard set.
        /// </summary>
        private void UpdateFlashcardUI()
        {
            UpdateProgressText();
            ToggleNavigationButtons();
            ToggleUnloadCurrentSetButton();

            if (currentFlashcardSet == null || currentFlashcardSet.FlashcardsList.Count == 0) // If no flashcard is loaded, set the cursor for the flashcard container to the "No" cursor
            {
                flashcardContainer.Cursor = Cursors.No;
                setTitle.Text             = "Load a set to start studying...";
                flashcardText.Text        = "";

                return;
            }
            else // Set the cursor to "Hand" if a flashcard set is loaded
            {
                flashcardContainer.Cursor = Cursors.Hand;
            }

            setTitle.Text = currentFlashcardSet.SetName;

            // Update the flashcard text on the GUI depending on which side is visible
            Flashcard currentFlashcard = currentFlashcardSet.FlashcardsList[flashcardsListCurrentIndex];

            flashcardText.Text       = (currentFlashcardState == FlashcardState.Term) ? currentFlashcard.Term : currentFlashcard.Definition;
            flashcardText.FontWeight = (currentFlashcardState == FlashcardState.Term) ? FontWeights.Bold : FontWeights.Normal; // Definition is bold while term is normal font weight
        }
Пример #26
0
 public void Edit([FromBody] Flashcard fc)
 {
     if (ModelState.IsValid)
     {
         _flashcard.UpdateFlashCard(fc);
     }
 }
Пример #27
0
 public void Create([FromBody] Flashcard fc)
 {
     if (ModelState.IsValid)
     {
         _flashcard.AddFlashCard(fc);
     }
 }
Пример #28
0
        public ActionResult EditCard(int id)
        {
            Flashcard card = new Flashcard {
                Id = id
            };

            return(View("Index", card));
        }
Пример #29
0
 public FlashcardDto(Flashcard flashcard)
 {
     Id               = flashcard.Id;
     Key              = flashcard.Key;
     Value            = flashcard.Value;
     KeyDescription   = flashcard.KeyDescription;
     ValueDescription = flashcard.ValueDescription;
 }
Пример #30
0
        public async Task <bool> UpdateFlashcard(Flashcard flashcard, string deckId, CancellationTokenSource cts = null)
        {
            string url = String.Format(_resources["FlashcardUpdateUrl"].ToString(), deckId, flashcard.Id);

            return(await UpdateHelper(url,
                                      new { question = flashcard.Question, answer = flashcard.Answer, isHidden = flashcard.IsHidden },
                                      cts));
        }