private void btnSave_Click(object sender, EventArgs e) { if (IsValid()) { rentACarEntities.Rents.Add(new Rent() { AmountPerDay = txtAmountPerDay.Value, CarId = (int)cbCar.SelectedValue, Comments = txtComments.Text, CustomerId = (int)cbCustomer.SelectedValue, EmployeeId = (int)cbEmployee.SelectedValue, Days = (int)txtDays.Value, RentalDate = DateTime.Now, RentStatusId = rentACarEntities.RentStatus.Where(rs => rs.Description == "Rentado").FirstOrDefault().Id, ReturnDate = dtpReturnDate.Value, Status = true }); Car car = rentACarEntities.Cars.Where(m => m.Id == (int)cbCar.SelectedValue).FirstOrDefault(); rentACarEntities.Entry(car).State = EntityState.Modified; car.Status = false; rentACarEntities.SaveChanges(); MessageBox.Show("La renta fue creada correctamente.", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information); frmRents frm = new frmRents(); frm.Show(); Close(); } }
private void rentasToolStripMenuItem_Click(object sender, EventArgs e) { frmRents frmRents = new frmRents(); frmRents.Show(); Hide(); }
private void btnSave_Click(object sender, EventArgs e) { if (IsValid()) { Rent rent = rentACarEntities.Rents.Where(r => r.Id == Rent.Id).FirstOrDefault(); rent.AmountPerDay = txtAmountPerDay.Value; rent.CarId = (int)cbCar.SelectedValue; rent.Comments = txtComments.Text; rent.CustomerId = (int)cbCustomer.SelectedValue; rent.Days = (int)txtDays.Value; rent.EmployeeId = (int)cbEmployee.SelectedValue; rentACarEntities.Entry(rent).State = System.Data.Entity.EntityState.Modified; rentACarEntities.SaveChanges(); MessageBox.Show("La renta fue editada correctamente.", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information); frmRents frmRents = new frmRents(); frmRents.Show(); Hide(); } }