/// <summary>
 /// Deprecated Method for adding a new object to the PricingPlans EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPricingPlans(PricingPlan pricingPlan)
 {
     base.AddObject("PricingPlans", pricingPlan);
 }
 /// <summary>
 /// Create a new PricingPlan object.
 /// </summary>
 /// <param name="pricingPlanId">Initial value of the PricingPlanId property.</param>
 /// <param name="pricingPlanName">Initial value of the PricingPlanName property.</param>
 /// <param name="isPromo">Initial value of the IsPromo property.</param>
 /// <param name="isFeatured">Initial value of the IsFeatured property.</param>
 /// <param name="isEnabled">Initial value of the IsEnabled property.</param>
 /// <param name="showOnSite">Initial value of the ShowOnSite property.</param>
 /// <param name="customContactUs">Initial value of the CustomContactUs property.</param>
 /// <param name="customSiteProfile">Initial value of the CustomSiteProfile property.</param>
 public static PricingPlan CreatePricingPlan(global::System.Int32 pricingPlanId, global::System.String pricingPlanName, global::System.Boolean isPromo, global::System.Boolean isFeatured, global::System.Boolean isEnabled, global::System.Boolean showOnSite, global::System.Boolean customContactUs, global::System.Boolean customSiteProfile)
 {
     PricingPlan pricingPlan = new PricingPlan();
     pricingPlan.PricingPlanId = pricingPlanId;
     pricingPlan.PricingPlanName = pricingPlanName;
     pricingPlan.IsPromo = isPromo;
     pricingPlan.IsFeatured = isFeatured;
     pricingPlan.IsEnabled = isEnabled;
     pricingPlan.ShowOnSite = showOnSite;
     pricingPlan.CustomContactUs = customContactUs;
     pricingPlan.CustomSiteProfile = customSiteProfile;
     return pricingPlan;
 }
Beispiel #3
0
 public static bool IsWithinLimitsOf(this PlanBalance balance, PricingPlan plan)
 {
     return (plan.NumberOfSongs == null || plan.NumberOfSongs >= balance.NumberOfSongs) &&
                                     (plan.NumberOfInvitedUsers == null || plan.NumberOfInvitedUsers >= balance.NumberOfInvitedUsers) &&
                                     (plan.NumberOfCatalogAdmins == null || plan.NumberOfCatalogAdmins >= balance.NumberOfCatalogAdmins);
 }
Beispiel #4
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;
        }
Beispiel #5
0
        // **************************************
        // CreateUser
        // **************************************
        internal static User Create(this SongSearchContext ctx, User user, Invitation inv, PricingPlan pricingPlan)
        {
            var newUser = new User() {
                UserName = user.UserName,
                FirstName = user.FirstName,
                LastName = user.LastName,
                HasAgreedToPrivacyPolicy = user.HasAgreedToPrivacyPolicy,
                HasAllowedCommunication = user.HasAllowedCommunication,
                Password = user.Password.PasswordHashString(),
                ParentUserId = inv.InvitedByUserId > 0 ? inv.InvitedByUserId : _defaultUserId,
                PlanUserId = inv.InvitedByUser != null ? inv.InvitedByUser.UserId : _defaultUserId, //default placeholder;_defaultUserId; //default placeholder;
                PricingPlanId = pricingPlan.PricingPlanId,
                PlanBalanceId = inv.InvitedByUser != null ? inv.InvitedByUser.PlanBalanceId : _defaultUserId, //default placeholder;

                //// Members are Clients until promoted, new plans are admins from the start:
                //RoleId = inv.IsPlanInvitation ? (int)Roles.Client : (int)Roles.Admin,
                RoleId = (int)Roles.Admin, //making all new invitees admins from the start

                //user.PricingPlanId = (int)PricingPlans.Basic;
                SiteProfileId = inv.InvitedByUser.SiteProfileId,// int.Parse(SystemConfig.DefaultSiteProfileId);
                RegisteredOn = DateTime.Now,
                InvitationId = inv.InvitationId
            };
            //create user to get a userid
            ctx.Users.AddObject(newUser);

            return newUser;
        }
Beispiel #6
0
        // **************************************
        // Subscribe
        // **************************************
        public static PlanBalance SubscribeTo(this User user, PricingPlan pricingPlan)
        {
            using (var ctx = new SongSearchContext()) {

                var balance = ctx.SubscribeUserTo(user, pricingPlan);
                ctx.SaveChanges();

                return balance;

            }
        }