public async Task <ServiceResult <Hashtag> > CreateAsync(CreateHashtagDto model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var result = new ServiceResult <Hashtag> { Result = new Hashtag { Title = model.Title, UserId = model.UserId } }; if (model.Title.IsNotNullOrEmpty()) { return(result.Which( isValid: false, withMessage: ErrorText.Hashtag_Title_Required)); } var existed = await GetAsync(model.UserId, model.Title); if (existed != null) { return new ServiceResult <Hashtag> { Result = existed } } ; var hashtag = model.ToResult(); hashtag.CreateDate = _dateService.UtcNow(); await _repository.InsertAsync(hashtag); return(new ServiceResult <Hashtag> { Result = hashtag }); }
public static Hashtag ToResult(this CreateHashtagDto dto) => new Hashtag { Title = dto.Title.Trim().ApplyCorrectYeKe(), UserId = dto.UserId };