Beispiel #1
0
        public async Task <IActionResult> AddBrand([FromBody] NewBrandDto newBrand)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (await _brandRepository.IsDuplicateBrandAsync(newBrand))
                {
                    ModelState.AddModelError("brand", "Brand already exists");
                    return(BadRequest(ModelState));
                }

                var brandId = await _brandRepository.AddBrandAsync(newBrand);

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

                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"));
            }
        }
Beispiel #2
0
        public async Task <BrandResponseObject> AddBrandAsync(BrandRequestObject brand)
        {
            var result = await _brandRepository.AddBrandAsync(_mapper.Map <Brand>(brand));

            return(result != null?_mapper.Map <BrandResponseObject>(result) : null);
        }