public IHttpActionResult PutGotoviProizvod(int id, GotoviProizvod gotoviProizvod) { if (id != gotoviProizvod.GotoviProizvodID) { return(BadRequest()); } GotoviProizvod gp = _db.GotoviProizvod.Find(id); if (gp == null) { return(BadRequest()); } gp.KategorijaID = gotoviProizvod.KategorijaID; gp.GotoviProizvodID = gotoviProizvod.GotoviProizvodID; gp.VrijemePripreme = gotoviProizvod.VrijemePripreme; gp.Slika = gotoviProizvod.Slika; gp.SlikaUmanjeno = gotoviProizvod.SlikaUmanjeno; gp.Opis = gotoviProizvod.Opis; gp.Naziv = gotoviProizvod.Naziv; try { _db.SaveChanges(); } catch (Exception e) { return(BadRequest(e.Message)); } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetGotoviProizvod(int id) { GotoviProizvod gotoviProizvod = _db.GotoviProizvod.Find(id); if (gotoviProizvod == null) { return(NotFound()); } return(Ok(gotoviProizvod)); }
public IHttpActionResult DeleteGotoviProizvod(int id) { GotoviProizvod gotoviProizvod = _db.GotoviProizvod.Find(id); if (gotoviProizvod == null) { return(NotFound()); } _db.GotoviProizvod.Remove(gotoviProizvod); _db.SaveChanges(); return(Ok(gotoviProizvod)); }
public IHttpActionResult PostGotoviProizvod(GotoviProizvod gotoviProizvod) { try { _db.GotoviProizvod.Add(gotoviProizvod); _db.SaveChanges(); } catch (Exception e) { return(BadRequest(e.Message)); } return(CreatedAtRoute("DefaultApi", new { id = gotoviProizvod.GotoviProizvodID }, gotoviProizvod)); }
public GotoviProizvodiEdit(int id) { InitializeComponent(); this.AutoValidate = AutoValidate.Disable; HttpResponseMessage responseGP = gotoviProizvodiService.GetResponse(id.ToString()); if (responseGP.IsSuccessStatusCode) { gotoviProizvod = responseGP.Content.ReadAsAsync <GotoviProizvod>().Result; } else if (responseGP.StatusCode == System.Net.HttpStatusCode.NotFound) { this.Close(); MessageBox.Show(Messages.error + ": " + Messages.not_found, Messages.error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void DodajButton_Click(object sender, EventArgs e) { if (this.ValidateChildren()) { List <GPProizvod> gppList = new List <GPProizvod>(); try { foreach (DataGridViewRow row in sastojciDataGridView.Rows) { if (row.Cells[1].Value.ToBool()) { if (row.Cells[4].Value.ToInt() == 0) { throw new Exception("MjernaJedinicaID:" + row.Cells[2].Value.ToString()); } gppList.Add(new GPProizvod() { ProizvodID = row.Cells[0].Value.ToInt(), KolicinaUtroska = row.Cells[3].Value.ToDecimal(), MjernaJedinicaID = row.Cells[4].Value.ToInt(), }); } } if (gppList.Count == 0) { throw new Exception("NijeOdabranoNista"); } gp.Cijena = cijenaInput.Text.ToDecimal(); gp.KategorijaID = kategorijaComboBox.SelectedValue.ToInt(); gp.Opis = opisInput.Text; gp.VrijemePripreme = vrijemePripremeInput.Text.ToInt(); gp.Naziv = nazivInput.Text; gp.Opis = opisInput.Text; if (string.IsNullOrEmpty(slikaInput.Text)) { gp.Slika = UIHelper.AddDefaultPictureFull(); gp.SlikaUmanjeno = UIHelper.AddDefaultPictureResized(); } else { gp.Slika = UIHelper.AddFromFileFull(slikaInput.Text); gp.SlikaUmanjeno = UIHelper.AddFromFileResized(slikaInput.Text); } HttpResponseMessage responseGP = gotoviProizvodiService.PostResponse(gp); if (responseGP.IsSuccessStatusCode) { gp = responseGP.Content.ReadAsAsync <GotoviProizvod>().Result; gppList.ForEach(x => x.GotoviProizvodID = gp.GotoviProizvodID); HttpResponseMessage responseGPP = gpProizvodService.PostActionResponse("GPProizvodList", gppList); if (responseGPP.IsSuccessStatusCode) { DialogResult = DialogResult.OK; this.Close(); MessageBox.Show(Messages.success_add, Messages.success, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(Messages.error + ": " + responseGPP.ReasonPhrase, Messages.error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show(Messages.error + ": " + responseGP.ReasonPhrase, Messages.error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception k) { if (k.Message.Split(':')[0] == "MjernaJedinicaID") { MessageBox.Show(Messages.mj_not_selected + " za " + k.Message.Split(':')[1], Messages.error, MessageBoxButtons.OK, MessageBoxIcon.Error); } if (k.Message == "NijeOdabranoNista") { MessageBox.Show(Messages.nothing_selected_product, Messages.error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }