//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 DeleteUnAttachedFlashCard()
        {
            var flashCard = GetFlashCard();

            using (var repo = new FlashCardRepository())
            {
            }
        }
Exemplo n.º 3
0
 void DeleteSelectedFlashCard()
 {
     using (var repo = new FlashCardRepository())
     {
         repo.Delete(selectedFlashCard.Id);
     }
     SelectedFlashCard = null;
     UpdateFlashCardPreview();
 }
        public bool AddFlashCard(FlashCard flashCard)
        {
            bool success = false;

            using (var repo = new FlashCardRepository())
            {
                repo.Add(flashCard);
                success = true;
            }
            return(success);
        }
        public FlashCard GetFlashCard(int id)
        {
            var flashCard = new FlashCard();

            using (var repo = new FlashCardRepository())
            {
                flashCard = repo.GetOne(id);
                repo.Context.Entry(flashCard).Collection(x => x.Tags).Load();
                repo.Context.Entry(flashCard).Collection(x => x.TextAnserws).Load();
                repo.Context.Entry(flashCard).Collection(x => x.FileAnserws).Load();
                repo.Context.Entry(flashCard).Reference(x => x.FlashCardData).Load();
            }
            return(flashCard);
        }
        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();
            }
        }
Exemplo n.º 7
0
        void EditSelectedFlashCard()
        {
            using (var repo = new FlashCardRepository())
            {
                FlashCardFactory    flashCardFactory    = new FlashCardFactory();
                FlashCardTagFactory flashCardTagFactory = new FlashCardTagFactory();
                var addFlashCardWindow = new FlashCardDetailsWindow(
                    new FlashCardDetails(flashCardFactory.GetFlashCard(selectedFlashCard.Id), flashCardTagFactory.GetAllTags())
                    );
                addFlashCardWindow.ShowDialog();

                if (addFlashCardWindow.addFlashCard.Save)
                {
                    repo.Save(addFlashCardWindow.addFlashCard.ReturnedFlashCard);
                }
            }
            UpdateFlashCardPreview();
        }
        public void ModifyTextAnserw()
        {
            var flashCard = GetFlashCard();

            flashCard.TextAnserws.Add(new TextAnserw {
                Text = "ModifyTextAnserw", Annotation = "a"
            });
            using (var repo = new FlashCardRepository())
            {
                //repo.Context.FlashCards.Attach(flashCard);
                //var tempFlashCard = repo.GetAll().Find(x => x.Title == flashCard.Title);
                //tempFlashCard = flashCard;
                //repo.Context.Entry(tempFlashCard).State = EntityState.Modified;
                //repo.Save(tempFlashCard);
                repo.Context.Entry(flashCard).State             = EntityState.Modified;
                repo.Context.Entry(flashCard.TextAnserws).State = EntityState.Modified;
                repo.Context.SaveChanges();
            }
        }
        public void AddDetachedFlashCard1()
        {
            var flashCard = GetFlashCard();

            using (var repo = new FlashCardRepository())
            {
                repo.Context.Entry(flashCard).State = EntityState.Added;
                //var existingTags = repo.GetAll().ToList().Select(x => x.Tags).ToList();
                //var existingTagsStrings = existingTags.Except(flashCard.Tags);
                List <string> tagsInDb = new List <string>();
                using (var repoTag = new TagRepository())
                {
                    tagsInDb = repoTag.GetAll().Select(x => x.Tag1).ToList();
                }
                var pendingTags = new List <string>();
                pendingTags = flashCard.Tags.Select(x => x.Tag1).ToList();
                var notExistingTags = pendingTags.Where(x => !tagsInDb.Any());
                var tagsToBeAdded   = new List <Tag>();
                foreach (var item in notExistingTags)
                {
                    tagsToBeAdded.Add(new Tag {
                        Tag1 = item
                    });                                         //dodac flashcard?
                }
                flashCard.Tags.ToList().ForEach(x => repo.Context.Tags.AddRange(tagsToBeAdded));
                //modyfikujemy istniejace
                var tagsToBeModified = new List <string>();
                tagsToBeModified = pendingTags.Where(x => !tagsToBeAdded.Any()).ToList();
                var tagsToModify = new List <Tag>();
                foreach (var item in tagsToBeModified)
                {
                    tagsToModify.Add(new Tag {
                        Tag1 = item
                    });                                         //dodac flashcard?
                }
                foreach (var item in flashCard.Tags)
                {
                    repo.Context.Entry(item).State = EntityState.Modified;
                }
                repo.Context.SaveChanges();
            }
        }
Exemplo n.º 10
0
        void StartFlashCardRecallCommand()
        {
            //zablokowac mozliwosc zmiany danych
            //2 przyciski na dole - powtorzone poprawnie lub negatywnie
            var           flashCard = new FlashCard();
            List <string> tags      = new List <string>();

            using (var repo = new TagRepository())
            {
                tags = repo.GetAll().Select(x => x.Tag1).Distinct().ToList();
            }
            using (var repo = new FlashCardRepository())
            {
                flashCard = repo.GetOne(selectedFlashCard.Id);
                repo.Context.Entry(flashCard).Collection(x => x.Tags).Load();
                repo.Context.Entry(flashCard).Collection(x => x.TextAnserws).Load();
                repo.Context.Entry(flashCard).Collection(x => x.FileAnserws).Load();
                var addFlashCardWindow = new FlashCardDetailsWindow(new FlashCardDetails(flashCard, tags));
                addFlashCardWindow.ShowDialog();
            }
        }
Exemplo n.º 11
0
 public void DeleteAttachedFlashCard()
 {
     using (var repo = new FlashCardRepository())
     {
         var flashCard = repo.Context.FlashCards.Find(26006);
         //flashCard.Tags.ToList().ForEach(x => repo.Context.Tags.Remove(x));
         //repo.Context.Tags.RemoveRange(flashCard.Tags);
         //repo.Context.Entry(flashCard).State = EntityState.Deleted;
         if (flashCard.FileAnserws.ToList().Count > 0)
         {
             flashCard.FileAnserws.ToList().ForEach(x => repo.Context.FileAnserws.Remove(x));
         }
         if (flashCard.TextAnserws.ToList().Count > 0)
         {
             flashCard.TextAnserws.ToList().ForEach(x => repo.Context.TextAnserws.Remove(x));
         }
         repo.Context.FlashCardDatas.Remove(flashCard.FlashCardData);
         //repo.Context.Tags.ToList().ForEach(x => repo.Context.Tags.Remove(x));
         repo.Context.FlashCards.Remove(flashCard);
         repo.Context.SaveChanges();
     }
 }
Exemplo n.º 12
0
        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();
            }
        }