public IActionResult EditCard(string flashcardId)
        {
            var flashcard          = _flashcardRepository.GetFlashcardById(flashcardId);
            var flashcardViewModel = new FlashcardViewModel
            {
                FlashcardFolderId = flashcard.FlashcardFolderId,
                FrontText         = flashcard.FrontText,
                BackText          = flashcard.BackText,
                Id = flashcardId
            };

            return(View(flashcardViewModel));
        }
        public IActionResult EditCard(FlashcardViewModel flashcardViewModel)
        {
            var newCard = new Flashcard
            {
                Id                = flashcardViewModel.Id,
                FrontText         = flashcardViewModel.FrontText,
                BackText          = flashcardViewModel.BackText,
                FlashcardFolderId = flashcardViewModel.FlashcardFolderId
            };
            var success = _flashcardRepository.UpdateFlashcard(newCard);

            if (success)
            {
                TempData["UserMessage"] = "Card Updated Successfully";
            }
            else
            {
                TempData["ErrorMessage"] = "We weren't able to update your card.  Please try again in a few minutes.";
            }
            return(RedirectToAction("ViewCards", new { flashcardFolderId = flashcardViewModel.FlashcardFolderId }));
        }
        public IActionResult CreateFlashcard(FlashcardViewModel flashcardModel, IFormFile file)
        {
            //Check if picture is selected
            if (file == null)
            {
                ModelState.AddModelError("", "Error: Picture is not selected! Flashcard could not be created!");
                return(View());
            }

            if (ModelState.IsValid)
            {
                //Set picture URL
                var PictureURL = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\images\flashcards", file.FileName);

                //Copy file to server/disk
                using (var stream = new FileStream(PictureURL, FileMode.Create))
                {
                    file.CopyTo(stream);
                }

                //Record flashcard details
                Flashcard flashcard = new Flashcard()
                {
                    Name       = flashcardModel.Name,
                    Date       = flashcardModel.Date,
                    PictureURL = "/images/flashcards/" + file.FileName //Get picture URL
                };

                //Save new flashcard to the database
                _repositoryWrapper.Flashcard.Create(flashcard);
                _repositoryWrapper.Flashcard.Save();

                //Done
                return(Redirect("/Masterclass/Index"));
            }

            ModelState.AddModelError("", "Error: Flashcard could not be created!");
            return(View());
        }
        public IActionResult AddCard(FlashcardViewModel flashcardViewModel)
        {
            if (ModelState.IsValid)
            {
                var flashcard = new Flashcard
                {
                    FrontText         = flashcardViewModel.FrontText,
                    BackText          = flashcardViewModel.BackText,
                    FlashcardFolderId = flashcardViewModel.FlashcardFolderId,
                    Id = Guid.NewGuid().ToString()
                };


                var success = _folderRepository.AddFlashcard(flashcard);
                if (success)
                {
                    TempData["UserMessage"] = "Card added successfully";
                    return(RedirectToAction("AddCard", new { flashcardFolderId = flashcard.FlashcardFolderId }));
                }
            }
            TempData["ErrorMessage"] = "Unable to add card to folder.  Please try again.";
            return(RedirectToAction("AddCard", new { flashcardFolderId = flashcardViewModel.FlashcardFolderId }));
        }