Example #1
0
        public HttpResponseMessage DeleteItem(int id)
        {
            _todoItemsRepo.Delete(id);
            var response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);
        }
        public void Delete(int id)
        {
            var todoItem = repository.Get(a => a.Id == id).FirstOrDefault();

            if (todoItem != null)
            {
                repository.Delete(todoItem);
            }
        }
        public async Task WillDeleteExistingItem()
        {
            // Arrange
            var item = new TodoItem
            {
                Name       = "test delete",
                IsComplete = false
            };

            var addedItem = await sut.Create(item);

            // Act
            await sut.Delete(addedItem.Key);

            var items = await sut.GetAll();

            // Assert
            Assert.IsFalse(items.Any(x => x.Key == item.Key));
        }
Example #4
0
        public OperationDetails DeleteTodoItem(TodoItemDTO todoItem)
        {
            TodoItemEntity todoItemEntity = _todoItemRepository.GetTodoItemById(todoItem.Id);

            if (todoItemEntity != null)
            {
                _todoItemRepository.Delete(todoItemEntity);
                db.Commit();
                return(new OperationDetails(true, "TodoItem успешно удален", ""));
            }
            return(new OperationDetails(false, "todoItem, который должен быть удален отсутствует", "Id"));
        }
Example #5
0
        public TodoItemMutation(ITodoItemRepository repo)
        {
            this.repo = repo;

            Field <TodoItemType>(
                "addTodo",
                description: "Adds a todo to the database",
                arguments: new QueryArguments
            {
                new QueryArgument <TodoItemInputType>()
                {
                    Name = "todo"
                }
            },
                resolve: context =>
            {
                var task = context.GetArgument <TodoItem>("todo");
                return(repo.Add(task));
            }
                );

            Field <TodoItemType>(
                "updateTodo",
                description: "Updates a todo in the database",
                arguments: new QueryArguments
            {
                new QueryArgument <TodoItemInputType>()
                {
                    Name = "todo"
                }
            },
                resolve: context =>
            {
                return(repo.Update(context.GetArgument <TodoItem>("todo")));
            }
                );

            Field <BooleanGraphType>(
                "deleteTodo",
                description: "Deletes a todo from the database",
                arguments: new QueryArguments
            {
                new QueryArgument <StringGraphType>()
                {
                    Name = "todoId"
                }
            },
                resolve: context =>
            {
                return(repo.Delete(context.GetArgument <string>("todoId")));
            }
                );
        }
        public async Task DeleteTodoItem(long todoItemId)
        {
            var existingValue = await _todoItemRepository.GetById(todoItemId);

            if (existingValue == null)
            {
                return;
            }

            _todoItemRepository.Delete(existingValue);

            await _todoUnitOfWork.SaveChanges();
        }
Example #7
0
        public async Task Delete(TodoItem item)
        {
            if (string.IsNullOrEmpty(item.Key))
            {
                throw new ArgumentNullException("key cannot be null");
            }

            try
            {
                await todoItemRepository.Delete(item.Key);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Example #8
0
        public TodoModule(ITodoItemRepository repository)
            : base("/todo")
        {
            Get["/", true] = async (_, ct) => await repository.GetAll();

            Post["/", true] = async (_, ct) =>
            {
                var item = this.Bind<TodoItem>();

                await repository.Store(item);

                return Negotiate.WithModel(item).WithStatusCode(HttpStatusCode.Created);
            };

            Put["/{id*}", true] = async (args, ct) =>
            {
                string id = args.id;

                var item = await repository.GetById(id);
                if (item == null)
                {
                    return HttpStatusCode.NotFound;
                }

                var newItem = this.Bind<TodoItem>();

                item.Title = newItem.Title;
                item.IsCompleted = newItem.IsCompleted;

                return item;
            };

            Delete["/{id*}", true] = async (args, ct) =>
            {
                string id = args.id;

                var item = await repository.GetById(id);
                if (item == null)
                {
                    return HttpStatusCode.NotFound;
                }

                repository.Delete(item);

                return HttpStatusCode.OK;
            };
        }
Example #9
0
        public async Task <JsonResult> Delete(int id)
        {
            var itemToDelete = await _todoRepo
                               .Read(i => i.Id == id)
                               .FirstOrDefaultAsync();

            if (itemToDelete == null)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(Json($"No item was found with an id of {id}"));
            }
            else
            {
                _todoRepo.Delete(itemToDelete);
                await _unitOfWork.SaveChangesAsync();
            }

            return(Json($"The item with the id of {id} was deleted"));
        }
        public async Task <ActionResult> Delete(int id)
        {
            TodoItem todoItem = await _todoItemRepository.GetTodoById(id);

            if (todoItem is null)
            {
                return(NotFound());
            }

            int userId = int.Parse(User.Identity.Name);

            if (todoItem.UserId != userId)
            {
                return(Forbid());
            }

            await _todoItemRepository.Delete(id);

            return(NoContent());
        }
Example #11
0
        public async Task <IActionResult> DeleteConfirmed(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var todoItem = await _todoItemRepo
                           .Read(item => item.Id == id)
                           .SingleOrDefaultAsync();

            if (todoItem == null)
            {
                return(NotFound());
            }
            else
            {
                _todoItemRepo.Delete(todoItem);
                await _unitOfWork.SaveChangesAsync();
            }

            return(RedirectToAction("Index"));
        }
Example #12
0
 public void Remove(TodoItem todoItem)
 {
     _todoItemRepo.Delete(todoItem);
 }
Example #13
0
 public IActionResult Delete(int id)
 {
     _todoItemRepository.Delete(id);
     return(Redirect("/Main/Index"));
 }
Example #14
0
 public async Task Delete(int id)
 {
     await _todoItemRepository.Delete(id);
 }
Example #15
0
 public void Delete(int id)
 {
     _repository.Delete(x => x.Id.Equals(id));
 }
Example #16
0
        public async Task <bool> Delete(Guid id)
        {
            await _repository.Delete(id).ConfigureAwait(false);

            return(await _unitOfWork.Save().ConfigureAwait(false));
        }
Example #17
0
 public async Task DeleteItemAsync(ToDoItem toDoItem)
 {
     todoItemRepository.Delete(toDoItem);
     await todoItemRepository.SaveAsync();
 }
Example #18
0
        public async Task <ActionResult> DeleteTodo(string todoId)
        {
            await repo.Delete(todoId);

            return(NoContent());
        }
 public Task DeleteTodoItem(int todoItemId)
 {
     return(_todoItemRepository.Delete(todoItemId));
 }
Example #20
0
 public async Task Delete(Guid id)
 {
     await _Repository.Delete(id);
 }