private async Task ValidateTag(NewTagDto newTagDto) { if (newTagDto == null) { throw new ArgumentNullException(nameof(newTagDto)); } else if (await _repository.TagExists(newTagDto.Title)) { throw new ValidationException("Tag already exists"); } else if (newTagDto.Title.Length < 3) { throw new ValidationException("Tag is too short"); } else if (newTagDto.Title.Length > 10) { throw new ValidationException("Tag is too long"); } var regexForTagValidation = new Regex("^[a-zA-Z0-9#-]*$"); if (!regexForTagValidation.IsMatch(newTagDto.Title)) { throw new ValidationException("Tag has invalid characters"); } }
public async Task <IActionResult> Post([FromBody] NewTagDto newTag) { var createdTag = await _tagsService.Create(newTag); var tagUri = CreateResourceUri(createdTag.Id); return(Created(tagUri, createdTag)); }
public async Task <int> Create(NewTagDto newTagDto) { await ValidateTag(newTagDto); var tag = _mapper.Map <Tag>(newTagDto); var newTagId = await _repository.Create(tag); return(newTagId); }
public ActionResult CreateTag( [FromBody, SwaggerParameter("New Tag data", Required = true)] NewTagDto newTagDto ) { var newTag = _publicAccessService.CreateTag(newTagDto); if (newTag == null) { return(BadRequest()); } return(CreatedAtAction(nameof(GetTag), new { tagId = newTag.Id }, newTag.ToPublicDto())); }
public async Task <IActionResult> Post([FromBody] NewTagDto newTagDto) { try { var tagId = await _tagsService.Create(newTagDto); return(Ok(tagId)); } catch (ValidationException exception) { return(BadRequest(exception.Message)); } catch (ArgumentNullException exception) { return(NotFound(exception.Message)); } }
public async Task <TagDto> Create(NewTagDto newItem) { if (newItem == null) { throw new ArgumentNullException(nameof(newItem)); } var creationDate = _timeService.GetCurrentTime(); var newTag = _mapper.Map <Tag>(newItem); newTag.Created = creationDate; await _repository.Create(newTag); var tagDto = _mapper.Map <TagDto>(newTag); return(tagDto); }
public Tag CreateTag(NewTagDto newTagDto) { if (_tagRepository.Exists(newTagDto.Name)) { return(null); } var tagEntry = _dbContext.Tags.Add(new Tag()); tagEntry.CurrentValues.SetValues(newTagDto); _dbContext.SaveChanges(); var newTag = tagEntry.Entity; return(newTag); }
public bool NewTag([FromServices] ITagService TagService, [FromBody] NewTagDto tag) { return(TagService.NewTag(tag)); }