private async void btnSnimiProizvod_Click(object sender, EventArgs e) { var sastojci = chListSastojci.CheckedItems.Cast <MSastojci>().Select(x => x.SastojciId).ToList(); var meni = chbMeni.CheckedItems.Cast <MMeni>().Select(x => x.MeniId).ToList(); request.Naziv = txtNaziv.Text; request.Cijena = decCijena.Value; request.Opis = txtOpis.Text; request.Sastojci = sastojci; request.Meni = meni; AddReplacePicture(); var kategorija = cmbKategorija.SelectedValue; if (int.TryParse(kategorija.ToString(), out int kategorijaId)) { request.KategorijaId = kategorijaId; } if (_id.HasValue) { if (ValidateChildren(ValidationConstraints.Enabled)) { await _serviceProdukti.Update <MProdukti>(_id, request); MessageBox.Show("Operacija uspješna"); this.Close(); await _jelovnik.UpdateForm(); } } else { if (ValidateChildren(ValidationConstraints.Enabled)) { await _serviceProdukti.Insert <MProdukti>(request); MessageBox.Show("Operacija uspješna"); this.Close(); await _jelovnik.UpdateForm(); } } }
private async void btnSnimiProizvod_Click(object sender, EventArgs e) { if (ValidateChildren(ValidationConstraints.Enabled)) { MeniRequest.DatumNapravljen = DateTime.Now; MeniRequest.Naziv = txtNaziv.Text; MeniRequest.Opis = txtOpis.Text; int restoranId = Global.prijavljeniRestoran.RestoranId; MeniRequest.RestoranId = restoranId; DateTime dt = Convert.ToDateTime(dateTimeRok.Value); MeniRequest.DatumIsteka = dt; foreach (DataGridViewRow row in produktiGrid.Rows) { if (Convert.ToBoolean(row.Cells[4].Value) == true) { int id = Convert.ToInt32(row.Cells[0].Value); MeniRequest.listaProizvoda.Add(id); } } if (_meniId.HasValue) { await _serviceMeni.Update <MMeni>(_meniId, MeniRequest); } else { await _serviceMeni.Insert <MMeni>(MeniRequest); } MessageBox.Show("Operacija uspješna!"); this.Close(); await _jelovnik.UpdateForm(); } }