//dodac opcjonalny arguemnt do filtrowania
        public List <FlashCardPreview> FlashCardPreviews()
        {
            var flashCardPreview = new List <FlashCardPreview>();

            using (var flashCardRepository = new FlashCardRepository())
            {
                var allFlashCards = flashCardRepository.GetAll();
                //usunac try
                try
                {
                    for (int i = 0; i < allFlashCards.Count; i++)
                    {
                        //zabezpieczyc sie na wypadek braku danych
                        flashCardPreview.Add(new FlashCardPreview(allFlashCards[i].Id));
                        flashCardPreview.Last().Title        = allFlashCards[i].Title;
                        flashCardPreview.Last().CreationDate = allFlashCards[i].FlashCardData.CreationDate;
                        if (allFlashCards[i].FlashCardData.LastOccurrence != null)
                        {
                            flashCardPreview.Last().LastOccurance = (DateTime)allFlashCards[i].FlashCardData.LastOccurrence;
                        }
                        else
                        {
                            flashCardPreview.Last().LastOccurance = default(DateTime);
                        }
                        var flashCardMemorizer = new FlashCardMemorizer();
                        flashCardRepository.Context.Entry(allFlashCards[i]).Reference(x => x.FlashCardData).Load();
                        int recallVal = flashCardMemorizer.GetRecallValue(allFlashCards[i].FlashCardData);
                        flashCardPreview.Last().RecallVal = recallVal;
                    }
                }
                catch (Exception) { }
            }
            return(flashCardPreview);
        }
        public void Delete()
        {
            var flashCard = GetFlashCard();
            int id;

            using (var repo = new FlashCardRepository())
            {
                var tempFlashCard = repo.GetAll().Find(x => x.Title == flashCard.Title);
                repo.Context.FlashCards.Remove(tempFlashCard);
                var tempTags = tempFlashCard.Tags;
                foreach (var item in tempTags)
                {
                    repo.Context.Tags.Remove(item);
                }
                repo.Context.SaveChanges();
            }
        }
        public void UpdateByDeleteAndAdd()
        {
            var flashCard = GetFlashCard();
            int id;

            using (var repo2 = new FlashCardRepository())
            {
                var tempFlashCard = repo2.GetAll().Find(x => x.Title == flashCard.Title);
                id = tempFlashCard.Id;
                //repo.Delete(tempFlashCard.Id);
                //repo.Context.FlashCards.Remove(tempFlashCard);
                //repo.Context.SaveChanges();

                using (var repo = new FileAnserwRepository())
                {
                    var loop = repo.Context.FileAnserws.Where(n => n.FlashCard.Id == id).ToList();
                    foreach (var item in loop)
                    {
                        repo.Delete(item);
                    }
                    repo.Context.SaveChanges();
                }
                using (var repo = new TextAnserwRepository())
                {
                    var loop = repo.Context.TextAnserws.Where(n => n.FlashCard.Id == id).ToList();
                    foreach (var item in loop)
                    {
                        repo.Delete(item);
                    }
                    repo.Context.SaveChanges();
                }
                using (var repo = new FlashCardDataRepository())
                {
                    var loop = repo.Context.FlashCardDatas.Where(n => n.FlashCard.Id == id).ToList();
                    foreach (var item in loop)
                    {
                        repo.Delete(item);
                    }
                    repo.Context.SaveChanges();
                }
                List <Tag> temp1 = new List <Tag>();
                using (var repo = new FlashCardRepository())
                {
                    //var flashCardsFromDb = repo.GetAll();
                    //FlashCard flashCard2 = flashCardsFromDb.Find(n => n.Id == 14007); //new FlashCard { Id = 13006 };
                    //var loop = repo.Context.FlashCards.Where(n => n.Id == 14007).ToList();
                    //var loop2 = loop.
                    var       flashCardsFromDb = repo.GetAll();
                    FlashCard flashCard2       = flashCardsFromDb.Find(n => n.Id == id);
                    temp1 = flashCard2.Tags.ToList();
                }
                using (var repo = new TagRepository())
                {
                    foreach (var item in temp1)
                    {
                        try
                        {
                            repo.Delete(item);
                        }
                        catch (Exception)
                        {
                        }
                    }
                    //repo.Context.SaveChanges();
                }
                repo2.Context.FlashCards.Remove(tempFlashCard);
                repo2.Context.SaveChanges();
            }
        }