Ejemplo n.º 1
0
        private ActionResult <APIResponseWrapper <T> > InternalAPIResponse <T>(object result,
                                                                               int failureStatusCode = StatusCodes.Status500InternalServerError)
        {
            var apiResponse = new APIResponseWrapper <T>();

            if (result is ValidationResult validationResult)
            {
                apiResponse.Errors = validationResult.Errors;
                HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
            }
            else if (result is CommandResult commandResult)
            {
                apiResponse.Errors = commandResult.Errors;
                HttpContext.Response.StatusCode = commandResult.Success ? StatusCodes.Status200OK : failureStatusCode;
                apiResponse.IsComplete          = commandResult.Success ? true : false;
            }

            if (result is T data)
            {
                apiResponse.Data       = data;
                apiResponse.IsComplete = HttpContext.Response.StatusCode == StatusCodes.Status200OK ? true : false;
            }

            return(apiResponse);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <APIResponseWrapper <ItemDTO> > > GetItemById(int itemId)
        {
            var item = await itemBusinessLogic.GetItemById(itemId);

            if (item == null)
            {
                return(NotFound());
            }

            var itemDTO = item.ToDTO();

            return(APIResponseWrapper <ItemDTO> .StatusComplete(itemDTO));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <APIResponseWrapper <ItemDTO[]> > > GetAllItems()
        {
            var items = await itemBusinessLogic.GetAllItems();

            if (items == null)
            {
                return(NotFound());
            }

            var itemDTO    = items.Select(c => c.ToDTO()).ToArray();
            var itemResult = APIResponseWrapper <ItemDTO[]> .StatusComplete(itemDTO);

            return(itemResult);
        }