コード例 #1
0
        public void Create(string tokenId, SubscriberDto subscriberDto)
        {
            var user = UserAdapter.BuildUser(subscriberDto);

            user.Id = Guid.NewGuid();

            var roleUser = _roleRepository.Find(x => x.Name.Equals(RoleConstants.Subscriber)).FirstOrDefault();

            user.Roles = new List <Role> {
                roleUser
            };

            var customerId = StripeService.StripeService.CreateCustomer(tokenId, user.Email);

            var subscriberId = StripeService.StripeService.SubscribeCustomer(customerId, subscriberDto.SubscriptionPlan);

            var sub = new Subscriber
            {
                UserId           = user.Id,
                StripeId         = customerId,
                SubscriptionPlan = subscriberDto.SubscriptionPlan.ToString(),
                IsTrial          = subscriberDto.IsTrial
            };

            _userRepository.AddUser(user);

            _gSubscriberRepository.Add(sub);

            var body = _email.CreateEmailBody(user.UserName, "Subscriber");

            _email.SendEmail("Welcome", body, user.Email);
        }
コード例 #2
0
        public void Create(string email, UserDto userDto)
        {
            var user = UserAdapter.BuildUser(userDto);

            var sub = _gUserRepository.Find(usr => usr.Email.Equals(email)).FirstOrDefault();

            if (sub != null)
            {
                var subs = _userRepository.GetUserById(sub.Id).Subscriber;

                user.DependsOnAdmin = new List <Subscriber>()
                {
                    subs
                };
            }

            var roleUser = _roleRepository.Find(x => x.Name.Equals(RoleConstants.User)).FirstOrDefault();

            user.Roles = new List <Role> {
                roleUser
            };

            _userRepository.AddUser(user);

            var body = _email.CreateEmailBody(user.UserName, "Subscriber");

            _email.SendEmail("Welcome", body, user.Email);
        }
コード例 #3
0
        public void Edit(UserDto userDto, Guid requestorUserId)
        {
            var user = UserAdapter.BuildUser(userDto);

            var userRequestor = _userRepository.GetUserById(requestorUserId);

            if (userRequestor.Roles[0].Name.Equals(RoleConstants.Subscriber))
            {
                var roleUser = _roleRepository.Find(x => x.Name.Equals(RoleConstants.User)).FirstOrDefault();
                user.Roles = new List <Role> {
                    roleUser
                };
                user.ValidUntil = userRequestor.ValidUntil;
            }
            else
            {
                var role = _roleRepository.Find(x => x.Name.Equals(userDto.Roles[0])).FirstOrDefault();
                user.Roles = new List <Role> {
                    role
                };
            }

            _userRepository.UpdateUser(user);
        }