コード例 #1
0
        public void Delete(long id)
        {
            ToDo thing = context.ToDos.Single(c => c.Id == id);

            context.Remove(thing);
            context.SaveChanges();
        }
コード例 #2
0
        public async Task deleteTodoList(int userid, int todoListID)
        {
            var userexists = _toDoContext.Users.Where(a => a.ID == userid).First();
            var listexists = _toDoContext.TodoLists.Where(a => a.TodoListID == todoListID).First();

            if (userexists == null || listexists == null)
            {
                throw new Exception();
            }
            else
            {
                _toDoContext.Remove(listexists);
                await _toDoContext.SaveChangesAsync();
            }
        }
        public async Task DeleteAsync(int toDoId, CancellationToken ct = default(CancellationToken))
        {
            var toDoItem = await _uow.ToDoItems.SingleAsync(t => t.Id == toDoId, ct);

            _uow.Remove(toDoItem);
            await _uow.SaveChangesAsync(ct);
        }
コード例 #4
0
        public void DeleteToDo(int todoId)
        {
            var currToDo = context.ToDos.Where(t => t.Id == todoId).FirstOrDefault();

            context.Remove(currToDo);
            context.SaveChanges();
        }
コード例 #5
0
        public async Task <IActionResult> deleteList(int listId)
        {
            User user = await _context.users.Include(u => u.lists).FirstOrDefaultAsync(u => u.id == currentUser);

            if (user == default(User))
            {
                return(Json(new jsonResponse {
                    success = false, errMsg = "Invalid UID"
                }));
            }

            ToDoList list = await _context.lists.Include(l => l.items).FirstOrDefaultAsync(l => l.id == listId);

            if (list == default(ToDoList) && !user.lists.Contains(list))
            {
                return(Json(new jsonResponse {
                    success = false, errMsg = "List does not exist"
                }));
            }

            try {
                _context.Remove(list); // remove list - cascade delete removes items
                _context.SaveChanges();
            } catch {
                return(Json(new jsonResponse {
                    success = false, errMsg = "Failed to delete list"
                }));
            }

            return(Json(new jsonResponse {
                success = true
            }));
        }
コード例 #6
0
        public void Delete(long id)
        {
            ToDo thing = context.ToDos.FirstOrDefault(c => c.Id == id);

            context.Remove(thing);
            context.SaveChanges();
        }
コード例 #7
0
        public void DeleteToDo(int id)
        {
            var item = _context.ToDoItems.Find(id);

            _context.Remove(item);
            _context.SaveChanges();
        }
コード例 #8
0
 public void Remove(IBaseModel removedItem)
 {
     using (var context = new ToDoContext())
     {
         var deletedEntity = _mapper.Map <TodoItems>(removedItem);
         context.Remove(deletedEntity);
         context.SaveChanges();
     }
 }
コード例 #9
0
        public async Task <ActionResult> Delete(int Id)
        {
            //Console.WriteLine(Id);
            TodoList item = await context.ToDoLists.FindAsync(Id);

            context.Remove(item);
            await context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
コード例 #10
0
        public virtual async Task Delete <T>(int key) where T : class
        {
            T existing = _context.Set <T>().Find(key);

            if (existing != null)
            {
                _context.Remove(existing);
                await _context.SaveChangesAsync();
            }
        }
コード例 #11
0
 public void DeleteToDo(long id)
 {
     foreach (var item in toDoContext.ToDos)
     {
         if (item.Id == id)
         {
             toDoContext.Remove(item);
         }
     }
     toDoContext.SaveChanges();
 }
コード例 #12
0
        public async Task DeleteToDoItemByIdAsync(int id)
        {
            var item = await _toDoContext.ToDoItems.SingleOrDefaultAsync(item => item.Id == id);

            if (item == null)
            {
                throw new NotFoundException($"{id} does not exist");
            }

            _toDoContext.Remove(item);
            await _toDoContext.SaveChangesAsync();
        }
コード例 #13
0
        public IActionResult DeleteToDo(int id)
        {
            var toDo = _context.ToDos.FirstOrDefault(x => x.Id == id);

            if (toDo == null)
            {
                return(NotFound());
            }
            _context.Remove(toDo);
            _context.SaveChanges();

            return(NoContent());
        }
コード例 #14
0
ファイル: DataService.cs プロジェクト: dknewman/ToDoApp
        public static async Task DeleteToDoItem(ToDoItemModel toDoDelete)
        {
            try
            {
                await using var toDoContext = new ToDoContext();
                toDoContext.Remove(toDoDelete);
                await toDoContext.SaveChangesAsync();

                PostToDoItem(toDoContext);
            }
            catch (Exception ex)
            {
                //Handle exception - Typically I use a service like rollbar
                Debug.WriteLine(ex);
            }
        }
コード例 #15
0
        public async Task <ActionResult <ToDoItem> > DeleteTask(int id)
        {
            if (ModelState.IsValid)
            {
                var toDoItem = await _toDoContext.ToDoItems.FindAsync(id);

                _toDoContext.Remove(toDoItem);
                var output = await _toDoContext.SaveChangesAsync();

                if (output > 0)
                {
                    return(Ok("ToDo deleted successfully"));
                }
            }

            return(BadRequest("Some error happened"));
        }
コード例 #16
0
 public void Delete <T>(T entity) where T : class
 {
     _context.Remove(entity);
 }
コード例 #17
0
 public void DeleteToDo(int id)
 {
     _context.Remove(GetToDo(id));
 }