示例#1
0
        public static Brand ToBrand(this BrandToPutDto brand)
        {
            if (brand == null)
            {
                return(null);
            }

            return(new Brand
            {
                Id = brand.Id,
                Title = brand.Title,
                YearFounded = brand.YearFounded,
                Description = brand.Description
            });
        }
        public async Task <IActionResult> UpdateBrandAsync(long id, BrandToPutDto brandDto)
        {
            if (id != brandDto.Id)
            {
                throw new BadRequestException($"Brand id {brandDto.Id} does not match the id in the route: {id}.", "id");
            }
            if (brandDto.Id == default(long))
            {
                throw new BadRequestException($"Brand id cannot be 0.", "id");
            }

            var updated = await _brandRepository.UpdateBrandAsync(brandDto.ToBrand());

            if (!updated)
            {
                return(NotFound($"Brand with id {id} cannot be found."));
            }
            return(NoContent());
        }