public async Task <IActionResult> CreateColorAsync([FromBody] CreateColorModel createColorModel)
        {
            if (await _product.CreateColorAsync(createColorModel))
            {
                return(new OkObjectResult($"{createColorModel.ColorName} Created Successfully"));
            }

            return(new BadRequestObjectResult($"{createColorModel.ColorName} Unable too Create {createColorModel.ColorHex}"));
        }
Esempio n. 2
0
        public async Task <bool> CreateColorAsync(CreateColorModel createColorModel)
        {
            if (!_context.Colors.Any(color => color.ColorName == createColorModel.ColorName))
            {
                try
                {
                    var color = new Color()
                    {
                        ColorName = createColorModel.ColorName,
                        ColorHex  = createColorModel.ColorHex
                    };

                    _context.Colors.Add(color);
                    await _context.SaveChangesAsync();

                    return(true);
                }
                catch
                {
                }
            }
            return(false);
        }