public Thing Map(CreateThingDto createThingDto, int userId) { return(new Thing() { Name = createThingDto.Name, Description = createThingDto.Description, Value = createThingDto.Value, CurrencyId = createThingDto.CurrencyId, CategoryId = createThingDto.CategoryId, UserId = userId, PlaceId = createThingDto.PlaceId }); }
public async Task <int> CreateThing(CreateThingDto createThingDto) { _logger.LogInformation("{class}.{method} with dto = [{@dto}] Invoked", nameof(ThingCommandService), nameof(CreateThing), createThingDto); var userGuid = _httpContextUserService.GetUserGuid(); var user = await _userRepository.GetByGuid(userGuid); var thing = _thingMappingService.Map(createThingDto, user.Id); _thingRepository.Add(thing); await _unitOfWork.Commit(); _logger.LogInformation("{entityName} with id = [{id}] has been created in local database", nameof(Thing), thing.Id); var @event = _thingMappingService.MapToThingCreatedEvent(thing); _eventBusPublisher.Publish(@event); _logger.LogInformation("{entityName} with id = [{id}] has been successfully created", nameof(Thing), thing.Id); return(thing.Id); }
public async Task <ActionResult <int> > CreateThing(CreateThingDto createThingDto) { return(StatusCode(201, await _thingCommandService.CreateThing(createThingDto))); }