public async Task <IActionResult> Delete(int id)
        {
            if (id == default)
            {
                return(BadRequest($"{id} is invalid"));
            }

            try
            {
                var entity = new Post {
                    Id = id
                };
                _appDataContext.Attach(entity);
                _appDataContext.Remove(entity);
                var result = await _appDataContext.SaveChangesAsync();

                if (result == 1)
                {
                    return(Ok($"{id} deleted successfully"));
                }
            }
            catch (Exception)
            {
                // log error
            }

            return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
        }
예제 #2
0
        public void deleteUser(int userID)
        {
            /*var userChannels = (from c in _db.ChannelUsers
             *                  where username == c.userID
             *                  select c);
             */
            User usr = (from u in _db.Users
                        where userID == u.id
                        select u).SingleOrDefault();
            Token userToken = (from t in _db.Tokens
                               where userID == t.userID
                               select t).SingleOrDefault();

            _db.Remove(userToken);
            _db.Remove(usr);
            _db.SaveChanges();
        }
        /// <summary>
        /// Method for deleting category.
        /// </summary>
        public void Delete(int id)
        {
            Category category = context.Categories.Find(id);

            if (category != null)
            {
                context.Remove(category);
            }
        }
예제 #4
0
        public async Task DeleteSavingsDepositAsync(string userId, int entityId)
        {
            var result = await _context.SavingsDeposits.Where(x => x.Id == entityId).FirstOrDefaultAsync();

            if (result == null)
            {
                throw new NotFoundException("");
            }

            if (result.Owner == userId)
            {
                _context.Remove(result);
                await _context.SaveChangesAsync();
            }
            else
            {
                throw new NotAuthorizedException("User cannot remove this record");
            }
        }
        public void Remove(int Id)
        {
            var itemToRemove = _context.Candidatos.Include(x => x.VagasCandidato).First(c => c.CanditadoId == Id);

            if (itemToRemove != null)
            {
                _context.Remove(itemToRemove);
                _context.SaveChanges();
            }
            else
            {
                throw new System.Exception("Record not found");
            }
        }
예제 #6
0
        /// <inheritdoc />
        /// <exception cref="TodoNotFoundException">When todo is not found</exception>
        public async Task RemoveTodoByIdAsync(int todoId, string userId)
        {
            var todo = await _db.Todo.SingleOrDefaultAsync(t => t.Id == todoId && t.Owner.Id == userId);

            if (todo == null)
            {
                throw new TodoNotFoundException();
            }
            _db.Remove(todo);
            await _db.SaveChangesAsync();

            // Clear all related caches
            _cache.Remove(CacheConstants.GetSingleTodoCacheKey(todoId, userId));
            _cache.Remove(CacheConstants.GetAllTodosCacheKey(userId));
            _cache.Remove(CacheConstants.GetAllTodosForDayCacheKey(userId, todo.Due));
        }
예제 #7
0
        public async Task <Unit> Handle(DeleteOneCommand request, CancellationToken cancellationToken)
        {
            var serie = await _context.Series.FindAsync(request.Id);

            if (serie == null)
            {
                throw new SerieNotFoundException(request.Id);
            }

            _context.Remove(serie);

            var success = await _context.SaveChangesAsync() > 0;

            if (success)
            {
                return(Unit.Value);
            }

            throw new Exception("Problem saving changes.");
        }
            public async Task <Unit> Handle(Client request, CancellationToken cancellationToken)
            {
                var client = await _context.DealerInfos.FindAsync(request.Id);

                if (client == null)
                {
                    throw new Exception("Dealer info not found");
                }

                _context.Remove(client);

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving changes");
            }
예제 #9
0
        public async Task <Unit> Handle(DeleteOneEditionCommand request, CancellationToken cancellationToken)
        {
            var bookEdition = await _context.BookEditions.FindAsync(request.Isbn);

            if (bookEdition == null)
            {
                throw new BookEditionNotFoundException(request.Isbn);
            }

            _context.Remove(bookEdition);

            var success = await _context.SaveChangesAsync() > 0;

            if (success)
            {
                return(Unit.Value);
            }

            throw new Exception("Problem saving changes.");
        }
예제 #10
0
 public void Delete(T entity)
 {
     _context.Remove(entity);
     Save();
 }
예제 #11
0
 public void Delete <T>(T entity) where T : class
 {
     _data.Remove(entity);
 }
예제 #12
0
        public void Excluir(int Id)
        {
            T cliente = Get(Id);

            _db.Remove(cliente);
        }
예제 #13
0
        public void Excluir(int Id)
        {
            Colaborador cliente = Get(Id);

            _db.Remove(cliente);
        }
        public void Excluir(int Id)
        {
            Cliente cliente = GetCliente(Id);

            _db.Remove(cliente);
        }