public ActionResult Create(dokumenti dokumenti) { if (ModelState.IsValid) { db.dokumenti.Add(dokumenti); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.idOglasa = new SelectList(db.oglasi, "idOglasa", "nazivOglasa", dokumenti.idOglasa); return View(dokumenti); }
// POST api/DokumentiApi public HttpResponseMessage Postdokumenti(dokumenti dokumenti) { if (ModelState.IsValid) { db.dokumenti.Add(dokumenti); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, dokumenti); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = dokumenti.idDokumenta })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// PUT api/DokumentiApi/5 public HttpResponseMessage Putdokumenti(int id, dokumenti dokumenti) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != dokumenti.idDokumenta) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(dokumenti).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
public ActionResult Edit(dokumenti dokumenti) { if (ModelState.IsValid) { db.Entry(dokumenti).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.idOglasa = new SelectList(db.oglasi, "idOglasa", "nazivOglasa", dokumenti.idOglasa); return View(dokumenti); }