Files

10 KiB

public void SetDefaults(BMNUsersEntities bmnue, Guid userGUID) { System.Web.HttpContext http = System.Web.HttpContext.Current;

        if (userGUID == Guid.Empty)
        {
            // Creating a new account
            this.UserName = String.Empty;
            this.AccountGroups = new List<AccountGroup>();
            this.AccountSubscriptions = new List<AccountSubscription>();
            this.CanAccessPassword = false;
        }
        else
        {
            this.AccountID = userGUID;
            String accountIDString = userGUID.ToString();
            account bmnue_account = bmnue.accounts.Include("account_subscriptions").Include("account_subscriptions.Subscription").Single(a => a.UserGUID == accountIDString);
            account_contacts bmn_accounts_contact = bmnue.accounts_contacts.Single(a => a.user == bmnue_account.user);
            option bmnue_options = bmnue.options.Single(a => a.user == bmnue_account.user);

            setStaticProps(bmnue_account);

            this.UserName = bmnue_account.user;

            if (this.CanAccessPassword)
                this.PasswordUnencrypted = bmnue_account.pass2;

            this.AccountName = bmnue_account.business_name;
            this.ZoneName = bmnue_account.ZoneName;
            this.IsMultiZoneAccount = this.AccountGroups.Any(g => g.GroupType == "MultiZone");
            this.ServiceKey = bmnue_account.service;
            //this.ActiveSubscriptions = String.Join("+", bmnue_account.account_active_subscriptions.Where(aas => (aas.EndDate == null || aas.EndDate >= DateTime.UtcNow)).OrderBy(aas => aas.Subscription.SubscriptionKey).Select(aas => aas.Subscription.SubscriptionKey));
            this.ToBeDeleted = bmnue_account.ToBeDeleted;

            this.ContactName = bmn_accounts_contact.tech_contact;
            this.Phone = bmn_accounts_contact.tech_phone;
            this.Email = bmn_accounts_contact.tech_email;
            this.FBPlacePageID = bmn_accounts_contact.FBPlacePageID;
            this.IsMobileRequestsEnabled = (bmnue_options.MobileRequests == 1);
            this.VenueCode = String.IsNullOrEmpty(bmnue_options.CustomVenueCode) ? bmnue_account.user : bmnue_options.CustomVenueCode;

            this.AddressStreet1 = bmn_accounts_contact.address1;
            this.AddressStreet2 = bmn_accounts_contact.address2;
            this.AddressCity = bmn_accounts_contact.city;
            this.AddressState = bmn_accounts_contact.state;
            this.AddressZip = bmn_accounts_contact.zip;
            this.AddressCountry = bmn_accounts_contact.country;

            this.ShippingAddressStreet1 = bmn_accounts_contact.ShippingAddress1;
            this.ShippingAddressStreet2 = bmn_accounts_contact.ShippingAddress2;
            this.ShippingAddressCity = bmn_accounts_contact.ShippingCity;
            this.ShippingAddressState = bmn_accounts_contact.ShippingState;
            this.ShippingAddressZip = bmn_accounts_contact.ShippingZip;
            this.ShippingAddressCountry = bmn_accounts_contact.ShippingCountry;

            this.time_zone = bmn_accounts_contact.time_zone;
            this.latitude = bmn_accounts_contact.latitude;
            this.longitude = bmn_accounts_contact.longitude;

            //if (bmnue_account.AgreementTermMos == null)
            //    this.AgreementTermMos = 0;
            this.AgreementTermMos = bmnue_account.AgreementTermMos;

            this.AgreementStartDate = adjustUtcOffset(bmnue_account.AgreementStartDate.Value);
            this.BillAmount = bmnue_account.bill_amount;
            if (bmnue_account.billed_date != null)
                this.BilledDate = adjustUtcOffset(bmnue_account.billed_date.Value);
            else
                this.BilledDate = null;

            this.SFAccountID = bmnue_account.SFAccountID;
            this.SFQuoteID = bmnue_account.SFQuoteID;
            this.NetBanxConsumerId = bmnue_account.NetBanxConsumerId;
            this.NetBanxBillingAddressId = bmnue_account.NetBanxBillingAddressId;
            this.NetBanxPaymentMethodId = bmnue_account.NetBanxPaymentMethodId;
            this.NetBanxBillingScheduleId = bmnue_account.NetBanxBillingScheduleId;
            this.NetBanxContactMethodId = bmnue_account.NetBanxContactMethodId;
            this.PaymentMethod = bmnue_account.PaymentMethod;
            this.ElectronicPaymentMethod = bmnue_account.ElectronicPaymentMethod;
            this.CCExpiryMonth = bmnue_account.CCExpiryMonth;
            this.CCExpiryYear = bmnue_account.CCExpiryYear;
            this.CCLastDigits = bmnue_account.CCLastDigits;
            this.DDCheckNumber = bmnue_account.DDCheckNumber;
            this.DDAccountLastDigits = bmnue_account.DDAccountLastDigits;

            this.AccountSubscriptions = bmnue_account
                .account_subscriptions
                .OrderByDescending(s => s.IsBillingOverdue && s.EndDate > DateTime.UtcNow)
                .ThenByDescending(s => s.IsTrial && s.EndDate > DateTime.UtcNow)
                .ThenByDescending(s => s.IsActive)
                .ThenBy(s => s.Subscription.SubscriptionName)
                .Select(s => new AccountSubscription(this.AccountID, s.StartDate, s.EndDate)
                {
                    ID = s.id,
                    Subscription = new Models.MetadataModel.Subscription()
                    {
                        ID = s.Subscription.ID,
                        SubscriptionKey = s.Subscription.SubscriptionKey,
                        SubscriptionName = s.Subscription.SubscriptionName,
                        SubscriptionDescription = s.Subscription.SubscriptionDescription,
                        IsForPlayer = s.Subscription.IsForPlayer
                    },
                    StartDate = s.StartDate,
                    EndDate = s.EndDate,
                    //StartDateLocal = TimeZoneInfo.ConvertTimeFromUtc(s.StartDate, Models.BMNUsersModel.ModelHelpers.GetTimeZoneInfo(this.AccountID)),
                    //EndDateLocal = (s.EndDate.HasValue ? TimeZoneInfo.ConvertTimeFromUtc(s.EndDate.Value, Models.BMNUsersModel.ModelHelpers.GetTimeZoneInfo(this.AccountID)) : (DateTime?)null),
                    IsBillingOverdue = s.IsBillingOverdue,
                    IsTrial = s.IsTrial
                }).ToList();

            // Note: We're subtracting 10 minutes here so that jquery date/time selector which steps by 5min increments won't round it into the future.
            //this.NewSubscriptions = new List<account_subscription>() { new account_subscription() { StartDateLocal = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow - TimeSpan.FromMinutes(10), Models.BMNUsersModel.ModelHelpers.GetTimeZoneInfo(accountID)) } };
        }
    }

    //public DateTime? correctUTC(DateTime? passedDate)
    //{
    //    string ZoneId = "Eastern Standard Time";
    //    DateTime localtime = passedDate.Value;
    //    DateTime newTime;
    //    if (TimeZoneInfo.FindSystemTimeZoneById(ZoneId).IsDaylightSavingTime(localtime))
    //    {
    //        newTime = localtime.Add(new TimeSpan(TimeZoneInfo.FindSystemTimeZoneById(ZoneId).BaseUtcOffset.Hours + 1,
    //            TimeZoneInfo.FindSystemTimeZoneById(ZoneId).BaseUtcOffset.Minutes, TimeZoneInfo.FindSystemTimeZoneById(ZoneId).BaseUtcOffset.Seconds));
    //    }
    //    else
    //    {
    //        newTime = localtime.Add(new TimeSpan(TimeZoneInfo.FindSystemTimeZoneById(ZoneId).BaseUtcOffset.Hours,
    //            TimeZoneInfo.FindSystemTimeZoneById(ZoneId).BaseUtcOffset.Minutes, TimeZoneInfo.FindSystemTimeZoneById(ZoneId).BaseUtcOffset.Seconds));
    //    }
    //    newTime = DateTime.SpecifyKind(newTime, DateTimeKind.Local);
    //    return newTime;
    //}

    public DateTime adjustUtcOffset(DateTime date)
    {
        var tzi = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");

        if (tzi.IsDaylightSavingTime(date))
            return DateTime.SpecifyKind(date.AddHours(tzi.BaseUtcOffset.Hours + 1), DateTimeKind.Local);
        else
            return DateTime.SpecifyKind(date.AddHours(tzi.BaseUtcOffset.Hours), DateTimeKind.Local);
    }

    //DateTime dataTimeByZoneId = System.TimeZoneInfo.ConvertTime(localtime, System.TimeZoneInfo.Local, timeZoneInfo);

    /// <summary>
    /// Save for MVC requests.
    /// </summary>
    /// <param name="bmnue"></param>
    /// <param name="msd"></param>
    //public void Save(BMNUsersEntities bmnue, ManagedMediaEntities mme, ModelStateDictionary msd)
    //{
    //    foreach (KeyValuePair<String, String> error in save(bmnue, mme))
    //        msd.AddModelError(error.Key, error.Value);
    //}

    /// <summary>
    /// Save account for Web API requests.
    /// </summary>
    /// <param name="bmnue"></param>
    /// <param name="msd"></param>
    public void SaveAccount(BMNUsersEntities bmnue, ManagedMediaEntities mme, System.Web.Http.ModelBinding.ModelStateDictionary msd)
    {
        if (msd.IsValid)
            foreach (KeyValuePair<String, String> error in save(bmnue, mme))
                msd.AddModelError(error.Key, error.Value);
    }

    /// <summary>
    /// Create account Web API requests.
    /// </summary>
    /// <param name="bmnue"></param>
    /// <param name="msd"></param>
    public void CreateAccount(BMNUsersEntities bmnue, ManagedMediaEntities mme, System.Web.Http.ModelBinding.ModelStateDictionary msd)
    {
        if (msd.IsValid)
            foreach (KeyValuePair<String, String> error in create(mme, bmnue))
                msd.AddModelError(error.Key, error.Value);
    }

    #endregion

    #region Helper Methods

    Dictionary<String, String> customValidation()

=======