Ejemplo n.º 1
0
        public async Task <User> SubscribeUserAsync(string email, SubscriptionTypeEnum subscriptionType)
        {
            User user = await this.FindByEmailAsync(email);

            if (user is null)
            {
                throw new ApiException((int)ErrorEnum.UserAlreadyExist, nameof(ErrorEnum.UserAlreadyExist));
            }

            SubscriptionType subscriptionTypeResult = await _subscriptionTypeService.GetSubscriptionTypeById((int)subscriptionType);

            if (user.UserSubscriptions != null)
            {
                throw new ApiException((int)ErrorEnum.UserAlreadyExist, nameof(ErrorEnum.UserAlreadyExist));
            }
            var result = await _subscriptionTypeService.AddUserSubscriptionType(new UserSubscriptionType
            {
                SubscriptionTypeId = subscriptionTypeResult.Id,
                UserId             = user.Id,
                CreateDateTime     = DateTime.Now,
                IsActive           = true
            });

            IdentityResult results = await _userManager.UpdateAsync(user);

            return(user);
        }
        public async Task <IActionResult> SubscribeAsync([FromRoute] SubscriptionTypeEnum type)
        {
            return(await _exceptionService.HandleApiExceptionAsync <ApiException>(nameof(AccountController), nameof(SubscribeAsync), async() =>
            {
                var user = await _userService.SubscribeUserAsync(_authenticationService.GetUserEmail(), type);

                return Ok();
            }));
        }
    private Type GetSubscriptionCriteriaType(SubscriptionTypeEnum type)
    {
        switch (type)
        {
        case SubscriptionTypeEnum.SomeType1:
            return(typeof(SomeType1));

        case SubscriptionTypeEnum.SomeType2:
            return(typeof(SomeType2));

            ...
        default:
            throw new NotImplementedException(string.Format("SubscriptionType of {0} is not implemented.", Enum.GetName(typeof(SubscriptionTypeEnum), type)));
        }
    }