Exemplo n.º 1
0
 //unos nove pjesme
 public HttpResponseMessage Post(Playlista playlista)
 {
     if (ModelState.IsValid)
     {
         db.Playlista.Add(playlista);
         db.SaveChanges();
         HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, playlista);
         response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = playlista.IDPlayliste }));
         return response;
     }
     else
     {
         return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
     }
 }
Exemplo n.º 2
0
 //ažuriranje pjesme
 public HttpResponseMessage Put(int id, Playlista playlista)
 {
     if (!ModelState.IsValid)
     {
         return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
     }
     if (id != playlista.IDPlayliste)
     {
         return Request.CreateResponse(HttpStatusCode.BadRequest);
     }
     db.Entry(playlista).State = EntityState.Modified;
     try
     {
         db.SaveChanges();
     }
     catch (DbUpdateConcurrencyException ex)
     {
         return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
     }
     return Request.CreateResponse(HttpStatusCode.OK);
 }