示例#1
0
        /// <summary>
        /// Recieve a tag type dto from the body with a already existing id and update
        /// the tag information.
        ///
        /// Returns the updated tag back to the client or null/exception if update failed
        /// </summary>
        /// <param name="updatedTag"></param>
        /// <returns></returns>
        public TagTypeDto Put([FromBody] TagTypeDto updatedTag)
        {
            return(ActionVerbConfigService.WrapAction(() =>
            {
                var tagTypeDomainObject = AutoMapper.Mapper.Map <TagTypeDto, TagType>(updatedTag);

                var tagUpdateActionResult = _tagTypesLogic.UpdateTag(tagTypeDomainObject);

                if (tagUpdateActionResult.Success)
                {
                    var updatedTagDto = AutoMapper.Mapper.Map <TagType, TagTypeDto>(tagUpdateActionResult.Data);
                    return updatedTagDto;
                }

                throw new HttpResponseException(ResponseMessageBuilder.BuildMessageFromActionResult(tagUpdateActionResult));
            }));
        }
示例#2
0
        /// <summary>
        /// Recieve a tag type dto from the body and create a new tag from the
        /// dto.
        ///
        /// Return the newly created tag including its id to the client
        /// </summary>
        /// <param name="newTag"></param>
        /// <returns></returns>
        public TagTypeDto Post([FromBody] TagTypeDto newTag)
        {
            return(ActionVerbConfigService.WrapAction(() =>
            {
                // map from the new tag to a TagType domain obhject using auto mapper
                var tagTypeDomainObject = AutoMapper.Mapper.Map <TagTypeDto, TagType>(newTag);

                var tagCreateActionResult = _tagTypesLogic.CreateTagForCategory(tagTypeDomainObject, newTag.CategoryId);

                if (tagCreateActionResult.Success)
                {
                    // map the dto of the newly created tag returned form the service to an apropriate tag dto
                    // which we will return back to the client
                    var storedTagDto = AutoMapper.Mapper.Map <TagType, TagTypeDto>(tagCreateActionResult.Data);
                    return storedTagDto;
                }

                throw new HttpResponseException(
                    ResponseMessageBuilder.BuildMessageFromActionResult(tagCreateActionResult));
            }));
        }