Example #1
0
        /// <summary>
        /// Deletes a subtask-item from the data context.
        /// </summary>
        /// <param name="item">Item to delete.</param>
        /// <returns>Success value.</returns>
        public async Task <bool> DeleteSubtask(SubtaskViewModel item)
        {
            using (var context = new TolldoDbContext())
            {
                // Get item to remove
                var itemToRemove = await context.Subtasks.Where(i => i.Id == item.Id).FirstOrDefaultAsync();

                if (itemToRemove == null)
                {
                    return(false);
                }

                // Remove item from database
                context.Remove(itemToRemove);
                return(await context.SaveChangesAsync() > 0 ? true : false);
            }
        }