Beispiel #1
0
 public void Map(UpdateThingDto updateThingDto, Thing thing)
 {
     thing.Name        = string.IsNullOrEmpty(updateThingDto.Name) ? thing.Name : updateThingDto.Name;
     thing.Description = string.IsNullOrEmpty(updateThingDto.Description) ? thing.Description : updateThingDto.Description;
     thing.Value       = updateThingDto.Value ?? thing.Value;
     thing.CurrencyId  = updateThingDto.CurrencyId ?? thing.CurrencyId;
     thing.CategoryId  = updateThingDto.CategoryId ?? thing.CategoryId;
     thing.PlaceId     = updateThingDto.PlaceId ?? thing.PlaceId;
 }
Beispiel #2
0
        public async Task UpdateThing(int id, UpdateThingDto updateThingDto)
        {
            _logger.LogInformation("{class}.{method} with id = [{id}] Invoked", nameof(ThingCommandService), nameof(UpdateThing), id);

            var userGuid = _httpContextUserService.GetUserGuid();
            var thing    = await _thingRepository.GetById(id, userGuid);

            if (thing is null || thing.Deleted)
            {
                throw new EntityNotFoundException <Thing>($"Id = [{id}]");
            }

            _thingMappingService.Map(updateThingDto, thing);
            await _unitOfWork.Commit();

            _logger.LogInformation("{entityName} with id = [{id}] has been updated in local database", nameof(Thing), thing.Id);

            var @event = _thingMappingService.MapToThingUpdatedEvent(thing);

            _eventBusPublisher.Publish(@event);

            _logger.LogInformation("{entityName} with id = [{id}] has been successfully updated", nameof(Thing), thing.Id);
        }
Beispiel #3
0
        public async Task <ActionResult <int> > Put(int id, UpdateThingDto updateThingDto)
        {
            await _thingCommandService.UpdateThing(id, updateThingDto);

            return(NoContent());
        }