private void buttonAdd_Click(object sender, EventArgs e) { if (userValidation.First && userValidation.Last && userValidation.Address && userValidation.CardNumber && userValidation.Email) { var user = new User { FirstName = textBoxFirst.Text, LastName = textBoxLast.Text, Address = textBoxAddress.Text, Phone = textBoxPhone.Text, Email = textBoxEmail.Text, CardNumber = Int32.Parse(textBoxCard.Text) }; db.Users.Add(user); db.SaveChanges(); userBindingSource.DataSource = db.Users.ToList(); textBoxFirst.Text = ""; textBoxLast.Text = ""; textBoxAddress.Text = ""; textBoxPhone.Text = ""; textBoxEmail.Text = ""; textBoxCard.Text = ""; MessageBox.Show("User added!"); } else { MessageBox.Show("Some fields are incorrect!"); } }
private void buttonAddDvd_Click(object sender, EventArgs e) { if (this.dvdValFlags.Title && this.dvdValFlags.DvdNumber && this.dvdValFlags.Price) { var dvd = new Dvd { Title = textBoxTitel.Text, DvdNumber = Int32.Parse(textBoxNumber.Text), Available = checkBoxAvailable.Checked, Price = decimal.Parse(textBoxPrice.Text), Genre = (Genres)Enum.Parse(typeof(Genres), comboBoxGenre.Text) }; db.Dvds.Add(dvd); db.SaveChanges(); textBoxTitel.Text = ""; textBoxNumber.Text = ""; checkBoxAvailable.Checked = false; textBoxPrice.Text = ""; MessageBox.Show("Dvd added!"); } else { MessageBox.Show("Some fields are incorrect!"); } }
private void buttonAddRental_Click(object sender, EventArgs e) { if (this.rentalValFlags.DvdNumber && this.rentalValFlags.UserCardNumber) { var userNumber = Int32.Parse(textBoxUserNumber.Text); var dvdNumber = Int32.Parse(textBoxDvdNumber.Text); DateTime currentDate = DateTime.Now; User queryUser = db.Users.Where(u => userNumber == u.CardNumber).FirstOrDefault(); Dvd queryDvd = db.Dvds.Where(d => dvdNumber == d.DvdNumber).FirstOrDefault(); if (queryDvd == null) { MessageBox.Show("There is no such Dvd Number!"); return; } if (!(bool)queryDvd.Available) { MessageBox.Show("Dvd is not available!"); return; } Rent rent = new Rent(); rent.UserId = queryUser.UserId; rent.DueDate = currentDate; db.Rents.Add(rent); db.SaveChanges(); textBoxUserNumber.Text = ""; textBoxDvdNumber.Text = ""; queryDvd.RentId = rent.RentId; queryDvd.Available = false; queryUser.Rents.Add(rent); rentalValFlags.DvdNumber = false; rentalValFlags.UserCardNumber = false; db.SaveChanges(); MessageBox.Show("Rental added!"); } else { MessageBox.Show("Some fields are incorrect!"); } }