/// <summary> /// Updates a subtask-item in the data context. /// </summary> /// <param name="item">Item to update.</param> /// <returns>Success value.</returns> public async Task <bool> UpdateSubtask(SubtaskViewModel item) { using (var context = new TolldoDbContext()) { // Get item to update var itemToUpdate = await context.Subtasks.Where(i => i.Id == item.Id).FirstOrDefaultAsync(); _mapper.Map(item, itemToUpdate); if (itemToUpdate == null) { return(false); } // Update item in database context.Update(itemToUpdate); return(await context.SaveChangesAsync() > 0 ? true : false); } }
/// <summary> /// Updates a todo-item in the data context. /// </summary> /// <param name="item">Item to update.</param> /// <returns>Success value.</returns> public async Task <bool> UpdateTodo(TodoViewModel item) { using (var context = new TolldoDbContext()) { // Get item to update var itemToUpdate = await context.Todos.Where(i => i.Id == item.Id).FirstOrDefaultAsync(); _mapper.Map(item, itemToUpdate); if (itemToUpdate == null) { return(false); } // Update item in database itemToUpdate.Tasks = null; context.Update(itemToUpdate); // Ignore tasks context.Entry(itemToUpdate).Collection(x => x.Tasks).IsModified = false; return(await context.SaveChangesAsync() > 0 ? true : false); } }