public ActionResult Create(poruke poruke) { if (ModelState.IsValid) { db.poruke.Add(poruke); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.idKorisnikaPosiljaoca = new SelectList(db.korisnici, "idKorisnika", "imeKorisnika", poruke.idKorisnikaPosiljaoca); ViewBag.idKorisnikaPrimaoca = new SelectList(db.korisnici, "idKorisnika", "imeKorisnika", poruke.idKorisnikaPrimaoca); return View(poruke); }
// PUT api/Poruke/5 public HttpResponseMessage Putporuke(int id, poruke poruke) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != poruke.idPoruke) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(poruke).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
// POST api/Poruke public HttpResponseMessage Postporuke(poruke poruke) { if (ModelState.IsValid) { db.poruke.Add(poruke); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, poruke); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = poruke.idPoruke })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
public void postaviporuku(Helpers.Poruka poruka) { if (poruka != null) { var porukaStara = new poruke() { tekstPoruke = poruka.TekstPoruke, naslovPoruke = poruka.NaslovPoruke, aktivan = poruka.Aktivan, idKorisnikaPosiljaoca = poruka.PosiljaocId, idKorisnikaPrimaoca = poruka.PrimaocId }; db.poruke.Add(porukaStara); db.SaveChanges(); } }
public ActionResult Edit(poruke poruke) { if (ModelState.IsValid) { db.Entry(poruke).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.idKorisnikaPosiljaoca = new SelectList(db.korisnici, "idKorisnika", "imeKorisnika", poruke.idKorisnikaPosiljaoca); ViewBag.idKorisnikaPrimaoca = new SelectList(db.korisnici, "idKorisnika", "imeKorisnika", poruke.idKorisnikaPrimaoca); return View(poruke); }