Exemplo n.º 1
0
        /// <summary>
        /// Register events
        /// </summary>
        public static void RegisterEvents()
        {
            SqlQuery.OnQueryExecuted += EventHandlers.OnQueryExecutedHandler;

            //register events on global storage
            SystemEvents.Common.RegisterEventGroup(nameof(SqlQuery), SystemEvents.GetEvents(typeof(SqlQuery)));
            SystemEvents.Common.RegisterEventGroup(nameof(Entities), SystemEvents.GetEvents(typeof(Entities)));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Register app events
 /// </summary>
 public static void RegisterEvents()
 {
     Authorization.OnUserLogIn  += delegate { };
     Authorization.OnUserLogout += delegate { };
     Users.OnUserCreated        += delegate { };
     //register events on global storage
     SystemEvents.Common.RegisterEventGroup(nameof(Authorization), SystemEvents.GetEvents(typeof(Authorization)));
     SystemEvents.Common.RegisterEventGroup(nameof(Users), SystemEvents.GetEvents(typeof(Users)));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Register app events
        /// </summary>
        public static void RegisterEvents()
        {
            //Pages
            Pages.OnPageCreated += EventHandlers.OnPageCreatedHandler;
            Pages.OnPageDeleted += EventHandlers.OnPageDeletedHandler;
            Pages.OnPageUpdated += EventHandlers.OnPageUpdatedHandler;

            //register events on global storage
            SystemEvents.Common.RegisterEventGroup(nameof(Pages), SystemEvents.GetEvents(typeof(Pages)));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Register events
        /// </summary>
        public static void RegisterEvents()
        {
            Products.OnProductAdded += CommerceEventHandlers.OnProductAddedHandler;

            SystemEvents.Common.RegisterEventGroup(nameof(Products), SystemEvents.GetEvents(typeof(Products)));
        }
Exemplo n.º 5
0
 public static void RegisterEvents()
 {
     SystemEvents.Common.RegisterEventGroup(nameof(AccountActivityEvents), SystemEvents.GetEvents(typeof(Events)));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Register events
 /// </summary>
 public static void RegisterEvents()
 {
     SystemEvents.Common.RegisterEventGroup(nameof(PhoneVerificationEvents), SystemEvents.GetEvents(typeof(Events)));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Register app events
 /// </summary>
 public static void RegisterEvents()
 {
     //register events on global storage
     SystemEvents.Common.RegisterEventGroup(nameof(Company), SystemEvents.GetEvents(typeof(Company)));
 }
Exemplo n.º 8
0
 /// <summary>
 /// Register events
 /// </summary>
 public static void RegisterEvents()
 {
     SystemEvents.Common.RegisterEventGroup(nameof(Orders), SystemEvents.GetEvents(typeof(Orders)));
 }
Exemplo n.º 9
0
        /// <summary>
        /// Register events
        /// </summary>
        public static void RegisterEvents()
        {
            SystemEvents.Common.RegisterEventGroup(nameof(Subscriptions), SystemEvents.GetEvents(typeof(Subscriptions)));

            TenantEvents.Company.OnCompanyRegistered += async(sender, args) =>
            {
                var productService      = IoC.Resolve <IProductService <Product> >();
                var subscriptionService = IoC.Resolve <ISubscriptionService <Subscription> >();
                var freeTrialPeriodStr  = (await productService.GetSettingAsync <string>(CommerceResources.SettingsParameters.FREE_TRIAL_PERIOD_DAYS)).Result ?? "15";

                var planRequest = await productService.GetProductByAttributeMinNumberValueAsync("Number of users");

                if (planRequest.IsSuccess)
                {
                    var plan = planRequest.Result;

                    var permissions = SubscriptionMapper.Map(plan.ProductAttributes).ToList();
                    var result      = await subscriptionService.CreateUpdateSubscriptionAsync(new SubscriptionViewModel
                    {
                        Name                    = "Free trial",
                        StartDate               = DateTime.Now,
                        Availability            = int.Parse(freeTrialPeriodStr),
                        UserId                  = args.UserId,
                        IsFree                  = true,
                        SubscriptionPermissions = permissions
                    });
                }
            };

            OrderEvents.Orders.OnPaymentReceived += async(sender, args) =>
            {
                var orderService        = IoC.Resolve <IOrderProductService <Order> >();
                var subscriptionService = IoC.Resolve <ISubscriptionService <Subscription> >();
                var productService      = IoC.Resolve <IProductService <Product> >();

                var orderRequest = await orderService.GetOrderByIdAsync(args.OrderId);

                if (orderRequest.IsSuccess.Negate())
                {
                    return;
                }
                var order = orderRequest.Result;
                var checkIfProductIsSubscription = order.ProductOrders
                                                   .FirstOrDefault(x => x.Product?.ProductTypeId == ProductTypes.SubscriptionPlan)?.ProductId;
                if (checkIfProductIsSubscription == null)
                {
                    return;
                }
                var planRequest = await productService.GetProductByIdAsync(checkIfProductIsSubscription);

                if (planRequest.IsSuccess.Negate())
                {
                    return;
                }
                var plan        = planRequest.Result;
                var permissions = SubscriptionMapper.Map(plan.ProductAttributes).ToList();
                var variationId = order.ProductOrders.FirstOrDefault(x => x.ProductId == checkIfProductIsSubscription)?.ProductVariationId;
                var variation   = plan.ProductVariations.FirstOrDefault(x => x.Id.Equals(variationId));


                var userSubscriptionRequest = await subscriptionService.GetLastSubscriptionForUserAsync(args.UserId);


                var newSubscription = new SubscriptionViewModel
                {
                    Name                    = plan.Name,
                    OrderId                 = args.OrderId,
                    StartDate               = DateTime.Now,
                    Availability            = subscriptionService.GetSubscriptionDuration(variation),
                    UserId                  = order.UserId,
                    SubscriptionPermissions = permissions,
                };

                if (userSubscriptionRequest.IsSuccess)
                {
                    var userSubscription = userSubscriptionRequest.Result;
                    newSubscription.Id            = userSubscription.Id;
                    newSubscription.Availability += userSubscription.Availability;
                    newSubscription.IsFree        = false;
                }

                await subscriptionService.CreateUpdateSubscriptionAsync(newSubscription);
            };
        }