public string CreateBibFile(Article art) { string directory = AppDomain.CurrentDomain.BaseDirectory; string name = art.title + ".bib"; string path = directory + "/BibFiles/" + name; System.IO.StreamWriter textFile = new System.IO.StreamWriter(@path); AddBib(textFile, art); textFile.Close(); return name; }
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"); }
private void AddBib(System.IO.StreamWriter textFile, Article art) { if (art.Type == "Статья") { textFile.WriteLine("@ARTICLE{"); } else if (art.Type == "Книга") { textFile.WriteLine("@BOOK{"); } textFile.WriteLine("author = {" + art.author + "},"); textFile.WriteLine("title = {«" + art.title + "»},"); if (art.publisher != "") { textFile.WriteLine("publisher = {" + art.publisher + "},"); } if (art.journal != "") { textFile.WriteLine("journal = {" + art.journal + "},"); } if (art.year != "") { textFile.WriteLine("year = {" + art.year + "},"); } textFile.WriteLine("note = {" + art.note + "},"); textFile.WriteLine("}"); }
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; }