예제 #1
0
        public Element ToElement()
        {
            AuthorDao autdao = new AuthorDao(cvDb);
            var authors = autdao.GetAuthors();

            Element e = null;

            if (Type == "word")
            {
                Word w = new Word();

                if (string.IsNullOrEmpty(Details1) == false && string.IsNullOrEmpty(Content1) == false)
                {
                    w.Definitions.Add(new Definition()
                    {
                        Id = IdDef1,
                        Content = Content1,
                        Details = Details1,
                        WordId = w.Id
                    });
                }
                if (string.IsNullOrEmpty(Details2) == false && string.IsNullOrEmpty(Content2) == false)
                {
                    w.Definitions.Add(new Definition()
                    {
                        Id = IdDef2,
                        Content = Content2,
                        Details = Details2,
                        WordId = w.Id
                    });
                }
                if (string.IsNullOrEmpty(Details3) == false && string.IsNullOrEmpty(Content3) == false)
                {
                    w.Definitions.Add(new Definition()
                    {
                        Id = IdDef3,
                        Content = Content3,
                        Details = Details3,
                        WordId = w.Id
                    });
                }

                e = w;
            }
            else
            {
                Contrepeterie ctp = new Contrepeterie();

                ctp.Content = Content;
                ctp.Solution = Solution;

                e = ctp;
            }

            e.Author = authors.Where(a => a.Id == AuthorId).FirstOrDefault();
            e.Id = ElementId;
            e.Title = Title;
            e.Date = Date;
            e.FavoriteCount = VoteCount;

            return e;
        }
예제 #2
0
 public ElementViewModel()
 {
     AuthorDao autdao = new AuthorDao(cvDb);
     Authors = autdao.GetAuthors();
 }
예제 #3
0
        public ActionResult Import()
        {
            object results = "Pouet";
            ElementDao dao = new ElementDao(cvDb);
            AuthorDao authDao = new AuthorDao(cvDb);

            List<Author> authors = authDao.GetAuthors();
            List<Element> newWsElementsId = dao.GetAllElements(true).ToList();

            // Appel à l'ancien WS
            OldWSRetriever retriever = new OldWSRetriever();
            bool mergeComplete = false;
            int page = 1;
            int count = 0;

            while (mergeComplete == false)
            {
                List<Element> elements = retriever.GetElements(page);

                if (elements == null || elements.Count == 0)
                {
                    mergeComplete = true;
                }
                else
                {
                    foreach (Element oldE in elements)
                    {
                        if (newWsElementsId.Where(newE => newE.Title.ToLowerInvariant() == oldE.Title.ToLowerInvariant()).Count() == 0)
                        {
                            // Auteur
                            Author aut = authors.Where(a => a.Name.ToLower() == oldE.Author.Name.ToLowerInvariant()).FirstOrDefault();

                            if (aut != null)
                            {
                                oldE.Author = aut;

                                count++;

                                // Ajout
                                if (dao.Create(oldE) == false)
                                {
                                    throw dao.LastException;
                                }
                            }
                        }
                        else
                        {
                            mergeComplete = true;
                            break;
                        }
                    }

                    if (mergeComplete == false)
                    {
                        page++;
                    }
                }
            }

            results = count + " élements ajoutés sur " + page + " pages.";

            return View(results);
        }