Exemple #1
0
        public async Task <object> DeleteProblem([FromRoute] int id)
        {
            try
            {
                if (id == 0)
                {
                    return(BadRequest("Missing id in route"));
                }
                var problem = await _dbContext.FindAsync <Problem>(id);

                if (problem == null)
                {
                    return(NotFound(new { errors = "Could not find problem object with specified id: " + id }));
                }
                var teamProblems = _dbContext.TeamProblems.Where(x => x.Problem.Id == id).ToList();

                teamProblems.ForEach(x => _dbContext.Remove <TeamProblems>(x));

                var deleted = _dbContext.Remove <Problem>(problem);
                var result  = await _dbContext.SaveChangesAsync();

                return(Ok(deleted.Entity));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }