Beispiel #1
0
        public async Task <Producer> UpdateProducerAsync(
            [GraphQLType(typeof(UpdateProducerInputType))][GraphQLName("input")]
            UpdateProducerCommand input, [Service] ISheaftMediatr mediatr,
            ProducersByIdBatchDataLoader producersDataLoader, CancellationToken token)
        {
            await ExecuteAsync(mediatr, input, token);

            return(await producersDataLoader.LoadAsync(input.ProducerId, token));
        }
Beispiel #2
0
        public async Task <IActionResult> Put([FromBody] UpdateProducerCommand producerCommand, int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            producerCommand.Id = id;

            await _producerService.UpdateAsync(producerCommand);

            return(Ok(ResponseDto.Default));
        }
        public async Task UpdateAsync(UpdateProducerCommand command)
        {
            var producer = await _context.Producers
                           .FirstOrDefaultAsync(x => x.Id == command.Id);

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

            producer.Name        = command.Name;
            producer.City        = command.City;
            producer.Street      = command.Street;
            producer.Email       = command.Email;
            producer.PhoneNumber = command.PhoneNumber;

            await _context.SaveChangesAsync();
        }