private void dgvFavorites_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { if (e.ColumnIndex == 11) { var result = dgvFavorites.Rows[e.RowIndex].DataBoundItem as Model.ViewModel.VehicleListVM; if (result != null) { frmRentCar frm = new frmRentCar(result.Id, double.Parse(result.Price)); frm.ShowDialog(); } } } }
private async void btnSave_Click(object sender, EventArgs e) { if (APIService.loggedUser.RoleId == 2) { if (!editVehicle.IsActive.Value) { MessageBox.Show("Can not rent vehicle that is not active.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { frmRentCar frm = new frmRentCar(editVehicle.Id, editVehicle.Price); frm.ShowDialog(); } } else { try { if (Validate(txtName) && Validate(txtPrice) && Validate(cmbFuel) && Validate(cmbBrand) && Validate(cmbModel) && cbTransmission.SelectedIndex > 0) { if (StringToInt(txtYear.Text.ToString()) && StringToInt(txtSeats.Text.ToString()) && StringToInt(txtPrice.Text.ToString())) { request.Description = rtxtDesc.Text; request.NumberOfSeats = int.Parse(txtSeats.Text); request.YearManufactured = int.Parse(txtYear.Text); request.Name = txtName.Text; request.BrandId = int.Parse(cmbBrand.SelectedValue.ToString()); request.FuelId = int.Parse(cmbFuel.SelectedValue.ToString()); request.IsActive = cbActive.Checked; request.VehicleModelId = int.Parse(cmbModel.SelectedValue.ToString()); request.VehicleTypeId = 1; request.Price = int.Parse(txtPrice.Text); request.Transmission = cbTransmission.SelectedValue.ToString(); } else { MessageBox.Show("Check your input"); return; } if (EditId != 0) { try { await _serviceVehicle.Update <Model.Vehicle>(editVehicle.Id, request); MessageBox.Show("Vehicle sucessfully updated!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); } catch (Exception) { MessageBox.Show("Check your input"); } } else { try { await _serviceVehicle.Insert <Model.Vehicle>(request); MessageBox.Show("Vehicle sucessfully added!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); } catch (Exception) { MessageBox.Show("Chech your input"); } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); throw; } } }