public async Task <ShortUrlCreatedViewModel> CreateShortenUrl(ShortenUrlDTO shortenUrlDTO) { if (string.IsNullOrEmpty(shortenUrlDTO.Code)) { shortenUrlDTO.Code = _codeService.GenerateCode(6, new Random()); } if (_codeService.IsCodeValid(shortenUrlDTO.Code)) { var shortenUrl = await _shortenUrlRepository.GetShortenUrl(shortenUrlDTO.Code); if (shortenUrl != null) { throw new ConflictException("Code in Use"); } await _shortenUrlRepository.InsertShortenUrl(shortenUrlDTO); return(new ShortUrlCreatedViewModel { Code = shortenUrlDTO.Code }); } else { throw new UnprocessableEntityException("Code should be alphanumeric and 6 chars long"); } }
public async Task <UserPasswordForgotResponseDto> PasswordForgot(UserPasswordForgotRequestDto requestDto) { var user = await _userRepository.GetByEmail(requestDto.Email); if (user == null) { return(new UserPasswordForgotResponseDto { Error = ErrorCodes.UserEmailNotExists, ErrorField = new List <string> { nameof(requestDto.Email) } }); } var res = await _codeRepository.Create( new CodeModel { UserId = user.Id, Code = _codeService.GenerateCode(6), ReasonId = CodeReason.PasswordForgot, DateExpiration = new DateTime().Add(new TimeSpan(0, 0, 30)) }, user.Id.Value ); //TODO email send return(new UserPasswordForgotResponseDto()); }
public async Task <PollCreated> CreatePoll(PollCreate pollCreate) { //TODO Category Repository var generatedCode = await _codeService.GenerateCode(); int catId = 1; var poll = new PollEntity { Title = pollCreate.Title, Category = new CategoryEntity { Id = catId, Name = pollCreate.Category }, Code = generatedCode }; await _pollRepository.InsertPollAsync(poll); return(new PollCreated { Code = generatedCode.Code }); }
public async Task <string> Generate(CodeType type) { return(await _codeService.GenerateCode(type)); }