/// <summary> /// Create a new PlanBalance object. /// </summary> /// <param name="planBalanceId">Initial value of the PlanBalanceId property.</param> /// <param name="pricingPlanId">Initial value of the PricingPlanId property.</param> /// <param name="lastUpdatedOn">Initial value of the LastUpdatedOn property.</param> /// <param name="lastUpdatedByUserId">Initial value of the LastUpdatedByUserId property.</param> /// <param name="numberOfSongs">Initial value of the NumberOfSongs property.</param> /// <param name="numberOfInvitedUsers">Initial value of the NumberOfInvitedUsers property.</param> /// <param name="numberOfCatalogAdmins">Initial value of the NumberOfCatalogAdmins property.</param> public static PlanBalance CreatePlanBalance(global::System.Int32 planBalanceId, global::System.Int32 pricingPlanId, global::System.DateTime lastUpdatedOn, global::System.Int32 lastUpdatedByUserId, global::System.Int32 numberOfSongs, global::System.Int32 numberOfInvitedUsers, global::System.Int32 numberOfCatalogAdmins) { PlanBalance planBalance = new PlanBalance(); planBalance.PlanBalanceId = planBalanceId; planBalance.PricingPlanId = pricingPlanId; planBalance.LastUpdatedOn = lastUpdatedOn; planBalance.LastUpdatedByUserId = lastUpdatedByUserId; planBalance.NumberOfSongs = numberOfSongs; planBalance.NumberOfInvitedUsers = numberOfInvitedUsers; planBalance.NumberOfCatalogAdmins = numberOfCatalogAdmins; return planBalance; }
/// <summary> /// Deprecated Method for adding a new object to the PlanBalances EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToPlanBalances(PlanBalance planBalance) { base.AddObject("PlanBalances", planBalance); }
public static void Delete(PlanBalance planBalance) { using (var ctx = new SongSearchContext()) { ctx.Attach(planBalance); ctx.PlanBalances.DeleteObject(planBalance); ctx.SaveChanges(); } }
// ---------------------------------------------------------------------------- // (Private) // ---------------------------------------------------------------------------- // ************************************** // UpdateBalanceAmounts // ************************************** private static void UpdateBalance(this SongSearchContext ctx, PlanBalance balanceDelta) { var balance = ctx.PlanBalances.SingleOrDefault(x => x.PlanBalanceId == balanceDelta.PlanBalanceId); balance.UpdateAmountsWithDelta(balanceDelta); // Update balance for SuperAdmins (=1) if (balance.PlanBalanceId != SUPER_ADMIN_BALANCE){ var superBalance = ctx.PlanBalances.SingleOrDefault(x => x.PlanBalanceId == SUPER_ADMIN_BALANCE); superBalance.UpdateAmountsWithDelta(balanceDelta); } }
// ************************************** // NewBalanceAmount // ************************************** private static PlanBalance UpdateAmountsWithDelta(this PlanBalance balance, PlanBalance balanceDelta) { if (balance != null && balanceDelta != null) { balance.NumberOfSongs = NewBalanceAmount(balance.NumberOfSongs, balanceDelta.NumberOfSongs); balance.NumberOfInvitedUsers = NewBalanceAmount(balance.NumberOfInvitedUsers, balanceDelta.NumberOfInvitedUsers); balance.NumberOfCatalogAdmins = NewBalanceAmount(balance.NumberOfCatalogAdmins, balanceDelta.NumberOfCatalogAdmins); } return balance; }
public static void Delete(this SongSearchContext ctx, PlanBalance planBalance) { ctx.PlanBalances.DeleteObject(planBalance); }
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; }