コード例 #1
0
        private void UpdateKeyword(EditContentCommand command)
        {
            var dbkeywords = _contentKeywordsQueryRepository.GetKeywordsId(command.Id);

            if (dbkeywords == null)
            {
                if (command.KeywordsId != null)
                {
                    foreach (var item in command.KeywordsId)
                    {
                        _contentKeywordsCommandRepository.Add(new ContentKeywords()
                        {
                            ContentId = command.Id,
                            KeywordId = item
                        });
                    }
                }
            }
            else
            {
                _contentKeywordsCommandRepository.RemoveKeywordsFromContent(command.Id);

                if (command.KeywordsId != null)
                {
                    foreach (var item in command.KeywordsId)
                    {
                        _contentKeywordsCommandRepository.Add(new ContentKeywords()
                        {
                            ContentId = command.Id,
                            KeywordId = item
                        });
                    }
                }
            }
        }
コード例 #2
0
        public override CommandResult Handle(AddContentCommand command)
        {
            if (IsValid(command))
            {
                var contentId = _contentCommandRepository.Add(new Content()
                {
                    CategoryId    = command.CategoryId,
                    ContentStatus = command.ContentStatus,
                    Description   = command.Description,
                    Body          = command.Body,
                    Title         = command.Title,
                    PublishDate   = command.PublishDate,
                    WriterId      = command.WriterId,
                    PhotoId       = command.PhotoId,
                    Rate          = command.Rate,
                });

                if (command.KeywordsId != null)
                {
                    foreach (var id in command.KeywordsId)
                    {
                        _contentKeywordsCommandRepository.Add(new ContentKeywords()
                        {
                            ContentId = contentId,
                            KeywordId = id
                        });
                    }
                }
                foreach (var id in command.PublishPlacesId)
                {
                    _contentPlacesCommandRepository.Add(new ContentPlaces()
                    {
                        ContentId      = contentId,
                        PublishPlaceId = id
                    });
                }
                return(Ok());
            }
            return(Failure());
        }