コード例 #1
0
ファイル: TagsController.cs プロジェクト: marax27/Episememe
        public async Task <NoContentResult> SetTag(string name, [FromBody] SetTagDto setTagDto)
        {
            var command = SetTagCommand.Create(name, setTagDto);
            await _mediator.Send(command);

            return(NoContent());
        }
コード例 #2
0
        public static SetTagCommand Create(string currentName, SetTagDto dto)
        {
            if (currentName == null)
            {
                throw new ArgumentNullException(nameof(currentName));
            }
            if (dto.Name == null)
            {
                throw new ArgumentNullException(nameof(dto.Name));
            }
            if (dto.Children == null)
            {
                throw new ArgumentNullException(nameof(dto.Children));
            }
            if (dto.Parents == null)
            {
                throw new ArgumentNullException(nameof(dto.Parents));
            }

            if (dto.Children.Intersect(dto.Parents).Any())
            {
                throw new ArgumentException($"An item appears in both {nameof(dto.Children)} and {nameof(dto.Parents)}.");
            }

            return(new SetTagCommand(currentName, dto.Name, dto.Description,
                                     dto.Children.ToList().AsReadOnly(), dto.Parents.ToList().AsReadOnly()));
        }