Example #1
0
        public Tag CreateTag(CreateTagInput inputTag)
        {
            _logger.LogInformation($"Creating tag {inputTag.Title}");
            var tag = new MapperConfiguration(cfg => cfg.CreateMap <CreateTagInput, Tag>())
                      .CreateMapper()
                      .Map <Tag>(inputTag);

            var createdTag = _data.EfContext.Tags.Add(tag);

            _data.EfContext.SaveChanges();

            _logger.LogInformation($"Tag {inputTag.Title} is created successfully");
            return(createdTag.Entity);
        }
Example #2
0
        public async Task <BlogResponse> CreateTagAsync(CreateTagInput input)
        {
            var response = new BlogResponse();

            var tag = await _tags.FindAsync(x => x.Name == input.Name);

            if (tag is not null)
            {
                response.IsFailed($"The tag:{input.Name} already exists.");
                return(response);
            }

            await _tags.InsertAsync(new Tag
            {
                Name  = input.Name,
                Alias = input.Alias
            });

            return(response);
        }