public void Update(int idUser, NoteModel noteModel) { var note = Find(idUser, noteModel.NoteId); if (note != null) { note.NoteName = noteModel.NoteName; note.NoteText = noteModel.NoteText; note.Image = noteModel.Image; note.Update = DateTime.Now; _db.Entry(note).State = EntityState.Modified; _db.SaveChanges(); } }
public async Task <IActionResult> PutNote([FromRoute] string id, [FromBody] Note note) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != note.Title) { return(BadRequest()); } _context.Entry(note).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NoteExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void TestPUT() { ClearDB(); Note tmpNote = new Note(); tmpNote.Text = "TestnotePUTOriginal"; var actionResult0 = _controller.PostNote(tmpNote); var createdAtActionResult = actionResult0.Result as CreatedAtActionResult; var oritinalNote = createdAtActionResult.Value as Note; Note modifiedNote = new Note(); modifiedNote.Text = "TestnotePUTModified"; modifiedNote.ID = oritinalNote.ID; var actionResult1 = _controller.PutNote(oritinalNote.ID, modifiedNote); _context.Entry(tmpNote).Reload(); var actionResult2 = _controller.GetNote(oritinalNote.ID); var okObjectResult = actionResult2.Result as OkObjectResult; var modifiedNoteFromGet = okObjectResult.Value as Note; Assert.Equal(modifiedNote.Text, modifiedNoteFromGet.Text); ClearDB(); }
/// <summary> /// Deletes the note. /// </summary> /// <param name="UserID">The user identifier.</param> /// <param name="noteID">The note identifier.</param> /// <returns></returns> public bool DeleteNote(long UserID, long noteID) { try { if (NotesDB.Notes.Any(n => n.NoteId == noteID && n.UserId == UserID)) { var note = NotesDB.Notes.Find(noteID); if (note.IsTrash) { NotesDB.Entry(note).State = EntityState.Deleted; } else { note.IsTrash = true; note.IsPin = false; note.IsArchive = false; } NotesDB.SaveChanges(); return(true); } return(false); } catch (Exception) { throw; } }
public IHttpActionResult PutNote(int id, Note note) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != note.Id) { return(BadRequest()); } db.Entry(note).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!NoteExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> PutCategory([FromRoute] int id, [FromBody] Category category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != category.ID) { return(BadRequest()); } _context.Entry(category).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutNote(int id, Note note) { if (id != note.IdNote) { return(BadRequest()); } _context.Entry(note).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NoteExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public static void SaveNote(Note note) { using (var context = new NotesContext()) { context.Entry(note).State = EntityState.Modified; context.SaveChanges(); } }
public ActionResult Edit([Bind(Include = "ID,DueDate,DueTime,HomeworkTitle,Priority,Department,CourseNumber,Notes")] HWnotes hWnotes) { if (ModelState.IsValid) { db.Entry(hWnotes).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(hWnotes)); }
public ActionResult Edit([Bind(Include = "ID,Title,Text,Now")] Notes notes) { if (ModelState.IsValid) { db.Entry(notes).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(notes)); }
public ActionResult Edit([Bind(Include = "FeaturedJamID,Title,Author,DatePublished,Content")] FeaturedJam featuredJam) { if (ModelState.IsValid) { db.Entry(featuredJam).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(featuredJam)); }
public ActionResult Edit([Bind(Include = "ID,Category")] Group group) { if (ModelState.IsValid) { db.Entry(group).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(group)); }
public ActionResult Edit([Bind(Include = "NoteId,NoteBody")] Note note) { if (ModelState.IsValid) { db.Entry(note).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(note)); }
public void Update(Notes notes) { using (notesContext = new NotesContext()) { var item = notesContext.Notes.Find(notes.Id); if (item != null) { notesContext.Entry(item).CurrentValues.SetValues(notes); notesContext.SaveChanges(); } } }
public void Edit(UserProfile user) { try { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } catch (Exception ex) { throw ex; } }
public void Edit(Note note) { try { db.Entry(note).State = EntityState.Modified; db.SaveChanges(); } catch (Exception ex) { throw ex; } }
public bool Update(int id, Note note) { try { note.Id = id; _context.Entry(note).State = EntityState.Modified; _context.SaveChanges(); return(true); } catch (System.Exception) { return(false); } }
public async Task <IActionResult> PutNote(int id, Note note) { if (id != note.IdNote) { return(BadRequest()); } if (!NoteExists(id) || !NoteHistoryExists(id)) { return(NotFound()); } try { var version = await _context.NoteHistories.Where(n => n.IdNote == id).MaxAsync(n => n.Version); var noteHistory = await _context.NoteHistories.FindAsync(id, version); ++version; _context.NoteHistories.Add(new NoteHistory { IdNote = note.IdNote, Version = version, Title = note.Title, Content = note.Content, Created = noteHistory.Created }); await _context.SaveChangesAsync(); noteHistory = await _context.NoteHistories.FindAsync(id, version); note.Created = noteHistory.Created; note.Modified = DateTime.Now; _context.Entry(note).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NoteExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Put([FromBody] Note note) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Entry(note).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(NoContent()); }
public bool ResetAccountPassword(ResetPasswordModel user) { try { var NewPassword = passwordEncryption.EncryptPassword(user.NewPassword); var LoginUser = UserDB.UserAccounts.FirstOrDefault(u => u.Email.Equals(user.Email)); if (user != null) { LoginUser.Password = NewPassword; UserDB.Entry(LoginUser).Property(x => x.Password).IsModified = true; UserDB.SaveChanges(); return(true); } } catch (Exception) { throw; } return(false); }
// PUT api/Note/5 public HttpResponseMessage PutNote(int id, Note note) { if (ModelState.IsValid && id == note.Id) { db.Entry(note).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
public async Task <IActionResult> PutNotes([FromRoute] int id, [FromBody] Notes notes) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != notes.ID) { return(BadRequest()); } var user = _context.Users.Find(notes.User.ID); var category = _context.Categories.Find(notes.Category.ID); notes.User = user; notes.Category = category; _context.Entry(notes).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NotesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutManagedNotes(long id, ManagedNotesDTO managedNotesDTO) { if (id != managedNotesDTO.Id) { return(BadRequest()); } var managedNotes = await _context.Notes.FindAsync(id); if (managedNotes == null) { return(NotFound()); } managedNotes.IsComplete = managedNotesDTO.IsComplete; managedNotes.Name = managedNotesDTO.Name; _context.Entry(managedNotes).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ManagedNotesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public virtual void Add(T entity) { EntityEntry dbEntityEntry = _context.Entry <T>(entity); _context.Set <T>().Add(entity); }