示例#1
0
        public async Task HandleAsync(StorySent @event)
        {
            await _storiesService.AddAsync(new Story
            {
                Id     = @event.StoryId,
                Title  = @event.Title,
                Author = new Author
                {
                    Id   = @event.Author.Id,
                    Name = @event.Author.Name
                },
                CreatedAt = @event.CreatedAt,
                Tags      = @event.Tags
            });

            await _usersService.IncrementStoriesCountAsync(@event.Author.Id);

            foreach (var tag in @event.Tags)
            {
                var isNew = await _tagsService.TryAddAsync(new Tag
                {
                    Name           = tag,
                    OccurenceCount = 1
                });

                if (isNew)
                {
                    continue;
                }

                await _tagsService.IncrementOccurrencesCountAsync(tag);
            }
        }
示例#2
0
        public async Task <IActionResult> PostAsync([FromBody] StoryInputModel value)
        {
            if (value == null)
            {
                return(BadRequest("Invalid input"));
            }

            var result = await _storiesService.AddAsync(value);

            if (result == null)
            {
                return(BadRequest("Story not inserted"));
            }

            return(CreatedAtRoute("StoryGetAsync",
                                  new
            {
                id = result.Id
            },
                                  result));
        }