public void Return() { try { Int32.Parse(_id); } catch (Exception e) { Thread errorParsing = new Thread(() => MessageBox.Show("Nie można przekonwertować ID. Wprowadź poprawne dane!")); errorParsing.Start(); return; } int ID = Int32.Parse(_id); using (filmyEntities entities = new filmyEntities()) { var movie_instance = entities.Movie_Instance.Find(ID); if (movie_instance.Is_Rented == false) { Thread notRented = new Thread(() => MessageBox.Show("Film nie jest wypożyczony")); notRented.Start(); return; } movie_instance.Is_Rented = false; entities.SaveChanges(); Thread returned = new Thread(() => MessageBox.Show("Film został zwrócony")); returned.Start(); return; } }
public void RentMovie() { try { Int32.Parse(_userId); Int32.Parse(_movieId); } catch (Exception e) { Thread badData = new Thread(() => MessageBox.Show("Wprowadzono niepoprawne dane!")); badData.Start(); return; } using (filmyEntities entities = new filmyEntities()) { int userID = Int32.Parse(_userId); int movieID = Int32.Parse(_movieId); var instance = entities.Movie_Instance.Find(movieID); var user = entities.Client.Find(userID); if (user == null) { Thread badData2 = new Thread(() => MessageBox.Show("Użytkownik o podanym ID nie istnieje!")); badData2.Start(); return; } if (instance == null) { Thread badData21 = new Thread(() => MessageBox.Show("Płyta o podanym ID nie istnieje!")); badData21.Start(); return; } if (instance.Is_Rented == true) { Thread badData3 = new Thread(() => MessageBox.Show("Ta kopia filmu jest już wypożyczona!")); badData3.Start(); return; } Transactions newTransaction = new Transactions(); newTransaction.FK_ID_Movie_Instance = instance.ID_Movie_Instance; newTransaction.FK_ID_Clients = user.ID_client; newTransaction.rental_date = DateTime.Now; instance.Is_Rented = true; //entities.Movie_Instance. //entities.Movie_Instance.AddOrUpdate(instance); entities.Transactions.Add(newTransaction); entities.SaveChanges(); Thread badData4 = new Thread(() => MessageBox.Show("Film został wypożyczony!")); badData4.Start(); } }
public AddNewUser(string name, string surname, string PESEL, string Street, string City, string PostNumber, int HouseNum, int FlatNum) { Client client = new Client(); client.Name = name; client.Surname = surname; client.PESEL = PESEL; client.street = Street; client.city = City; client.post_number = PostNumber; client.house_number = HouseNum; client.flat_number = FlatNum; using (filmyEntities f = new filmyEntities()) { if (f.Client.FirstOrDefault(c => c.PESEL == client.PESEL) != null) { MessageBox.Show("Klient z numerem PESEL " + client.PESEL + " jest już zarejestrowany", "Klient istnieje"); return; } f.Client.Add(client); f.SaveChanges(); MessageBox.Show("Klient " + client.Name + " " + client.Surname + " dodany.\nNumer ID klienta: " + client.ID_client, "Klient dodany"); } }