コード例 #1
0
        public async Task <IActionResult> Delete(int id)
        {
            var result = _context.ToDos.FirstOrDefault(t => t.ID == id);

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

                return(Ok());
            }
            return(BadRequest());
        }
コード例 #2
0
        public IActionResult Delete(int id)
        {
            using (var db = new ToDoDbContext())
            {
                Task taskDelete = db.Tasks.FirstOrDefault(t => t.Id == id);

                if (taskDelete == null)
                {
                    return(RedirectToAction("Index"));
                }

                db.Remove(taskDelete);
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
コード例 #3
0
        [HttpDelete("{id:int}")]  //- >>DELETE METHOD
        public async Task <IActionResult> Delete(int id, Todo todo)
        {
            /* Method for finding the and deleting to do by ID, as long as the Id is not null.
             *
             */

            var result = _context.Todos.FirstOrDefault(t => t.Id == id);

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

                return(Ok(result));
            }

            return(BadRequest(id));
        }
コード例 #4
0
ファイル: ToDoUserStore.cs プロジェクト: vietandy/ToDo
        public async Task <IdentityResult> DeleteAsync(User user, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            var userFromDb = await _context.User.FindAsync(user.Id);

            _context.Remove(userFromDb);
            var affectedRows = await _context.SaveChangesAsync(cancellationToken);

            return(affectedRows > 0
                ? IdentityResult.Success
                : IdentityResult.Failed(new IdentityError()
            {
                Description = $"Could not delete user {user.Username}."
            }));
        }
コード例 #5
0
ファイル: TaskRepository.cs プロジェクト: mugtea/todoapi
        public string Delete(int id)
        {
            var todoContext  = new ToDoDbContext();        //create instance dbcontext
            var existingData = GetTaskById(id);            //get contact by id

            if (existingData == null)                      //chec if null
            {
                return($@"Data with id { id } not found"); //return result
            }
            try
            {
                todoContext.Remove <Task>(existingData); //remove data
                todoContext.SaveChanges();               //commit save change
            }
            catch (Exception)
            {
                return("Failed remove data");   //return result
            }
            return("Successfully remove data"); //return result
        }