Ejemplo n.º 1
0
        public async Task <IActionResult> DeleteCodeId(int id)
        {
            var Response = new SingleResponse <Code>();

            try
            {
                if (!_ICodeRepository.DoesCodeExist(id))
                {
                    Response.DidError = true;
                    Response.Message  = $"The Code with the id: {id} was not found in the database.";
                    _Logger.LogError(ControllerContext, Response.Message);
                }
                else
                {
                    Code CodeToDelete = await _ICodeRepository.GetCodeByIdDefaultAsync(id);

                    await _ICodeRepository.DeleteCodeAsync(CodeToDelete);

                    Response.Message = $"Querying code with the id: {CodeToDelete.CodeId} to delete.";
                    Response.Model   = CodeToDelete;
                    _Logger.LogInfo(ControllerContext, $"Code with the id: {CodeToDelete.CodeId} has been deleted.");
                }
            }
            catch (Exception ex)
            {
                Response.DidError = true;
                Response.Message  = "Internal Server Error.";
                _Logger.LogError(ControllerContext, $"Error Message: {ex.Message}");
            }
            return(Response.ToHttpResponse());
        }