예제 #1
0
 public ActionResult Edit([Bind(Include = "ID,Task")] Notepad notepad)
 {
     if (ModelState.IsValid)
     {
         db.Entry(notepad).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(notepad));
 }
        public async Task UpdateAllProperties()
        {
            //Arranges
            var existingNote = NoteBuilder.WithDefaultValues();

            _notePadContext.Notes.Add(existingNote);
            _notePadContext.SaveChanges();
            _output.WriteLine($"Note to update Id: {existingNote.Id}");
            var UpdateNote = NoteBuilder.UpdateTitleValue();

            UpdateNote.Id = existingNote.Id;
            _notePadContext.Entry(existingNote).State = EntityState.Detached;

            //Acts
            await _noteRepository.UpdateAsync(UpdateNote);

            var dbNote = _notePadContext.Notes.Find(existingNote.Id);

            //Asserts
            Assert.NotEqual(existingNote.Title, dbNote.Title);
        }
 public async Task UpdateAsync(T entity)
 {
     _dbContext.Entry(entity).State = EntityState.Modified;
     await _dbContext.SaveChangesAsync();
 }