public async Task <ActionResult <Bok> > PostBok(Bok bok) { _context.Böcker.Add(bok); await _context.SaveChangesAsync(); return(CreatedAtAction("GetBok", new { id = bok.BokId }, bok)); }
private void btnRegistrera_Click(object sender, EventArgs e) { if (rdbVar == 1) { Bok nyBok = new Bok(tbxTitel.Text, Convert.ToInt32(tbxSidor.Text)); bibliotek.Add(nyBok); lbxBibliotek.Items.Add(nyBok); tbxTitel.Text = ""; tbxSidor.Text = ""; } else if (rdbVar == 2) { Ljudspår nyttLjud = new Ljudspår(tbxTitel.Text, Convert.ToDouble(tbxSpeltid.Text)); bibliotek.Add(nyttLjud); lbxBibliotek.Items.Add(nyttLjud); tbxTitel.Text = ""; tbxSpeltid.Text = ""; } else if (rdbVar == 3) { Film nyFilm = new Film(tbxTitel.Text, Convert.ToDouble(tbxSpeltid.Text), tbxUpplosning.Text); bibliotek.Add(nyFilm); lbxBibliotek.Items.Add(nyFilm); tbxTitel.Text = ""; tbxSpeltid.Text = ""; tbxUpplosning.Text = ""; } }
public async Task <IActionResult> PutBok(int id, Bok bok) { if (id != bok.BokId) { return(BadRequest()); } _context.Entry(bok).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BokExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void LäggTillBöcker() { Bok nyBok1 = new Bok("978-91-7000-150-5", "C# är superskoj", "Bert Bertilsson", false, 2, null); Bok nyBok2 = new Bok("928-94-8880-158-4", "Att skriva skönlitterär kod", "Nost Loi", false, 2, null); bm.LäggTillBok(nyBok1); bm.LäggTillBok(nyBok2); }
public bool settInnBok(Boken innBok) { var nyBok = new Bok() { ISBN = innBok.ISBN, Tittel = innBok.Tittel, Pris = innBok.Pris }; var db = new BokerContext(); try { var eksistererForfatter = db.Forfattere.FirstOrDefault(i => i.Navn == innBok.Forfatter); if (eksistererForfatter == null) { var nyForfatter = new Forfatter() { Navn = innBok.Forfatter }; nyBok.Forfatter = nyForfatter; nyBok.ForfatterId = nyForfatter.ForfatterId; } else { nyBok.Forfatter = eksistererForfatter; nyBok.ForfatterId = eksistererForfatter.ForfatterId; } var eksistererSjanger = db.Sjangere.FirstOrDefault(i => i.Navn == innBok.Sjanger); if (eksistererSjanger == null) { var nySjanger = new Sjanger() { Navn = innBok.Sjanger }; nyBok.Sjanger = nySjanger; nyBok.SjangerId = nySjanger.SjangerId; } else { nyBok.Sjanger = eksistererSjanger; nyBok.SjangerId = eksistererSjanger.SjangerId; } db.Boker.Add(nyBok); db.SaveChanges(); return(true); } catch (Exception feil) { skrivTilFil(feil); return(false); } }
public bool slettBok(int slettId) { var db = new BokerContext(); try { Bok slettBok = db.Boker.Find(slettId); db.Boker.Remove(slettBok); db.SaveChanges(); return(true); } catch (Exception feil) { skrivTilFil(feil); return(false); } }
public List <Bok> FileLoader() { List <Bok> bokList = new List <Bok>(); if (File.Exists("texter.txt")) { StreamReader reader = new StreamReader("texter.txt", Encoding.Default, true); string item = ""; while ((item = reader.ReadLine()) != null) { string[] vektor = item.Split(new string[] { "###" }, StringSplitOptions.None); Bok k = new Bok(vektor[0], vektor[1], vektor[2], vektor[3]); bokList.Add(k); } return(bokList); } return(null); }
public void GenereraObjekt() { if ((BibliotekController.HämtaAllaMedlemmar().Count() < 1) && (BibliotekController.HämtaAllaBocker().Count() < 1)) { //Medlemmar Medlem m1 = new Medlem("12", "Lars", "Kagge", "073019202", "*****@*****.**", null); Medlem m2 = new Medlem("13", "Kalle", "Larsson", "073119202", "*****@*****.**", null); Medlem m3 = new Medlem("14", "Klara", "Lagge", "073018202", "*****@*****.**", null); Medlem m4 = new Medlem("15", "Lila", "Nagge", "073010202", "*****@*****.**", null); Medlem m5 = new Medlem("16", "Hagge", "Kagge", "073119202", "*****@*****.**", null); IEnumerable <Medlem> medlemmar = new List <Medlem>() { m1, m2, m3, m4, m5 }; foreach (Medlem medlem in medlemmar) { BibliotekController.LäggTillMedlem(medlem); } //Böcker Bok b1 = new Bok("1788478126", "C# 8.0 and .NET Core 3.0", "Mark J. Price", 1); Bok b2 = new Bok("0134494164", "Clean Architecture", "Robert C. Martin", 2);; Bok b3 = new Bok("9780132350884", "Clean Code", "Robert C. Martin", 3); Bok b4 = new Bok("0137081073", "The Clean Coder", "Robert C. Martin", 4); Bok b5 = new Bok("1844132390", "Man's Search For Meaning", "Viktor E. Frankl", 5); Bok b6 = new Bok("9780722532935", "The Alchemist", "Paul Coelho", 6); Bok b7 = new Bok("9780316029186", "The Last Wish", "Andrzej Sapkowski", 7); Bok b8 = new Bok("9780316029186", "The Last Wish", "Andrzej Sapkowski", 8); IEnumerable <Bok> böcker = new List <Bok>() { b1, b2, b3, b4, b5, b6, b7, b8 }; foreach (Bok bok in böcker) { BibliotekController.LäggTillBok(bok); } } }
private void buttonAddBook_Click(object sender, EventArgs e) { if (dataGridViewBook.SelectedRows.Count == 0) { return; } DataGridViewRow valdBok = dataGridViewBook.SelectedRows[0]; Bok b = (Bok)valdBok.DataBoundItem; if (!bokadeBöcker.Contains(b)) { bokadeBöcker.Add(b); } var bindingList = new BindingList <Bok>(bokadeBöcker); var source = new BindingSource(bindingList, null); dataGridViewBooked.DataSource = source; dataGridViewBooked.Columns["Tillgänglig"].Visible = false; dataGridViewBooked.Columns["Titel"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; }
public Start(BusinessManager businessManager) { //Laddar in saker i listorna InitializeComponent(); BusinessManager = businessManager; Medlem M = new Medlem(10, "Calle", 0708555789, "*****@*****.**", new List <Bokning>()); Anställd A = new Anställd(10, "Lisa", "LOL", "expedit", new List <Bokning>()); Bok B = new Bok(1245, "How do?"); BusinessManager.MedRepo.Medlemmar.Add(M); BusinessManager.AnstRepo.anställda.Add(A); BusinessManager.BokRepo.Böcker.Add(B); Uppdatera(); ListboxBöcker.SelectionMode = SelectionMode.MultiExtended; }
public bool settInnBok(Boken innBok) { var nyBok = new Bok() { ISBN = innBok.ISBN, Tittel = innBok.Tittel, Pris = innBok.Pris }; var db = new BokerContext(); try { var eksistererForfatter = db.Forfattere.FirstOrDefault(i => i.Navn == innBok.Forfatter); if (eksistererForfatter == null) { var nyForfatter = new Forfatter() { Navn = innBok.Forfatter }; nyBok.Forfatter = nyForfatter; nyBok.ForfatterId = nyForfatter.ForfatterId; } else { nyBok.Forfatter = eksistererForfatter; nyBok.ForfatterId = eksistererForfatter.ForfatterId; } var eksistererSjanger = db.Sjangere.FirstOrDefault(i => i.Navn == innBok.Sjanger); if (eksistererSjanger == null) { var nySjanger = new Sjanger() { Navn = innBok.Sjanger }; nyBok.Sjanger = nySjanger; nyBok.SjangerId = nySjanger.SjangerId; } else { nyBok.Sjanger = eksistererSjanger; nyBok.SjangerId = eksistererSjanger.SjangerId; } db.Boker.Add(nyBok); db.SaveChanges(); return true; } catch (Exception feil) { skrivTilFil(feil); return false; } }
// This method adds a Bok instance or a derived one to your list public void AddBok(Bok b) { Böcker.Add(b); }