Esempio n. 1
0
        public async Task <IActionResult> CreateTagAsync([FromBody] Client.TagCreationInfo creationInfo,
                                                         CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (creationInfo == null)
            {
                var error = Responses.BodyIsMissing(nameof(creationInfo));
                return(BadRequest(error));
            }

            var modelCreationInfo = Converter.TagCreationInfoConverter.Convert(creationInfo);

            Model.Tag modelTag;

            try
            {
                modelTag =
                    await repository.CreateAsync(modelCreationInfo, cancellationToken).ConfigureAwait(false);
            }
            catch (TagDuplicationException ex)
            {
                var error = Responses.DuplicationError(ex.Message, Target);
                return(BadRequest(error));
            }

            var clientTag = Converter.TagConverter.Convert(modelTag);

            return(CreatedAtRoute("GetTagRoute", new { id = clientTag.Id }, clientTag));
        }
Esempio n. 2
0
        public static Model.TagCreationInfo Convert(Client.TagCreationInfo clientCreationInfo)
        {
            if (clientCreationInfo == null)
            {
                throw new ArgumentNullException(nameof(clientCreationInfo));
            }

            var modelCreationInfo = new Model.TagCreationInfo(clientCreationInfo.Id, clientCreationInfo.Name);
            return modelCreationInfo;
        }