예제 #1
0
        public IActionResult SaveChanges(ToDoList updatedItem)
        {
            ToDoList originalItem = _context.ToDoList.Find(updatedItem.ToDoId);

            originalItem.ToDoDesc     = updatedItem.ToDoDesc;
            originalItem.ToDoDue      = updatedItem.ToDoDue;
            originalItem.ToDoComplete = updatedItem.ToDoComplete;

            _context.Entry(originalItem).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            _context.Update(originalItem);
            _context.SaveChanges();

            return(RedirectToAction("ToDoItemList"));
        }
예제 #2
0
        public async Task UpdateTodoAsync(ToDoItem updatedItem)
        {
            var todo = await _dbContext.ToDos.Where(item => item.Id == updatedItem.Id).FirstOrDefaultAsync();

            if (todo == null)
            {
                throw new InvalidOperationException("Todo not found.");
            }
            todo.Text = updatedItem.Text;
            if (updatedItem.IsCompleted.HasValue)
            {
                todo.IsCompleted = updatedItem.IsCompleted;
            }
            if (todo.IsCompleted.Value)
            {
                todo.Completed = DateTime.UtcNow;
            }
            _dbContext.Update(todo);
            await _dbContext.SaveChangesAsync();
        }