Exemplo n.º 1
0
        /// <summary>
        /// Deletes a todo item.
        /// </summary>
        /// <param name="userId">User id</param>
        /// <param name="itemId">Id of todo item to be deleted</param>
        /// <returns>True if delete was successful</returns>
        public bool DeleteItem(int userId, int itemId)
        {
            var existing = dbContext.TodoItems.FirstOrDefault(u => u.Id == userId && u.Id == itemId);

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

            dbContext.Remove(existing);
            dbContext.SaveChanges();
            return(true);
        }
Exemplo n.º 2
0
        public async Task <bool> RemoveAsync(Collection collection)
        {
            var entry = _database.Remove(collection);
            await _database.SaveChangesAsync();

            return(entry.State == EntityState.Detached);
        }
Exemplo n.º 3
0
        public async Task <bool> RemoveAsync(TodoItem item)
        {
            var entry = _database.Remove(item);
            await _database.SaveChangesAsync();

            return(entry.State == EntityState.Detached);
        }
Exemplo n.º 4
0
        public ActionResult <int> Delete(int id)
        {
            var todo = _context.Set <Todo>().FirstOrDefault(x => x.Id == id);

            _context.Remove(todo);
            return(_context.SaveChanges());
        }
Exemplo n.º 5
0
        public async Task <IActionResult> DeleteTaskAsync(int id)
        {
            Logger?.LogDebug("'{0}' has been invoked", nameof(DeleteTaskAsync));

            var response = new Response();

            try
            {
                var entity = await DbContext.GetTaskAsync(new Task(id));

                if (entity == null)
                {
                    return(NotFound());
                }

                DbContext.Remove(entity);
                await DbContext.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = "There was an internal error, please contact to technical support.";

                Logger?.LogCritical("There was an error on '{0}' invocation: {1}", nameof(DeleteTaskAsync), ex);
            }

            return(response.ToHttpResponse());
        }
        public async Task <IActionResult> Delete(int id)
        {
            TodoItem item;

            try
            {
                item = await _context.TodoItems.FirstAsync(i => i.Id == id);
            }
            catch
            {
                // Couldn't find the entity to delete; just return 404
                return(NotFound());
            }

            _context.Remove(item);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch
            {
                // Couldn't commit the delete; send a 500 response
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  "Unable to commit entity deletion to database."));
            }

            // RFC 2616 Section 9.7 states that DELETE with no entity included within
            // the response should use the 204 code.
            return(NoContent());
        }
    public async Task <bool> Delete(int Id)
    {
        var todo = await Find(Id);

        _context.Remove(todo);
        await _context.SaveChangesAsync();

        return(true);
    }
Exemplo n.º 8
0
        public void Remove(int id)
        {
            var todo = _context.Todos.Find(id);

            if (todo != null)
            {
                _context.Remove(todo);
                _context.SaveChanges();
            }
        }
Exemplo n.º 9
0
        private async Task UpdateTodoTags(TodoItem item, IEnumerable <string> tags)
        {
            var existingTags = await _context.Tags
                               .Where(t => tags.Any(s => s == t))
                               .ToDictionaryAsync(t => t.Name);

            var existingMappings = item.TagsMapping?.ToDictionary(m => m.Tag.Name) ?? new Dictionary <string, TodoItemTag>();

            item.TagsMapping = tags
                               .Select(t =>
            {
                TodoItemTag result;
                if (existingMappings.TryGetValue(t, out result))
                {
                    return(result);
                }
                result = new TodoItemTag
                {
                    TodoItem = item
                };
                if (existingTags.TryGetValue(t, out Tag tag))
                {
                    result.Tag = tag;
                }
                else
                {
                    result.Tag = new Tag {
                        Name = t
                    };
                }
                return(result);
            })
                               .ToList();

            foreach (var mapping in existingMappings)
            {
                if (item.TagsMapping.All(x => x != mapping.Value))
                {
                    _context.Remove(mapping.Value);
                }
            }
        }
Exemplo n.º 10
0
        public async Task <bool> DeleteItemAsync(string id)
        {
            int count = 0;

            using (var context = new TodoDbContext())
            {
                var item = context.Items.Where(p => p.Id == id).FirstOrDefault();
                context.Remove <Item>(item);
                count = await context.SaveChangesAsync();
            }
            return(await Task.FromResult(count == 1));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> DeleteAsync(long id)
        {
            var entity = await _dbContext.TodoItems.SingleOrDefaultAsync(b => b.Id == id);

            if (entity == null)
            {
                return(NotFound());
            }

            _dbContext.Remove(entity);
            await _dbContext.SaveChangesAsync();

            return(Ok());
        }
Exemplo n.º 12
0
        public IActionResult DeleteList(int id, bool confirmed = false)
        {
            var todoList = _db.TodoLists
                           .Where(list => list.TodoListId == id)
                           .FirstOrDefault();

            if (!confirmed)
            {
                return(View(todoList));
            }

            _db.Remove(todoList);
            _db.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 13
0
        public async Task <ActionResult> Delete(int id)
        {
            var toDelete = await _context.TodoItems.FirstOrDefaultAsync(t => t.Id == id);

            if (toDelete != null)
            {
                _context.Remove(toDelete);
                await _context.SaveChangesAsync();

                return(NoContent());
            }
            else
            {
                return(NotFound());
            }
        }
Exemplo n.º 14
0
 public void Delete(Assignee element)
 {
     assigneeContext.Remove(element);
     assigneeContext.SaveChanges();
 }
Exemplo n.º 15
0
 public void Delete(T entity)
 {
     Context.Remove(entity);
     Save();
 }
Exemplo n.º 16
0
 public void Delete(Todo element)
 {
     toDoContext.Remove(element);
     toDoContext.SaveChanges();
 }