コード例 #1
0
ファイル: ThingMappingService.cs プロジェクト: Qtyb/Keeper
 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
     });
 }
コード例 #2
0
ファイル: ThingCommandService.cs プロジェクト: Qtyb/Keeper
        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);
        }
コード例 #3
0
 public async Task <ActionResult <int> > CreateThing(CreateThingDto createThingDto)
 {
     return(StatusCode(201, await _thingCommandService.CreateThing(createThingDto)));
 }