Пример #1
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Subscriptions EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSubscriptions(Subscription subscription)
 {
     base.AddObject("Subscriptions", subscription);
 }
Пример #2
0
 /// <summary>
 /// Create a new Subscription object.
 /// </summary>
 /// <param name="subscriptionId">Initial value of the SubscriptionId property.</param>
 /// <param name="pricingPlanId">Initial value of the PricingPlanId property.</param>
 /// <param name="userId">Initial value of the UserId property.</param>
 /// <param name="subscriptionStartDate">Initial value of the SubscriptionStartDate property.</param>
 /// <param name="planCharge">Initial value of the PlanCharge property.</param>
 public static Subscription CreateSubscription(global::System.Int32 subscriptionId, global::System.Int32 pricingPlanId, global::System.Int32 userId, global::System.DateTime subscriptionStartDate, global::System.Decimal planCharge)
 {
     Subscription subscription = new Subscription();
     subscription.SubscriptionId = subscriptionId;
     subscription.PricingPlanId = pricingPlanId;
     subscription.UserId = userId;
     subscription.SubscriptionStartDate = subscriptionStartDate;
     subscription.PlanCharge = planCharge;
     return subscription;
 }
Пример #3
0
        internal static PlanBalance SubscribeUserTo(this SongSearchContext ctx, User user, PricingPlan pricingPlan)
        {
            if (user.EntityState == System.Data.EntityState.Detached) {

                //ctx.Detach(user);
                ctx.Attach(user);
            }

            var oldSubs = user.Subscriptions;
            foreach (var sub in oldSubs) {
                if (sub.SubscriptionEndDate == null) {
                    sub.SubscriptionEndDate = DateTime.Now;
                }
            }

            //Start a new Subscription
            var subscription = new Subscription() {
                SubscriptionStartDate = DateTime.Now,
                SubscriptionEndDate = null,
                PricingPlanId = pricingPlan.PricingPlanId,
                PlanCharge = pricingPlan.PlanCharge.GetValueOrDefault()
            };

            user.Subscriptions.Add(subscription);
            ctx.Subscriptions.AddObject(subscription);

            // Adjust current plan
            user.PricingPlanId = pricingPlan.PricingPlanId;

            // if user was already on a plan, switch the balance over; if not, open a new balance
            PlanBalance balance;

            if (user.IsPlanOwner) {

                balance = user.PlanBalance;
                balance.PricingPlanId = pricingPlan.PricingPlanId;
                balance.LastUpdatedByUserId = user.UserId;
                balance.LastUpdatedOn = DateTime.Now;

            } else {

                balance = new PlanBalance() {
                    PricingPlanId = pricingPlan.PricingPlanId,
                    NumberOfCatalogAdmins = 1,
                    NumberOfInvitedUsers = 1,
                    NumberOfSongs = 0,
                    LastUpdatedByUserId = user.UserId,
                    LastUpdatedOn = DateTime.Now
                };

                user.PlanUserId = user.UserId;

                balance.Users.Add(user);
                ctx.PlanBalances.AddObject(balance);
            }

            return balance;
        }