public ActionResult CorrectArticle(int ArticleId, string ArticleName, string Author, string TagList, string Year, string Publisher, string Journal, string Note)
 {
     Article a = db.Articles.Find(ArticleId);
     List<string> list = StringToList(TagList);
     List<Tag> lT = new List<Tag>();
     for (int i = 0; i < list.Count; i++)
     {
         Tag t = new Tag { TagName = list[i] };
         //lT.Add(t);
         //db.Tags.Add(t);
         addTag(t);
         db.SaveChanges();
     }
     for (int i = 0; i < list.Count; i++)
     {
         foreach (var t in db.Tags.ToList())
         {
             if (t.TagName == list[i])
             {
                 lT.Add(t);
             }
         }
     }
     a.author = Author;
     a.journal = Journal;
     a.note = Note;
     a.publisher = Publisher;
     a.title = ArticleName;
     a.year = Year;
     a.Tags = lT;
     CreateBibFile(a);
     db.SaveChanges();
     return View("MainPage", db.Articles.ToList());
 }
Example #2
0
        public List<Article> SearchByTag(string tagName)
        {
            int tNumber = 0;
            Tag tag = new Tag();
            foreach (var t in this.Tags)
            {
                if (t.TagName == tagName)
                {
                    tNumber = t.TagId;
                    tag = t;
                }
            }
            Article a = new Article();
            List<Article> list = new List<Article>();
            foreach (var art in this.Articles.ToList())
            {
                /*if (art.Tags.Contains(tag))
                {
                    list.Add(art);
                }*/
                foreach (var t in art.Tags)
                {
                    if (tagName == t.TagName)
                    {
                        list.Add(art);
                    }
                }
            }

            return list;
        }
 public void addTag(Tag tag)
 {
     bool add = true;
     foreach (var t in db.Tags.ToList())
     {
         if (tag.TagName == t.TagName)
             add = false;
     }
     if (add)
     {
         db.Tags.Add(tag);
     }
 }
        public ActionResult Index(IEnumerable<HttpPostedFileBase> fileUpload, string ArticleName, string TagList, 
            string Author, string Year, string Journal, string Publisher, string Note)
        {
            if (ArticleName == "")
            {
                ListsOfStuff list1 = new ListsOfStuff();
                return View(list1);
            }
            if ((DateTime.Now.Year <= Convert.ToInt32(Year)) || (Convert.ToInt32(Year) <= 1500))
            {
                ListsOfStuff list1 = new ListsOfStuff();
                list1.ArticleName = ArticleName;
                list1.Author = Author;
                list1.Journal = Journal;
                list1.Note = Note;
                list1.Publisher = Publisher;
                list1.TagList = TagList;
                list1.wrongDate = true;
                return View(list1);
            }
            foreach (var file in fileUpload)
            {
                string filename = "";
                if (file != null)
                {
                    string allowFormat = "pdf";
                    var fileExt = System.IO.Path.GetExtension(file.FileName).Substring(1);
                    if (fileExt != allowFormat)
                    {
                        ListsOfStuff list1 = new ListsOfStuff();
                        list1.ArticleName = ArticleName;
                        list1.Author = Author;
                        list1.Journal = Journal;
                        list1.Note = Note;
                        list1.Publisher = Publisher;
                        list1.TagList = TagList;
                        list1.Year = Year;
                        list1.wrongFile = true;
                        return View(list1);
                    }
                    //string path = AppDomain.CurrentDomain.BaseDirectory + "UploadedFiles/";
                    filename = System.IO.Path.GetFileName(file.FileName);
                    file.SaveAs(Server.MapPath("~/Files/" + filename));
                }
                List<string> list = StringToList(TagList);
                List<Tag> lT = new List<Tag>();
                for (int i = 0; i < list.Count; i++)
                {
                    Tag t = new Tag { TagName = list[i] };
                    //lT.Add(t);
                    //db.Tags.Add(t);
                    addTag(t);
                    db.SaveChanges();
                }
                for (int i = 0; i < list.Count; i++)
                {
                    foreach(var t in db.Tags.ToList())
                    {
                        if (t.TagName == list[i])
                        {
                            lT.Add(t);
                        }
                    }
                }

                string tt = Request.Form["TypeT"].ToString();
                int tg = Convert.ToInt32(Request.Form["GroupT"].ToString());

                Article a1 = new Article { title = ArticleName, Path = filename, Tags = lT, author = Author, Type = tt,  journal = Journal, note = Note, publisher = Publisher, year = Year, UserName = User.Identity.Name, GroupId = tg };
                db.Articles.Add(a1);
                CreateBibFile(a1);
                db.SaveChanges();
                UsersArticle ua = new UsersArticle { UserName = User.Identity.Name, ArticleId = a1.ArticleId};
                db.UsersArticles.Add(ua);
                db.SaveChanges();
            }

            return RedirectToAction("Finish");
        }