public TempBook(long iSBN, string title, string language, decimal?price, DateTime?releaseDay, EFDtataAccessLibary.Models.Bokförlag publisher) { ISBN = iSBN; Title = title; Language = language; Price = price.Value; ReleaseDay = releaseDay.Value; Publisher = publisher; Authors = new List <EFDtataAccessLibary.Models.Författare>(); NewAuthors = new List <EFDtataAccessLibary.Models.Författare>(); }
private int SetPublisherComboBox(EFDtataAccessLibary.Models.Bokförlag publischer) { List <EFDtataAccessLibary.Models.Bokförlag> publishers = DataBaseCommand.GetPublishers(); int index = 0; for (int i = 0; i < publishers.Count; i++) { if (publishers[i].Namn.Equals(publischer.Namn)) { break; } else { index += 1; } } return(index); }//Här har jag lärt mig att ALLTID använda numreriskt ID som PK, ALLTID!!!!, Fick göra en abrovinsch här för att få fram en int som skall ändra index:arn i comboboxarna.
public static List <TempBook> GetBooksWAuthor() { List <TempBook> booksWAuthors = new List <TempBook>(); using (var context = new EFDtataAccessLibary.DataAccess.GewertsContext()) { var books = (from Böcker in context.Böckers join Bokförlag in context.Bokförlags on Böcker.BokförlagNamn equals Bokförlag.Namn select new { ISBN = Böcker.Isbn, Title = Böcker.Titel, Language = Böcker.Språk, Price = Böcker.Pris, ReleaseDay = Böcker.Utgivningsdatum, PublisherName = Bokförlag.Namn, PublisherCountry = Bokförlag.Land }).ToList(); var authorsBooks = (from FörfattareBöcker in context.FörfattareBöckers select new { ISBN = FörfattareBöcker.Isbn, AuthorID = FörfattareBöcker.FörfattareId }).ToList(); var authors = (from Författare in context.Författares select new { ID = Författare.Id, FirstName = Författare.Förnamn, LastName = Författare.Efternamn, Birthday = Författare.Födelsedatum }).ToList(); foreach (var item in books) { EFDtataAccessLibary.Models.Bokförlag pubL = new EFDtataAccessLibary.Models.Bokförlag(); pubL.Namn = item.PublisherName; pubL.Land = item.PublisherCountry; booksWAuthors.Add(new TempBook( item.ISBN, item.Title, item.Language, item.Price, item.ReleaseDay, pubL )); } for (int i = 0; i < booksWAuthors.Count; i++) { for (int j = 0; j < authorsBooks.Count; j++) { if (booksWAuthors[i].ISBN == authorsBooks[j].ISBN) { if (context.Författares.Any(a => a.Id == authorsBooks[j].AuthorID)) { var auth = context.Författares.FirstOrDefault(a => a.Id == authorsBooks[j].AuthorID) as EFDtataAccessLibary.Models.Författare; booksWAuthors[i].Authors.Add(auth); } } } } for (int i = 0; i < booksWAuthors.Count - 1; i++) { for (int j = i + 1; j < booksWAuthors.Count; j++) { if (booksWAuthors[i].ISBN == booksWAuthors[j].ISBN) { booksWAuthors.RemoveAt(i); i = -1; break; } } } return(booksWAuthors); } }