public IHttpActionResult PostPrekes(Prekes prekes) { prekes.PrekesId = Guid.NewGuid(); prekes.GaliojimoPabaiga = DateTime.Now.AddDays(2); prekes.KiekPerku = 1; if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Prekes.Add(prekes); try { db.SaveChanges(); } catch (DbUpdateException) { if (PrekesExists(prekes.PrekesId)) { return Conflict(); } else { throw; } } var a = CreatedAtRoute("DefaultApi", new { id = prekes.PrekesId }, prekes); return a; }
public IHttpActionResult PutPrekes(Guid id, Prekes prekes) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != prekes.PrekesId) { return BadRequest(); } db.Entry(prekes).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PrekesExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }