public IHttpActionResult PutHashTag([FromBody] HashTagDTO hashTag) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } int id = _hashTagService.PutHashTag(hashTag); return(Ok(id)); }
public int PutHashTag(HashTagDTO hashTag) { if (hashTag == null) { throw new ServiceException(ExceptionType.NullException, "Hash tag is null"); } int?hashTagId = _db.HashTagRepository.Get(hashTag.Id)?.Id ?? GetHashTagByName(hashTag.Name)?.Id; return(hashTagId ?? AddHashTag(hashTag)); }
public int AddHashTag(HashTagDTO hashTag) { ValidateHashTag(hashTag); if (GetHashTagByName(hashTag.Name) != null) { throw new ServiceException(ExceptionType.UniqueException, "Hash tag already exists!"); } HashTag hashTagDAL = _db.HashTagRepository.Add(_mapper.Map <HashTag>(hashTag)); _db.Save(); return(hashTagDAL.Id); }
private static IList <HashTagDTO> SplitHashtags(TweetDTO tweet) { IList <HashTagDTO> listOfHashTagsInMessage = new List <HashTagDTO>(); var regex = new Regex(@"(?<=#)\w+"); var hashTagsInMessage = regex.Matches(tweet.TweetContent); foreach (Match m in hashTagsInMessage) { var newhashtag = new HashTagDTO { HashTagName = m.ToString(), TweetId = tweet.TweetId, }; listOfHashTagsInMessage.Add(newhashtag); } return(listOfHashTagsInMessage); }
private void ValidateHashTag(HashTagDTO hashTag) { if (hashTag == null) { throw new ServiceException("Hash tag is null!") { Type = ExceptionType.NullException } } ; if (!(hashTag.Name?.Trim().Length > 0)) { throw new ServiceException("Hash tag name is empty") { Type = ExceptionType.EmptyStringException, ExceptionValue = nameof(hashTag.Name) } } ; } } }