public ActionResult Create(string bookTitle, string bookAuthor) { if (BookClass.CheckBookExistByTitle(bookTitle) == false && AuthorClass.CheckAuthorExistByName(bookAuthor) == false) { BookClass.Save(bookTitle); AuthorClass.Save(bookAuthor); int bookId = BookClass.GetBookByTitle(bookTitle).GetId(); int authorId = (AuthorClass.GetAuthorByName(bookAuthor)).GetId(); JoinBookAuthorClass.Save(authorId, bookId); int initial = 1; CopiesClass.Save(bookId, initial, initial); return(RedirectToAction("New")); } else if (BookClass.CheckBookExistByTitle(bookTitle) == true && AuthorClass.CheckAuthorExistByName(bookAuthor) == true) { int bookId = BookClass.GetBookByTitle(bookTitle).GetId(); int amount = CopiesClass.GetAmountByBookId(bookId); int totalAmount = CopiesClass.GetTotalByBookId(bookId); totalAmount++; amount++; CopiesClass.Update(bookId, amount); CopiesClass.UpdateTotal(bookId, totalAmount); return(RedirectToAction("New")); } else { BookClass.Save(bookTitle); int bookId = BookClass.GetBookByTitle(bookTitle).GetId(); int authorId = (AuthorClass.GetAuthorByName(bookAuthor)).GetId(); JoinBookAuthorClass.Save(authorId, bookId); int initial = 1; CopiesClass.Save(bookId, initial, initial); return(RedirectToAction("New")); } }
public CreateBlogModel() { AuthorClass a = new AuthorClass() { First_Name = "Thomas", Last_Name = "Keigh", Email = "*****@*****.**", }; AuthorClass b = new AuthorClass() { First_Name = "Boris", Last_Name = "Smart", Email = "*****@*****.**", }; AuthorClass c = new AuthorClass() { First_Name = "McGill", Last_Name = "Trent", Email = "*****@*****.**", }; Authors.Add(a); Authors.Add(b); Authors.Add(c); }
} /**/ public CreateBlogModel() { AuthorClass author1 = new AuthorClass() { GivenName = "Steve", LastName = "Rogers", Email = "*****@*****.**", WebSite = "CaptainAmerica.com", Country = "Canada", Province = "Ontario", PostalCode = "2R4 6Y7" }; AuthorClass author2 = new AuthorClass() { GivenName = "Tony", LastName = "Stark", Email = "*****@*****.**", WebSite = "ImIronMan.com", Country = "Canada", Province = "Ontario", PostalCode = "1T5 9Y8" }; AuthorClass author3 = new AuthorClass() { GivenName = "Natasha", LastName = "Rommanov", Email = "*****@*****.**", WebSite = "BlackWidow.com", Country = "Canada", Province = "Ontario", PostalCode = "4g4 8h8" }; AuthorClass author4 = new AuthorClass() { GivenName = "Bruce", LastName = "Banner", Email = "*****@*****.**", WebSite = "Hulk.com", Country = "Canada", Province = "Ontario", PostalCode = "4T6 7G8" }; AuthorClass author5 = new AuthorClass() { GivenName = "Thor", LastName = "Son of Odin", Email = "*****@*****.**", WebSite = "Thor.com", Country = "Canada", Province = "Ontario", PostalCode = "9Y7 9L3" }; authorClasses.Add(author1); authorClasses.Add(author2); authorClasses.Add(author3); authorClasses.Add(author4); authorClasses.Add(author5); }
public ActionResult ShowAuthor(int id) { Dictionary <string, object> dictionary = new Dictionary <string, object> { }; List <BookClass> books = BookClass.GetBooksByAuthorId(id); AuthorClass author = AuthorClass.GetAuthorById(id); dictionary.Add("books", books); dictionary.Add("author", author); return(View(dictionary)); }
public ActionResult SearchAuthor(string authorNameSearch) { AuthorClass author = AuthorClass.GetAuthorByName(authorNameSearch); int id = author.GetId(); Dictionary <string, object> dictionary = new Dictionary <string, object> { }; List <BookClass> books = BookClass.GetBooksByAuthorId(id); dictionary.Add("books", books); dictionary.Add("author", author); return(View("ShowAuthor", dictionary)); }
public ActionResult ShowBook(int id) { Dictionary <string, object> dictionary = new Dictionary <string, object> { }; BookClass newBook = BookClass.GetBookById(id); AuthorClass newAuthor = AuthorClass.GetAuthorByBookId(id); int amount = CopiesClass.GetAmountByBookId(id); int total = CopiesClass.GetTotalByBookId(id); CopiesClass copies = new CopiesClass(id, amount, total); dictionary.Add("book", newBook); dictionary.Add("author", newAuthor); dictionary.Add("copies", copies); return(View("ShowBook", dictionary)); }
public CreateBlogModel() { AuthorClass jack = new AuthorClass() { FirstName = "Jack", LastName = "David", BirthDate = new DateTime(1996, 10, 20), Email = "*****@*****.**", WebsiteAddress = "www.david.com", TelephoneNumber = "023820983420", Country = "UK", Province = "London", PostalCode = "44600" }; AuthorClass numan = new AuthorClass() { FirstName = "Numan", LastName = "Laka", BirthDate = new DateTime(1996, 10, 20), Email = "*****@*****.**", WebsiteAddress = "www.david.com", TelephoneNumber = "023820983420", Country = "UK", Province = "London", PostalCode = "LO100" }; AuthorClass laeman = new AuthorClass() { FirstName = "Layman", LastName = "Maka", BirthDate = new DateTime(1996, 10, 20), Email = "*****@*****.**", WebsiteAddress = "www.david.com", TelephoneNumber = "023820983420", Country = "UK", Province = "London", PostalCode = "41C70" }; AuthorLists.Add(jack); AuthorLists.Add(numan); AuthorLists.Add(laeman); }
// Order List of Authors based on the times they appear and return it truncated private static Dictionary <string, AuthorClass> OrderRanking(List <Authors> authorList) { try { // Use dictionary to store information <AuthorName, AuthorClass> var map = new Dictionary <string, AuthorClass>(); // Give a score to the author based on the times they appear for (int i = 0; i < authorList.Count; ++i) { Authors authors = authorList[i]; for (int j = 0; j < authors.Author.Count; ++j) { string authorName = authors.Author[j].Text; if (map.ContainsKey(authorName)) // Author already inside the dictionary { AuthorClass author = map.GetValueOrDefault(authorName); author.IncreaseScore(); author.SetPublicationYear(authors.Author[j].LastYear); author.AddVenue(authors.Author[j].Venue); } else // New Author { authors.Author[j].Score = 1; authors.Author[j].AddVenue(authors.Author[j].Venue); map.Add(authorName, authors.Author[j]); } } } return(map); } catch (Exception) { return(null); } }
private void bt_import_Purchase_Click(object sender, EventArgs e) { if (ofd_load_Purchase.ShowDialog() == DialogResult.OK)//Вызываем диалог выбора файла и проверяем, что полльзователь выбрал файл { DataTable table; if (ExcelClass.loadExcel(ofd_load_Purchase.FileName, out table))//Если загрузка данных(ИмяФайла,ТаблицаСРезультатом) прошел успешно { PurchaseListClass purchaseList = new PurchaseListClass { datePurchase = DateTime.Now }; foreach (DataRow row in table.Rows)//перебираем полученные строки { StringBuilder builder = new StringBuilder(); //Проверка на наличие такого типа литературы с такими данными string typename = row["Тип"].ToString(); TypeClass type = DbModel.init().Types.Where(t => t.type == typename).FirstOrDefault(); //Если книга не существует, то выдается сообщение об ошибке if (type == null) { type = new TypeClass { type = Convert.ToString(typename) }; } //проверка на наличие авторов в базе List <AuthorClass> authors = new List <AuthorClass>(); //разделение авторов сначала на двух разных, а затем каждого на инициалы string FIO_Authors = Convert.ToString(row["Автор"]); string[] split_Author = FIO_Authors.Split(','); //перебираем инициаллы foreach (string strF_IO in split_Author) { string[] F_I_O = strF_IO.Split(' ', '.'); AuthorClass author = null; string fam = F_I_O[0], name = F_I_O[1], otch = F_I_O[2]; //сравниваем инициалы на наличие соотношениий в базе. Инициалы И.О. сверяются с первыми бууквами значений. author = DbModel.init().Authors.Where(a => a.family_name.StartsWith(fam) && a.first_name.StartsWith(name) && a.middle_name.StartsWith(otch)).FirstOrDefault(); //если такой автор в базе найден, то..... if (author != null) { //в класс (таблицу) автора добавляется новой значение authors.Add(author); } else { //если данные не найдены, то открывается форма "AddAvtor" для того, чтобы пользователь расшифровал значение. //От формы данные добавляются в базу AddAvtorForm addAvtor = new AddAvtorForm(fam, name, otch); if (addAvtor.ShowDialog() != DialogResult.OK) { builder.AppendLine(String.Format("Fio author {0} not found!", strF_IO)); } else { author = addAvtor.GetAuthor(); authors.Add(author); } } } //Проверка на наличие издательства с такими данными. !!!!!!!!!Действия схожи с данными об авторах!!!!!!! List <PublisherClass> publishers = new List <PublisherClass>(); string publicher_str = Convert.ToString(row["Издательство"]); string[] split_publisher = publicher_str.Split(':'); PublisherClass publisher = null; string publisher_name = split_publisher[1], publisher_city = split_publisher[0]; publisher = DbModel.init().Publishers.Where(p => p.city.StartsWith(publisher_city) && p.name.StartsWith(publisher_name)).FirstOrDefault(); if (publisher != null) { publishers.Add(publisher); } else { AddPublisherForm addPublisher = new AddPublisherForm(publisher_city, publisher_name); if (addPublisher.ShowDialog() != DialogResult.OK) { builder.AppendLine(String.Format("Издательство не найдено!", publicher_str)); } else { publisher = addPublisher.GetPublisher(); publishers.Add(publisher); } } //Проверка на наличие данной литературы BookClass book = null; string bookname = row["Название"].ToString(); int? bookclassnum = null; try { bookclassnum = Convert.ToInt32(row["Класс"]); } catch { } book = DbModel.init().Books.Include(b => b.publisher).Include(b => b.type).Include(b => b.Authors) .Where(b => b.classnum == bookclassnum && b.name_book == bookname && b.publisher.idPublisher == publisher.idPublisher && b.type.idType == type.idType ).FirstOrDefault(); if (book == null) { AddBookForm addBook = new AddBookForm(bookclassnum, bookname, publisher, type, authors); if (addBook.ShowDialog() != DialogResult.OK) { builder.AppendLine(String.Format("Литература не найдена!", bookname)); } book = addBook.GetBook(); } int Litheraturecount = Convert.ToInt32(row["Количество"]); purchaseList.purchaseAccountings.Add( new PurchaseAccountingClass { count = Litheraturecount, price = Convert.ToDecimal(row["Цена"]), literatureTurnover = LiteratureTurnoverClass.addNewLitherature(book, Litheraturecount) } ); } AddPurchaseForm addPurchase = new AddPurchaseForm(purchaseList); addPurchase.ShowDialog(); MessageBox.Show("Boooozhe! ONO RABOTAET!"); } } }
public ActionResult ShowAuthors() { List <AuthorClass> allAuthors = AuthorClass.GetAll(); return(View(allAuthors)); }
// Get DBLP ranking for a determined number of years private static Dictionary <string, AuthorClass> GetDblpRanking(string venue, int minYear, int maxYear, string author, string location, string locationSearch) { if (ValidateInput(minYear, maxYear)) { List <Authors> authorList = new List <Authors>(); List <Authors> copyList = new List <Authors>(); string bestVenue = ""; int bestScore = 0; int bestPosition = int.MaxValue; if (venue.Equals("GSR")) { List <Venue> venueList = JsonFileVenueService.GetVenues().ToList(); foreach (Venue v in venueList) { // Clear copy list for every new venue copyList.Clear(); for (int i = minYear; i <= maxYear; i++) { // Copy list now has all the info about a venue copyList.AddRange(AddListByYear(v.Key, i)); } //Add values of venue to author list authorList.AddRange(copyList); // If we require the best venue for the author if (author != null) { List <AuthorClass> orderedList = FilterMap(OrderRanking(copyList), int.MaxValue, 0, location, locationSearch); AuthorClass authorClass = DataHelper.GetAuthorByName(author, orderedList); if (authorClass != null) { if (authorClass.Position <= bestPosition && authorClass.Score > bestScore) { bestScore = authorClass.Score; bestPosition = authorClass.Position; bestVenue = v.Name; } } } } } else { for (int i = minYear; i <= maxYear; i++) { authorList.AddRange(AddListByYear(venue, i)); } } // If we require the best venue for the author if (author != null && bestScore != 0) { AuthorClass bestAuthorClass = new AuthorClass() { Text = "BestVenue", Score = bestScore, FirstYear = minYear, LastYear = maxYear, Venue = bestVenue }; List <AuthorClass> authorClassList = new List <AuthorClass>() { bestAuthorClass }; Authors bestAuthors = new Authors(authorClassList); authorList.Add(bestAuthors); } return(OrderRanking(authorList)); } return(null); }
// Return a list of the authors extracted from a query by year private static List <Authors> AddListByYear(string venue, int year) { // Create new list List <Authors> authorList = new List <Authors>(); try { // Parse year to string string yearToString = year.ToString(); // Build Query string query = QueryBuilder.BuildQueryVenueYear(venue, yearToString); // Send request string response = SendRequest(query); // Parse response into JSON JObject search = JObject.Parse(response); // Get JSON result objects into a list List <JToken> results = search["result"]["hits"]["hit"].Children().ToList(); // Serialize JSON results into .NET objects foreach (JToken result in results) { try { string authorString = result["info"]["authors"].ToString(); int numberAuthors = Regex.Matches(authorString, "text").Count; if (numberAuthors == 1) { string authorClassString = result["info"]["authors"]["author"].ToString(); AuthorClass author = JsonConvert.DeserializeObject <AuthorClass>(authorClassString); // Set año de publicacion para un autor author.SetPublicationYear(year); // Set venue del autor author.Venue = venue; List <AuthorClass> tempAuthorList = new List <AuthorClass>() { author }; authorList.Add(new Authors(tempAuthorList)); } else { Authors authors = JsonConvert.DeserializeObject <Authors>(authorString); // Set año de la publicacion y venue para todos los autores de la publicacion foreach (AuthorClass au in authors.Author) { au.SetPublicationYear(year); au.Venue = venue; } authorList.Add(authors); } }catch (Exception) { continue; } } return(authorList); } catch (Exception) { return(authorList); } }