Esempio n. 1
0
        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
            });
        }
Esempio n. 2
0
 public static Hashtag ToResult(this CreateHashtagDto dto)
 => new Hashtag
 {
     Title  = dto.Title.Trim().ApplyCorrectYeKe(),
     UserId = dto.UserId
 };