Example #1
0
        public async Task <IActionResult> Put(int tagId, [FromBody] TagInputDto model)
        {
            model.TagId = tagId;
            var updatedTag = await _tagService.UpdateTag(model);

            return(Ok(updatedTag));
        }
Example #2
0
        public async Task <Tag> AddTag(TagInputDto model)
        {
            var newTag = new Tag
            {
                TagName = model.Name
            };

            _unitOfWork.TagRepository.Add(newTag);

            await _unitOfWork.SaveChangeAsync();

            return(newTag);
        }
Example #3
0
        public async Task <Tag> UpdateTag(TagInputDto model)
        {
            var tag = _unitOfWork.TagRepository.FindBy(t => t.TagId == model.TagId).FirstOrDefault();

            if (tag == null)
            {
                throw new ArgumentNullException($"Tag with Id {model.TagId} not found.");
            }

            tag.TagName = model.Name;

            _unitOfWork.TagRepository.Update(tag);
            await _unitOfWork.SaveChangeAsync();

            return(tag);
        }
Example #4
0
        public async Task <IActionResult> Post([FromBody] TagInputDto model)
        {
            var newTag = await _tagService.AddTag(model);

            return(Ok(newTag));
        }