public IHttpActionResult PutNarudzbePizze(int id, NarudzbePizze narudzbePizze) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != narudzbePizze.NarudzbaPizzaId) { return(BadRequest()); } db.Entry(narudzbePizze).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!NarudzbePizzeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
private void zavrsiNarudzbu_Click(object sender, RoutedEventArgs e) { if (Global.narudzbePizze.Count == 0) { MessageDialog msg = new MessageDialog("Korpa je prazna!"); msg.ShowAsync(); } else { Narudzbe n = new Narudzbe(); n.KorisnikId = Global.prijavljeniKorisnik.KorisnikId; n.StatusNarudzbeId = 1; n.DatumNarudzbe = DateTime.Now; n.OtkazanaNarudzba = false; n.AdresaZaDostavu = adresaZaDostavu.Text; n.BrojTelefona = kontaktTelefon.Text; HttpResponseMessage response = narudzbeService.PostResponse(n); if (response.IsSuccessStatusCode) { int narudzbaId = response.Content.ReadAsAsync <Narudzbe>().Result.NarudzbaId; for (int i = 0; i < Global.narudzbePizze.Count; i++) { NarudzbePizze np = new NarudzbePizze(); np.NarudzbaId = narudzbaId; np.PizzaId = Global.narudzbePizze[i].PizzaId; np.Kolicina = Global.narudzbePizze[i].Kolicina; np.Cijena = Global.narudzbePizze[i].Cijena; HttpResponseMessage responsenp = narudzbePizzeService.PostResponse(np); if (responsenp.IsSuccessStatusCode) { if (Global.narudzbePizze[i].DodatniSastojci != null) { int narudzbapId = responsenp.Content.ReadAsAsync <NarudzbePizze>().Result.NarudzbaPizzaId; for (int j = 0; j < Global.narudzbePizze[i].DodatniSastojci.Count; j++) { Sastojci s = new Sastojci(); s.NarudzbaPizzaId = narudzbapId; s.SastojakId = Global.narudzbePizze[i].DodatniSastojci[j].SastojakId; HttpResponseMessage responseDs = dodatniSastojciPizzeService.PostResponse(s); } } } } MessageDialog msg = new MessageDialog("Narudžba uspješno kompletirana!"); msg.ShowAsync(); Global.narudzbePizze = null; Frame.Navigate(typeof(AllProductsPage)); } } }
public IHttpActionResult GetNarudzbePizze(int id) { NarudzbePizze narudzbePizze = db.NarudzbePizze.Find(id); if (narudzbePizze == null) { return(NotFound()); } return(Ok(narudzbePizze)); }
private void narucenePizzeListView_ItemClick(object sender, ItemClickEventArgs e) { NarudzbePizze np = (NarudzbePizze)e.ClickedItem; Global.narudzbePizze.Where(d => d.PizzaId == np.PizzaId).First().Kolicina -= 1; if (np.Kolicina <= 0) { Global.narudzbePizze.Remove(np); } BindShoppingCart(); }
public IHttpActionResult DeleteNarudzbePizze(int id) { NarudzbePizze narudzbePizze = db.NarudzbePizze.Find(id); if (narudzbePizze == null) { return(NotFound()); } db.NarudzbePizze.Remove(narudzbePizze); db.SaveChanges(); return(Ok(narudzbePizze)); }
public IHttpActionResult PostNarudzbePizze(NarudzbePizze narudzbePizze) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { narudzbePizze.NarudzbaPizzaId = Convert.ToInt32(db.myPizza_NarudzbePizze_Insert(narudzbePizze.NarudzbaId, narudzbePizze.PizzaId, narudzbePizze.Kolicina, narudzbePizze.Cijena).FirstOrDefault()); } catch (EntityException ex) { throw CreateHttpResponseException(Util.ExceptionHandler.HandleException(ex), HttpStatusCode.Conflict); } return(CreatedAtRoute("DefaultApi", new { id = narudzbePizze.NarudzbaPizzaId }, narudzbePizze)); }