Exemplo n.º 1
0
        public async Task <ActionResult> DeleteAsync(int id)
        {
            if (!ModelState.IsValid || id < 1)
            {
                return(BadRequest());
            }
            try
            {
                var exist = await service.GetByIdAsync(id);

                if (exist != null)
                {
                    var result = await service.DeleteAsync(id);

                    return(result ? Ok(new Response {
                        Status = true, Description = "Record deleted successfully"
                    })
                        : StatusCode(500, new Response {
                        Status = false, Description = "Error deleting the record"
                    }));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
                return(StatusCode(500, new Response()
                {
                    Status = false, Description = "System error"
                }));
            }
        }