Exemplo n.º 1
0
        public async Task <IActionResult> UpdateByIdAsync(
            [FromRoute, SwaggerParameter("Id of Colour to update", Required = true)] int colourId,
            [FromBody, SwaggerRequestBody("Colours to update", Required = true)] ColoursItem coloursItemUpdate)
        {
            if (colourId < 0 || colourId > 1000)
            {
                return(UnprocessableEntity(new ProblemDetails {
                    Status = 422, Title = "Unprocessable Entity - {id} must be between 0 and 1000"
                }));
            }
            if (coloursItemUpdate.Name == null || coloursItemUpdate.Name.Length == 0)
            {
                return(UnprocessableEntity(new ProblemDetails {
                    Status = 422, Title = "Unprocessable Entity - Needs a Colour Name"
                }));
            }
            if (coloursItemUpdate.Id != colourId)
            {
                return(UnprocessableEntity(new ProblemDetails {
                    Status = 422, Title = "Unprocessable Entity - payload Id doesnt match {colourId}"
                }));
            }

            ColoursItem coloursItemReturn = await _ColoursService.UpdateById(colourId, coloursItemUpdate);

            return(Created("Colours/" + colourId, coloursItemReturn));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetByNameAsync(
            [FromQuery, SwaggerParameter("Name of Colour to return", Required = true)] string colourName)
        {
            ColoursItem _ColoursItem = await _ColoursService.GetByName(colourName);

            if (_ColoursItem == null)
            {
                return(NotFound(new ProblemDetails {
                    Status = 404, Title = "Not Found - {colourName}: " + colourName
                }));
            }

            return(Ok(_ColoursItem));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetByIdAsync(
            [FromRoute, SwaggerParameter("Id of Colour to return", Required = true)] int colourId)
        {
            if (colourId < 1 || colourId > 1000)
            {
                return(UnprocessableEntity(new ProblemDetails {
                    Status = 422, Title = "{colourId} must be between 1 and 1000"
                }));
            }

            ColoursItem _ColoursItem = await _ColoursService.GetById(colourId);

            if (_ColoursItem == null)
            {
                return(NotFound(new ProblemDetails {
                    Status = 404, Title = "Not Found - {colourId}: " + colourId
                }));
            }

            return(Ok(_ColoursItem));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> UpdateAsync(
            [FromBody, SwaggerRequestBody("Colours to update", Required = true)] List <ColoursItem> coloursItems)
        {
            List <ColoursItem> _ColoursInserted = new() { };

            foreach (ColoursItem coloursItem in coloursItems) // Loop through List with foreach
            {
                if (coloursItem.Name == null || coloursItem.Name.Length == 0)
                {
                    return(UnprocessableEntity(new ProblemDetails {
                        Status = 422, Title = "Missing a Colour Name"
                    }));
                }

                ColoursItem coloursItemReturn = await _ColoursService.UpdateById(0, coloursItem);

                _ColoursInserted.Add(coloursItemReturn);
            }

            List <ColoursItem> _ColoursList = await _ColoursService.GetAll();

            return(Created("Colours/", _ColoursInserted));
        }