Exemplo n.º 1
0
        public async Task <int> CreateAsync(CreateFabricCommand command)
        {
            var producer = await _context.Producers.FirstOrDefaultAsync(x => x.Id == command.ProducerId);

            if (producer == null)
            {
                throw new GfsException(ErrorCode.ProducerNotFound, _dictionary.ProducerNotFound);
            }

            var fabric = new Fabric
            {
                Thickness    = command.Thickness,
                Name         = command.Name,
                ImageUrl     = command.ImageUrl,
                ProducerCode = command.ProducerCode,
                Producer     = producer,
                ProducerId   = command.ProducerId
            };

            await _context.Fabrics.AddAsync(fabric);

            await _context.SaveChangesAsync();

            return(fabric.Id);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] CreateFabricCommand fabricCommand)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var result = await _fabricService.CreateAsync(fabricCommand);

            return(Ok(result.ToResponseDto()));
        }