Exemple #1
0
        public async Task <IActionResult> AddSize([FromBody] NewSizeDto newSize)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (await _sizeRepository.IsDuplicateSizeAsync(newSize))
                {
                    ModelState.AddModelError("size", "Size already exists");
                    return(BadRequest(ModelState));
                }

                var sizeId = await _sizeRepository.AddSizeAsync(newSize);

                if (sizeId > 0)
                {
                    return(Ok(sizeId));
                }

                return(StatusCode(500, "An error ocurred in server"));
            }
            catch (Exception e)
            {
                _logger.LogCritical($"POST {Route} - {e.GetType().Name} - {e.Message} - {e.StackTrace}");
                return(StatusCode(500, "An error ocurred in server"));
            }
        }