public RepoApiController(ISubscriptionRepo subscriptionRepo, IUserRepo userRepo, IGitRepo gitRepo, ILogger logger)
 {
     _subscriptionRepo = subscriptionRepo;
     _userRepo         = userRepo;
     _gitRepo          = gitRepo;
     _logger           = logger;
 }
Exemple #2
0
        protected override async Task <UserLogin> HandleInput(UserRegisterParams input)
        {
            using (var connection = database.GetConnection()) {
                using (var transaction = connection.BeginTransaction()) {
                    IUserRepo         userRepo  = database.GetRepo <IUserRepo>(connection);
                    ISpaceRepo        spaceRepo = database.GetRepo <ISpaceRepo>(connection);
                    ISubscriptionRepo subRepo   = database.GetRepo <ISubscriptionRepo>(connection);

                    // Check that the email is free first.
                    if (!String.IsNullOrWhiteSpace(input.Email))
                    {
                        User?emailInUse = await userRepo.FindByEmail(input.Email);

                        if (emailInUse != null)
                        {
                            throw new CollisionException("Email is already in use");
                        }
                    }

                    User?usernameInUse = await userRepo.FindByUsername(input.Username);

                    if (usernameInUse != null)
                    {
                        throw new CollisionException("Username is unavailable");
                    }

                    User user = new User()
                    {
                        Username     = input.Username,
                        PasswordHash = passwordHasher.Hash(input.Password),
                        Email        = StringUtils.NullifyWhiteSpace(input.Email),
                        JoinedDate   = System.DateTime.UtcNow
                    };

                    await userRepo.Add(user);

                    // Subscribe the user to the default spaces.
                    IEnumerable <Space> defaultSpaces = await spaceRepo.FindDefault();

                    IEnumerable <Subscription> defaultSubscriptions = defaultSpaces.Select(space => new Subscription()
                    {
                        User = user, Space = space
                    });

                    foreach (Subscription s in defaultSubscriptions)
                    {
                        await subRepo.Add(s);

                        s.Space.SubscriptionCount++;
                        await spaceRepo.Update(s.Space);
                    }

                    UserView userView  = userMapper.Map(user);
                    string   authToken = tokenHandler.IssueToken(user);

                    transaction.Commit();
                    return(new UserLogin(userView, authToken));
                }
            }
        }
Exemple #3
0
        protected override async Task HandleInput(SubscriptionDeleteParams input)
        {
            using (var conenction = database.GetConnection()) {
                ISpaceRepo        spaceRepo = database.GetRepo <ISpaceRepo>(conenction);
                ISubscriptionRepo subRepo   = database.GetRepo <ISubscriptionRepo>(conenction);

                //Pull in the space first
                Space?space = await spaceRepo.FindByName(input.Space);

                if (space == null)
                {
                    throw new InvalidOperationException($"No space with name {input.Space} exists.");
                }

                //Try to pull in the subscription
                Subscription?sub = await subRepo.FindByUserAndSpace(input.User.Username, input.Space);

                if (sub == null)
                {
                    throw new InvalidOperationException("Subscription does not exist");
                }

                await subRepo.Delete(sub);

                space.SubscriptionCount--;

                await spaceRepo.Update(space);
            }
        }
Exemple #4
0
 public FirmRepo(PropertyDbContext db, IBlobRepo blob, IConfiguration config, ISubscriptionRepo subRepo)
 {
     _db      = db;
     _blob    = blob;
     _config  = config;
     _subRepo = subRepo;
 }
Exemple #5
0
        protected override async Task <IEnumerable <SpaceView> > HandleInput(FindByValueParams <string> input)
        {
            using (var connection = database.GetConnection()) {
                ISubscriptionRepo subRepo = database.GetRepo <ISubscriptionRepo>(connection);

                IEnumerable <Subscription> subs = await subRepo.FindByUser(input.Value);

                return(subs.Select(s => spaceMapper.Map(s.Space)));
            }
        }
        protected override async Task <SubscriptionView> HandleInput(SubscriptionCreateParams input)
        {
            using (var connection = database.GetConnection()) {
                ISpaceRepo        spaceRepo = database.GetRepo <ISpaceRepo>(connection);
                ISubscriptionRepo subRepo   = database.GetRepo <ISubscriptionRepo>(connection);

                //Check to see if the Space exists first
                Space?space = await spaceRepo.FindByName(input.Space);

                if (space == null)
                {
                    throw new InvalidOperationException($"No space with name {input.Space} exists.");
                }

                //Ensure no sub for this combo is already in place
                Subscription?existingSub = await subRepo.FindByUserAndSpace(input.User.Username, input.Space);

                if (existingSub != null)
                {
                    return(subscriptionMapper.Map(existingSub));
                }

                //Create the subscription
                Subscription sub = new Subscription()
                {
                    Space = space,
                    User  = input.User
                };

                await subRepo.Add(sub);

                //Update sub count
                space.SubscriptionCount++;

                await spaceRepo.Update(space);

                return(subscriptionMapper.Map(sub));
            }
        }
 public SubscriptionManager(ISubscriptionRepo subscriptionRepo, IDependencyManager depManager, IPaymentCustomers paymentCustomers, ISecurity security, IAdminLogger logger, IAppConfig appConfig) : base(logger, appConfig, depManager, security)
 {
     _subscriptionRepo = subscriptionRepo;
     _paymentCustomers = paymentCustomers;
 }
 public SubscriptionManager()
 {
     repo = new SubscriptionRepo();
 }
 public UserRegisterEventHandler(ISpaceRepo spaceRepo, ISubscriptionRepo subscriptionRepo, ISubscriptionFactory subscriptionFactory)
 {
     this.spaceRepo           = spaceRepo;
     this.subscriptionRepo    = subscriptionRepo;
     this.subscriptionFactory = subscriptionFactory;
 }
Exemple #10
0
 public FirmController(IPropertyManager manager, IFirmRepo providerRepo, ISubscriptionRepo sub)
 {
     _manager      = manager;
     _providerRepo = providerRepo;
     _sub          = sub;
 }
Exemple #11
0
 public OnderwerpManager()
 {
     repo             = new OnderwerpRepository();
     Tweetmgr         = new TweetManager();
     subscriptionRepo = new SubscriptionRepo();
 }
 public SubscriptionService(IEventBus bus, ISubscriptionFactory factory, ISpaceRepo spaceRepo, ISubscriptionRepo repo) {
     this.bus = bus;
     this.factory = factory;
     this.spaceRepo = spaceRepo;
     this.repo = repo;
 }