private void AddCzytelnik(object sender, RoutedEventArgs e) { czytelnikDB.Czytelnik.Add(czytelnik); czytelnikDB.SaveChanges(); czytelnik = new Czytelnik(); this.Visibility = Visibility.Hidden; }
public ActionResult Login(Czytelnik czyt) { #region RemoveModelState ModelState.Remove("imie"); ModelState.Remove("nazwisko"); ModelState.Remove("email"); ModelState.Remove("kod_pocztowy"); ModelState.Remove("miasto"); ModelState.Remove("ulica"); ModelState.Remove("nr_domu"); ModelState.Remove("nr_mieszkania"); ModelState.Remove("wojewodztwo"); #endregion if (ModelState.IsValid) { var details = biblioDB.Czytelnik.Where(a => a.kod.Equals(czyt.kod) && a.pesel.Equals(czyt.pesel)).FirstOrDefault(); if (details != null) { Session["id"] = details.id_czytelnik; Session["imie"] = details.imie; Session["nazwisko"] = details.nazwisko; return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Niepoprawne dane!"); } } return(View()); }
private void openEdytujWindow(object sender, RoutedEventArgs e) { selectedCzytelnik = (sender as FrameworkElement).DataContext as Czytelnik; EdytujWindow edytujWindow = new EdytujWindow(czytelnikDB, selectedCzytelnik); edytujWindow.Show(); }
public EdytujWindow(CzytelnikDB czytelnikDB, Czytelnik selectedCzytelnik) { this.selectedCzytelnik = selectedCzytelnik; this.czytelnikDB = czytelnikDB; InitializeComponent(); edytujCzytelnikGrid.DataContext = selectedCzytelnik; }
// GET: Czytelnicy/Edit/5 public ActionResult Edit(int?id) { Czytelnik user = null; ViewBag.UserRole = null; if (Session["UserID"] != null) { user = db.Czytelnik.Find(Int32.Parse(Session["UserID"].ToString())); } if (user != null) { ViewBag.UserRole = user.Rola; } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Czytelnik czytelnik = db.Czytelnik.Find(id); if (czytelnik == null) { return(HttpNotFound()); } ViewBag.UserRoleString = RolaToString(czytelnik.Rola); ViewBag.RoleSelectList = new SelectList(db.Rola, "ID", "Nazwa", czytelnik.Rola); return(View(czytelnik)); }
public async Task <IActionResult> Edit(int id, [Bind("IdCzytelnik,Imie,Nazwisko,Miasto,Telefon")] Czytelnik czytelnik) { if (id != czytelnik.IdCzytelnik) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(czytelnik); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CzytelnikExists(czytelnik.IdCzytelnik)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(czytelnik)); }
public ActionResult Edit([Bind(Include = "ID,Imie,Nazwisko,Uzytkownik,Haslo,Email,Wazne,Rola")] Czytelnik czytelnik) { if (ModelState.IsValid) { CzytelnikValidator validator = new CzytelnikValidator(); ValidationResult result = validator.Validate(czytelnik); if (!result.IsValid) { List <string> errors = new List <string>(); foreach (ValidationFailure vf in result.Errors) { errors.Add(vf.ErrorMessage); } ViewBag.Error = errors; ViewBag.UserRoleString = RolaToString(czytelnik.Rola); ViewBag.RoleSelectList = new SelectList(db.Rola, "ID", "Nazwa", czytelnik.Rola); return(View(czytelnik)); } db.Entry(czytelnik).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(czytelnik)); }
public void PobierzCzytelnikaTest() { DataRepository dr = new DataRepository(new WypelnijStalymi()); Czytelnik c = dr.PobierzCzytelnika(1); Assert.AreEqual(1, c.IdCzytelnika); }
public ActionResult Create([Bind(Include = "IdCzytelnik,Imie,Nazwisko,Telefon,Adres,Wersja")] Czytelnik czytelnik) { if (ModelState.IsValid) { db.Czytelniks.Add(czytelnik); try { db.SaveChanges(); } catch (Exception e) { string message = ""; if (e.InnerException == null) { message = "Podano nieprawidłowe dane czytelnika!"; } else { message = e.InnerException.InnerException.Message; } ViewBag.Exception = message; return(View(czytelnik)); } return(RedirectToAction("Index")); } return(View(czytelnik)); }
public ActionResult Create([Bind(Include = "ID,Imie,Nazwisko,Uzytkownik,Haslo,Email")] Czytelnik czytelnik) { if (ModelState.IsValid) { CzytelnikValidator validator = new CzytelnikValidator(); ValidationResult result = validator.Validate(czytelnik); if (!result.IsValid) { List <string> errors = new List <string>(); foreach (ValidationFailure vf in result.Errors) { errors.Add(vf.ErrorMessage); } ViewBag.Error = errors; return(View(czytelnik)); } db.Czytelnik.Add(czytelnik); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(czytelnik)); }
private void usunRow(object sender, RoutedEventArgs e) { selectedCzytelnikToDelete = (sender as FrameworkElement).DataContext as Czytelnik; czytelnikDB.Czytelnik.Remove(selectedCzytelnikToDelete); czytelnikDB.SaveChanges(); GetCzytelnik(); }
public ActionResult DeleteConfirmed(int id) { Czytelnik czytelnik = db.Czytelnik.Find(id); db.Czytelnik.Remove(czytelnik); db.SaveChanges(); return(RedirectToAction("Index")); }
public void CreateCzytelnikTest() { Czytelnik czyt = new Czytelnik("Janina", "Kowal", "94121304040"); dataRepository.CreateCzytelnik(czyt); Assert.AreEqual(dataRepository.GetCzytelnik(dataRepository.GetAllCzytelnicy().Count - 1).Imie, "Janina"); Assert.AreEqual(dataRepository.GetCzytelnik(dataRepository.GetAllCzytelnicy().Count - 1).Nazwisko, "Kowal"); Assert.AreEqual(dataRepository.GetCzytelnik(dataRepository.GetAllCzytelnicy().Count - 1).Pesel, "94121304040"); }
public void GetCzytelnikTest() { Czytelnik czytelnik = new Czytelnik("Jan", "Kowalski", "123456789"); dataRepository.CreateCzytelnik(czytelnik); Assert.AreEqual(dataRepository.GetCzytelnik(dataRepository.GetAllCzytelnicy().Count - 1).Imie, "Jan"); Assert.AreEqual(dataRepository.GetCzytelnik(dataRepository.GetAllCzytelnicy().Count - 1).Nazwisko, "Kowalski"); Assert.AreEqual(dataRepository.GetCzytelnik(dataRepository.GetAllCzytelnicy().Count - 1).Pesel, "123456789"); }
public void DeleteCzytelnikTest() { Czytelnik czyt = new Czytelnik("Janina", "Kowal", "94121304040"); dataRepository.CreateCzytelnik(czyt); int size = dataRepository.GetAllCzytelnicy().Count; dataRepository.DeleteCzytelnik(czyt); Assert.AreEqual(size - 1, dataRepository.GetAllCzytelnicy().Count); }
public void EditCzytelnik(Czytelnik czytelnik) { var zmiana = db.Czytelnik.Where(a => a.IdCzytelnika == czytelnik.IdCzytelnika).FirstOrDefault(); zmiana.Imie = czytelnik.Imie; zmiana.Nazwisko = czytelnik.Nazwisko; zmiana.Pesel = czytelnik.Pesel; zmiana.Adres = czytelnik.Adres; db.SaveChanges(); }
public async Task <IActionResult> Create([Bind("IdCzytelnik,Imie,Nazwisko,Miasto,Telefon")] Czytelnik czytelnik) { if (ModelState.IsValid) { _context.Add(czytelnik); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(czytelnik)); }
public ActionResult Dashboard() { if (Session["UserID"] == null) { return(View()); } int id = Int32.Parse(Session["UserID"].ToString()); Czytelnik user = db.Czytelnik.Find(id); return(View(user)); }
public void GetWypozyczenieTest() { Czytelnik czytelnik = new Czytelnik("Jan", "Kowalski", "123456789"); OpisStanu opis = new OpisStanu(new Ksiazka(2000, "Jakas", "Autor"), true, 100); Wypozyczenie wyp = new Wypozyczenie(czytelnik, opis); dataRepository.CreateWypozyczenie(wyp); Assert.AreEqual(dataRepository.GetWypozyczenie(dataRepository.GetAllWypozyczenie().Count - 1).Czytelnik.Imie, "Jan"); Assert.AreEqual(dataRepository.GetWypozyczenie(dataRepository.GetAllWypozyczenie().Count - 1).Czytelnik.Nazwisko, "Kowalski"); Assert.AreEqual(dataRepository.GetWypozyczenie(dataRepository.GetAllWypozyczenie().Count - 1).Czytelnik.Pesel, "123456789"); Assert.AreEqual(dataRepository.GetWypozyczenie(dataRepository.GetAllWypozyczenie().Count - 1).Stan.CzyWypozyczona, true); Assert.AreEqual(dataRepository.GetWypozyczenie(dataRepository.GetAllWypozyczenie().Count - 1).Stan.Ksiazka.Id, 2000); }
public ActionResult Register(Czytelnik czyt) { if (ModelState.IsValid) { var detailsUser = biblioDB.Czytelnik.Where(p => p.kod == czyt.kod).FirstOrDefault(); if (detailsUser == null) { biblioDB.Czytelnik.Add(czyt); biblioDB.SaveChanges(); } } return(View()); }
// GET: Czytelnicy/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Czytelnik czytelnik = db.Czytelnik.Find(id); if (czytelnik == null) { return(HttpNotFound()); } return(View(czytelnik)); }
// GET: Czytelnicy/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Czytelnik czytelnik = db.Czytelnik.Find(id); if (czytelnik == null) { return(HttpNotFound()); } ViewBag.UserRoleString = RolaToString(czytelnik.Rola); return(View(czytelnik)); }
public void CzytelnikEqualsTest() { Czytelnik czytelnik = new Czytelnik("Jan", "Nowak", "123"); Czytelnik czytelnik2 = new Czytelnik("Jan", "Nowak", "124"); Czytelnik czytelnik3 = new Czytelnik("Jan", "Kowalski", "123"); Czytelnik czytelnik4 = new Czytelnik("Michał", "Nowak", "123"); Czytelnik czytelnik5 = new Czytelnik("Jan", "Nowak", "123"); Assert.AreEqual(czytelnik.Equals(czytelnik), true); Assert.AreEqual(czytelnik.Equals(czytelnik5), true); Assert.AreEqual(czytelnik.Equals(null), false); Assert.AreEqual(czytelnik.Equals(czytelnik2), false); Assert.AreEqual(czytelnik.Equals(czytelnik3), false); Assert.AreEqual(czytelnik.Equals(czytelnik4), false); }
public void UpdateCzytelnikTest() { Czytelnik staryCzytelnik = new Czytelnik("Zosia", "Samosia", "1223"); Czytelnik czyt = new Czytelnik("Janina", "Kowal", "94121304040"); dataRepository.CreateCzytelnik(staryCzytelnik); Assert.AreEqual(dataRepository.GetCzytelnik(dataRepository.GetAllCzytelnicy().Count - 1).Imie, "Zosia"); Assert.AreEqual(dataRepository.GetCzytelnik(dataRepository.GetAllCzytelnicy().Count - 1).Nazwisko, "Samosia"); Assert.AreEqual(dataRepository.GetCzytelnik(dataRepository.GetAllCzytelnicy().Count - 1).Pesel, "1223"); dataRepository.UpdateCzytelnik(dataRepository.GetAllCzytelnicy().Count - 1, czyt); Assert.AreEqual(dataRepository.GetCzytelnik(dataRepository.GetAllCzytelnicy().Count - 1).Imie, "Janina"); Assert.AreEqual(dataRepository.GetCzytelnik(dataRepository.GetAllCzytelnicy().Count - 1).Nazwisko, "Kowal"); Assert.AreEqual(dataRepository.GetCzytelnik(dataRepository.GetAllCzytelnicy().Count - 1).Pesel, "94121304040"); }
public ActionResult Edit([Bind(Include = "IdCzytelnik,Imie,Nazwisko,Telefon,Adres,Wersja")] Czytelnik czytelnik) { if (ModelState.IsValid) { db.Entry(czytelnik).State = EntityState.Modified; try { var aktualnaWersja = from czytelnikWersja in db.Czytelniks where czytelnikWersja.IdCzytelnik == czytelnik.IdCzytelnik select czytelnikWersja.Wersja; if (aktualnaWersja.FirstOrDefault() != czytelnik.Wersja) { throw new Exception("BO"); } czytelnik.Wersja++; db.SaveChanges(); } catch (Exception e) { string message = ""; if (e.Message == "BO") { message = "Konflikt aktualizacji - blokowanie optymistyczne!"; } else if (e.InnerException == null) { message = "Podano nieprawidłowe dane czytelnika!"; } else { message = e.InnerException.InnerException.Message; } //ViewBag.IdCzytelnikaDlaWypozyczenia = id; TempData["Exception"] = message; czytelnik = (from czytelnicy in db.Czytelniks where czytelnicy.IdCzytelnik == czytelnik.IdCzytelnik select czytelnicy).FirstOrDefault(); return(RedirectToAction("Edit")); } return(RedirectToAction("Index")); } return(View(czytelnik)); }
public void SzukaWypozyczenCzytelnika() { Czytelnik czyt = new Czytelnik("Zofia", "Mazurkiewicz", "321"); Ksiazka ksiazka = new Ksiazka(1000, "Jakaś Książka", "Autor nieznany"); Ksiazka ksiazka2 = new Ksiazka(2000, "Jakaś Książka cz. 2", "Autor nieznany"); OpisStanu opis = new OpisStanu(ksiazka, false, 20); OpisStanu opis2 = new OpisStanu(ksiazka2, false, 25); service.DodajWypozyczenie(new Wypozyczenie(czyt, opis)); service.DodajWypozyczenie(new Wypozyczenie(czyt, opis2)); ObservableCollection <Wypozyczenie> wypozyczenia = service.SzukajWypozyczenCzytelnika(czyt); Assert.AreEqual(wypozyczenia.Count, 2); Assert.AreEqual(wypozyczenia[0].Czytelnik, czyt); Assert.AreEqual(wypozyczenia[0].Stan, opis); Assert.AreEqual(wypozyczenia[1].Czytelnik, czyt); Assert.AreEqual(wypozyczenia[1].Stan, opis2); }
public void WypozyczTestWyjatekKsiazkaJestJuzWypozyczona() { try { Czytelnik czyt = new Czytelnik("Zofia", "Mazurkiewicz", "123"); Ksiazka ksi = new Ksiazka(1000, "Jakaś Książka", "Autor nieznany"); OpisStanu opis = new OpisStanu(ksi, true, 200); service.DodajOpisStanu(opis); service.DodajCzytelnika(czyt); ObservableCollection <Wypozyczenie> wypozyczenia = service.SzukajWypozyczenCzytelnika(czyt); Assert.AreEqual(wypozyczenia.Count, 0); service.Wypozycz(czyt, ksi); } catch (Exception ex) { Assert.AreEqual(ex.Message, "Nie znaleziono książki o tym tyltule, którą możnaby wypożyczyć"); } }
public void CreateWypozyczenieTest() { Czytelnik czyt = new Czytelnik("Janina", "Kowal", "94121304040"); Ksiazka ksiazka = new Ksiazka(1000, "Opium w Rosole", "Małgorzata Musierowicz"); dataRepository.CreateCzytelnik(czyt); OpisStanu opisStanu = new OpisStanu(ksiazka, true, 30); dataRepository.CreateOpisStanu(opisStanu); Wypozyczenie wypozyczenie = new Wypozyczenie(dataRepository.GetCzytelnik(dataRepository.GetAllCzytelnicy().Count - 1), dataRepository.GetOpisStanu(dataRepository.GetAllOpisStanu().Count - 1)); dataRepository.CreateWypozyczenie(wypozyczenie); Assert.AreEqual(dataRepository.GetWypozyczenie(dataRepository.GetAllWypozyczenie().Count - 1).Czytelnik.Imie, "Janina"); Assert.AreEqual(dataRepository.GetWypozyczenie(dataRepository.GetAllWypozyczenie().Count - 1).Czytelnik.Nazwisko, "Kowal"); Assert.AreEqual(dataRepository.GetWypozyczenie(dataRepository.GetAllWypozyczenie().Count - 1).Czytelnik.Pesel, "94121304040"); Assert.AreEqual(dataRepository.GetWypozyczenie(dataRepository.GetAllWypozyczenie().Count - 1).Stan.Ksiazka.Id, 1000); Assert.AreEqual(dataRepository.GetWypozyczenie(dataRepository.GetAllWypozyczenie().Count - 1).Stan.CzyWypozyczona, true); Assert.AreEqual(dataRepository.GetWypozyczenie(dataRepository.GetAllWypozyczenie().Count - 1).Stan.Wartosc, 30); }
public void WypozyczTest() { Czytelnik czyt = new Czytelnik("Zofia", "Mazurkiewicz", "123"); Ksiazka ksi = new Ksiazka(1000, "Jakaś Książka", "Autor nieznany"); OpisStanu opis = new OpisStanu(ksi, false, 200); service.DodajOpisStanu(opis); service.DodajCzytelnika(czyt); ObservableCollection <Wypozyczenie> wypozyczenia = service.SzukajWypozyczenCzytelnika(czyt); Assert.AreEqual(wypozyczenia.Count, 0); service.Wypozycz(czyt, ksi); ObservableCollection <Wypozyczenie> wypozyczenia2 = service.SzukajWypozyczenCzytelnika(czyt); Assert.AreEqual(wypozyczenia2[0].Stan.CzyWypozyczona, true); Assert.AreEqual(wypozyczenia2.Count, 1); }
public void WypozyczenieEqualsTest() { Czytelnik czytelnik = new Czytelnik("Jan", "Nowak", "123"); Czytelnik czytelnik2 = new Czytelnik("Jan", "Nowak", "124"); Czytelnik czytelnik3 = new Czytelnik("Jan", "Kowalski", "123"); Ksiazka ksiazka = new Ksiazka(1, "Jakis", "Tam"); Ksiazka ksiazka2 = new Ksiazka(1, "Jais", "Tam"); OpisStanu opis = new OpisStanu(ksiazka, true, 100); OpisStanu opis2 = new OpisStanu(ksiazka2, true, 100); Wypozyczenie wypozyczenie = new Wypozyczenie(czytelnik, opis); Wypozyczenie wypozyczenie2 = new Wypozyczenie(czytelnik, opis); Wypozyczenie wypozyczenie3 = new Wypozyczenie(czytelnik, opis2); Wypozyczenie wypozyczenie4 = new Wypozyczenie(czytelnik3, opis); Assert.AreEqual(wypozyczenie.Equals(wypozyczenie), true); Assert.AreEqual(wypozyczenie.Equals(wypozyczenie2), true); Assert.AreEqual(wypozyczenie.Equals(null), false); Assert.AreEqual(wypozyczenie.Equals(wypozyczenie3), false); Assert.AreEqual(wypozyczenie.Equals(wypozyczenie4), false); }