//PUT: api/Notes/PutNote/1 public IHttpActionResult PutNote(int id, PutNoteDto dto) { if (id != dto.Id) { return(BadRequest()); } var note = db.Notes.Find(id); if (note == null) { return(NotFound());//hata döndürüyor 404 status kodları farklı } if (note.AuthorId != User.Identity.GetUserId()) { return(Unauthorized());//değiştirmek istediğin yazı sana ait mi değilse yetkin yok demesi lazım status 401 } if (ModelState.IsValid) { note.Title = dto.Title; note.Content = dto.Content; note.ModifiedTime = DateTime.Now; db.SaveChanges(); return(Ok(note.ToGetNoteDto())); } return(BadRequest(ModelState)); }
//put: api/Notes/PutNote/1 public IHttpActionResult PutNote(int id, PutNoteDto dto) { if (id != dto.Id) { return(BadRequest()); } var note = db.Notes.Find(id); if (note == null) { return(NotFound()); } if (note.AuthorId != User.Identity.GetUserId()) { return(Unauthorized()); } if (ModelState.IsValid) { note.Title = dto.Title; note.Content = dto.Content; note.ModifiedTime = DateTime.Now; db.SaveChanges(); return(Ok(note.ToGetNoteDto())); } return(BadRequest(ModelState)); }
public IHttpActionResult PutNote(int id, PutNoteDto dto) { if (id != dto.Id) { return(BadRequest()); } if (ModelState.IsValid) { var note = db.Notes.Find(id); note.Title = dto.Title; note.Content = dto.Content; note.ModifiedTime = DateTime.Now; db.SaveChanges(); return(Ok(note.ToGetNoteDto())); } return(BadRequest(ModelState)); }