Пример #1
0
        public async Task <IActionResult> ShortUrlAsync(string base62,
                                                        CancellationToken token)
        {
            if (string.IsNullOrEmpty(base62))
            {
                return(NotFound());
            }

            //if (!long.TryParse(base62, out var id))
            //{
            if (!Base62.TryParse(base62, out var id))
            {
                return(NotFound());
            }

            _userManager.TryGetLongUserId(User, out var userId);
            var query = new DocumentById(id, userId);
            var model = await _queryBus.QueryAsync(query, token);

            if (model == null)
            {
                return(NotFound());
            }
            var t = RedirectToRoutePermanent(SeoTypeString.Document, new
            {
                courseName = FriendlyUrlHelper.GetFriendlyTitle(model.Document.Course),
                id         = id.Value,
                name       = FriendlyUrlHelper.GetFriendlyTitle(model.Document.Title)
            });

            return(t);
        }
Пример #2
0
        public void TryParse_InvalidValue_False()
        {
            const string invalidString = "המסלול-האקדמי-המכללה-למנהל";
            var          result        = Base62.TryParse(invalidString, out var p);

            result.Should().BeFalse();
            p.Value.Should().Be(0);
            p.ToString().Should().Be("0");
        }
Пример #3
0
        private async Task <IActionResult> FinishRegistrationAsync(User user, string country, string fingerPrint,
                                                                   string userAgent, CancellationToken token)
        {
            if (TempData[HomeController.Referral] != null)
            {
                if (Base62.TryParse(TempData[HomeController.Referral].ToString(), out var base62))
                {
                    try
                    {
                        var command = new ReferringUserCommand(base62, user.Id);
                        await _commandBus.DispatchAsync(command, token);
                    }
                    catch (UserLockoutException)
                    {
                        _logger.Warning($"{user.Id} got locked referring user {TempData[HomeController.Referral]}");
                    }
                }
                else
                {
                    _logger.Error($"{user.Id} got wrong referring user {TempData[HomeController.Referral]}");
                }
                TempData.Remove(HomeController.Referral);
            }
            TempData.Clear();

            var command2 = new AddUserLocationCommand(user, country, HttpContext.GetIpAddress(), fingerPrint, userAgent);
            var registrationBonusCommand = new FinishRegistrationCommand(user.Id);
            var t1 = _commandBus.DispatchAsync(command2, token);
            var t2 = _signInManager.SignInAsync(user, false);
            var t3 = _commandBus.DispatchAsync(registrationBonusCommand, token);
            await Task.WhenAll(t1, t2, t3);

            return(Ok(new
            {
                user.Id
            }));
        }