示例#1
0
        public async Task UpdateAsync(UpdateFabricCommand command)
        {
            var fabric = await _context.Fabrics.FirstOrDefaultAsync(x => x.Id == command.Id);

            if (fabric == null)
            {
                throw new GfsException(ErrorCode.FabricNotFound, _dictionary.FabricNotFound);
            }

            var producer = await _context.Producers.FirstOrDefaultAsync(x => x.Id == command.ProducerId);

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

            fabric.Thickness    = command.Thickness;
            fabric.Name         = command.Name;
            fabric.ImageUrl     = command.ImageUrl;
            fabric.ProducerCode = command.ProducerCode;
            fabric.ProducerId   = producer.Id;
            fabric.Producer     = producer;

            await _context.SaveChangesAsync();
        }
示例#2
0
        public async Task <IActionResult> Put([FromBody] UpdateFabricCommand fabricCommand, int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            fabricCommand.Id = id;

            await _fabricService.UpdateAsync(fabricCommand);

            return(Ok(ResponseDto.Default));
        }