Example #1
0
        /*
         * public DataAccessResponseType UpdatePlanMaxUsers(string paymentPlanName, int newUserMax, string requesterId, RequesterType requesterType)
         * {
         #region Validate Request
         *
         *  var requesterName = string.Empty;
         *  var requesterEmail = string.Empty;
         *
         *  var requestResponseType = RequestManager.ValidateRequest(requesterId,
         *      requesterType, out requesterName, out requesterEmail,
         *      Sahara.Core.Settings.Platform.Users.Authorization.Roles.SuperAdmin,
         *      null);
         *
         *  if (!requestResponseType.isApproved)
         *  {
         *      //Request is not approved, send results:
         *      return new DataAccessResponseType { isSuccess = false, ErrorMessage = requestResponseType.requestMessage };
         *
         *  }
         *
         #endregion
         *
         *  return PaymentPlanManager.UpdatePlanMaxUsers(paymentPlanName, newUserMax);
         * }
         *
         * public DataAccessResponseType UpdatePlanMaxCategories(string paymentPlanName, int newCategoryMax, string requesterId, RequesterType requesterType)
         * {
         #region Validate Request
         *
         *  var requesterName = string.Empty;
         *  var requesterEmail = string.Empty;
         *
         *  var requestResponseType = RequestManager.ValidateRequest(requesterId,
         *      requesterType, out requesterName, out requesterEmail,
         *      Sahara.Core.Settings.Platform.Users.Authorization.Roles.SuperAdmin,
         *      null);
         *
         *  if (!requestResponseType.isApproved)
         *  {
         *      //Request is not approved, send results:
         *      return new DataAccessResponseType { isSuccess = false, ErrorMessage = requestResponseType.requestMessage };
         *
         *  }
         *
         #endregion
         *
         *  return PaymentPlanManager.UpdatePlanMaxCategories(paymentPlanName, newCategoryMax);
         * }
         *
         * public DataAccessResponseType UpdatePlanMaxSubcategories(string paymentPlanName, int newSubcategoryMax, string requesterId, RequesterType requesterType)
         * {
         #region Validate Request
         *
         *  var requesterName = string.Empty;
         *  var requesterEmail = string.Empty;
         *
         *  var requestResponseType = RequestManager.ValidateRequest(requesterId,
         *      requesterType, out requesterName, out requesterEmail,
         *      Sahara.Core.Settings.Platform.Users.Authorization.Roles.SuperAdmin,
         *      null);
         *
         *  if (!requestResponseType.isApproved)
         *  {
         *      //Request is not approved, send results:
         *      return new DataAccessResponseType { isSuccess = false, ErrorMessage = requestResponseType.requestMessage };
         *
         *  }
         *
         #endregion
         *
         *  return PaymentPlanManager.UpdatePlanMaxSubcategories(paymentPlanName, newSubcategoryMax);
         * }
         *
         * public DataAccessResponseType UpdatePlanMaxTags(string paymentPlanName, int newTagMax, string requesterId, RequesterType requesterType)
         * {
         #region Validate Request
         *
         *  var requesterName = string.Empty;
         *  var requesterEmail = string.Empty;
         *
         *  var requestResponseType = RequestManager.ValidateRequest(requesterId,
         *      requesterType, out requesterName, out requesterEmail,
         *      Sahara.Core.Settings.Platform.Users.Authorization.Roles.SuperAdmin,
         *      null);
         *
         *  if (!requestResponseType.isApproved)
         *  {
         *      //Request is not approved, send results:
         *      return new DataAccessResponseType { isSuccess = false, ErrorMessage = requestResponseType.requestMessage };
         *
         *  }
         *
         #endregion
         *
         *  return PaymentPlanManager.UpdatePlanMaxTags(paymentPlanName, newTagMax);
         * }
         *
         *
         *
         * public DataAccessResponseType UpdatePlanMaxImages(string paymentPlanName, int newImageMax, string requesterId, RequesterType requesterType)
         * {
         #region Validate Request
         *
         *  var requesterName = string.Empty;
         *  var requesterEmail = string.Empty;
         *
         *  var requestResponseType = RequestManager.ValidateRequest(requesterId,
         *      requesterType, out requesterName, out requesterEmail,
         *      Sahara.Core.Settings.Platform.Users.Authorization.Roles.SuperAdmin,
         *      null);
         *
         *  if (!requestResponseType.isApproved)
         *  {
         *      //Request is not approved, send results:
         *      return new DataAccessResponseType { isSuccess = false, ErrorMessage = requestResponseType.requestMessage };
         *
         *  }
         *
         #endregion
         *
         *  return PaymentPlanManager.UpdatePlanMaxImages(paymentPlanName, newImageMax);
         * }
         *
         *
         * public DataAccessResponseType UpdatePlanAllowImageEnhancements(string paymentPlanName, bool allowEnhancements, string requesterId, RequesterType requesterType)
         * {
         #region Validate Request
         *
         *  var requesterName = string.Empty;
         *  var requesterEmail = string.Empty;
         *
         *  var requestResponseType = RequestManager.ValidateRequest(requesterId,
         *      requesterType, out requesterName, out requesterEmail,
         *      Sahara.Core.Settings.Platform.Users.Authorization.Roles.SuperAdmin,
         *      null);
         *
         *  if (!requestResponseType.isApproved)
         *  {
         *      //Request is not approved, send results:
         *      return new DataAccessResponseType { isSuccess = false, ErrorMessage = requestResponseType.requestMessage };
         *
         *  }
         *
         #endregion
         *
         *  return PaymentPlanManager.UpdatePlanAllowImageEnhancements(paymentPlanName, allowEnhancements);
         * }
         *
         */
        #endregion


        #endregion

        #region Delete

        public DataAccessResponseType DeletePaymentPlan(string paymentPlanName, string requesterId, RequesterType requesterType, string sharedClientKey)
        {
            // Ensure the clients are certified.
            if (sharedClientKey != Sahara.Core.Platform.Requests.RequestManager.SharedClientKey)
            {
                return(null);
            }

            #region Validate Request

            var requesterName  = string.Empty;
            var requesterEmail = string.Empty;

            var requestResponseType = RequestManager.ValidateRequest(requesterId,
                                                                     requesterType, out requesterName, out requesterEmail,
                                                                     Sahara.Core.Settings.Platform.Users.Authorization.Roles.SuperAdmin,
                                                                     null);

            if (!requestResponseType.isApproved)
            {
                //Request is not approved, send results:
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = requestResponseType.requestMessage
                });
            }
            #endregion

            return(PaymentPlanManager.DeletePaymentPlan(paymentPlanName));
        }
Example #2
0
        public static ConstraintResponseType CheckUserConstraint(string accountId)
        {
            var response = new ConstraintResponseType {
                isConstrained = false
            };

            // Get the Account & the associated Plan:
            var account = AccountManager.GetAccount(accountId);
            var plan    = PaymentPlanManager.GetPaymentPlan(account.PaymentPlanName);

            int maxUsers = plan.MaxUsers;

            int userCount       = account.Users.Count;
            int invitationCount = AccountUserManager.GetInvitations(accountId, account.StoragePartition).Count;

            int totalAssociatedUsers = (userCount + invitationCount) - 1; //<--Offset by 1 to hide: platformadmin@[Config_PlatformEmail]  LEGACY: //<-- We remove 1 user from the validation as the account creator does not count in the constraint

            if (maxUsers <= totalAssociatedUsers)
            {
                response.isConstrained     = true;
                response.constraintMessage = "You have reached your limit of " + maxUsers + " users.";
            }


            return(response);
        }
Example #3
0
        public static List <AlternateRate> AssignAlternateRates(decimal MonthlyRate)
        {
            var results = new List <AlternateRate>();

            if (MonthlyRate > 0)
            {
                var frequencies = PaymentPlanManager.GetPaymentFrequencies();

                foreach (var frequency in frequencies)
                {
                    //Ignore the FREE and base MONTHLY rates or any rate at a month or below
                    if (frequency.PaymentFrequencyMonths > 1)
                    {
                        decimal price             = Convert.ToDecimal(Sahara.Core.Common.Methods.Billing.GenerateStripePlanAmountInCents(MonthlyRate, frequency.PaymentFrequencyMonths, frequency.PriceBreak));
                        string  savingsPercentage = frequency.PriceBreak.ToString().Substring((frequency.PriceBreak.ToString().IndexOf(".") + 1));

                        string frequencyInterval = string.Empty;

                        if (frequency.IntervalCount > 1)
                        {
                            frequencyInterval = frequency.IntervalCount + " " + frequency.Interval.ToLower() + "s";
                        }
                        else
                        {
                            frequencyInterval = frequency.Interval;
                        }

                        results.Add(
                            new AlternateRate {
                            FrequencyInMonths = frequency.PaymentFrequencyMonths,
                            FrequencyName     = frequency.PaymentFrequencyName,
                            FrequencyInterval = frequencyInterval,
                            DiscountedPrice   = price,
                            SavingsPercentage = savingsPercentage,
                            Description       = "Save " + savingsPercentage + "% per " + frequency.Interval.ToLower() + "!"
                        }
                            );
                    }
                }
            }

            return(results);
        }
Example #4
0
        public static DataAccessResponseType ProvisionPlatform(string FirstName, string LastName, string Email, string password)
        {
            // Begin timing task
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            DataAccessResponseType response = new DataAccessResponseType();

            if (!isPlatformInitialized())
            {
                //Generate Databases & Schemas
                PlatformInitialization platformInitialization = new PlatformInitialization();
                response = platformInitialization.InitializePlatform();

                if (response.isSuccess)
                {
                    try
                    {
                        //Create initial Platform User & Assign to SuperAdmin Role
                        var createUserResult = PlatformUserManager.CreatePlatformUser(Email, FirstName, LastName, password, Sahara.Core.Settings.Platform.Users.Authorization.Roles.SuperAdmin);
                        if (createUserResult.isSuccess)
                        {
                            //Replicate Payment Plans to Stripe Account:
                            //StripeInitialization.SeedPaymentPlans();
                            var stripePlansResponse = PaymentPlanManager.DuplicatePlansToStripe();

                            if (!stripePlansResponse.isSuccess)
                            {
                                response.isSuccess    = false;
                                response.ErrorMessage = "An error occured when creating Stripe plans";
                                return(response);
                            }


                            /*======================================
                             *   Create AccountPartition Document Database
                             * ========================================*/

                            /*  Retired ------------------*/

                            //var client = Sahara.Core.Settings.Azure.DocumentDB.DocumentClients.AccountDocumentClient;
                            var databasename = Sahara.Core.Settings.Azure.DocumentDB.AccountPartitionDatabaseId;

                            Database accountDatabase = Sahara.Core.Settings.Azure.DocumentDbClients.AccountDocumentClient.CreateDatabaseQuery().Where(db => db.Id == databasename).ToArray().FirstOrDefault();
                            if (accountDatabase == null)
                            {
                                //Create if not exists
                                accountDatabase = Sahara.Core.Settings.Azure.DocumentDbClients.AccountDocumentClient.CreateDatabaseAsync(new Database {
                                    Id = databasename
                                }).Result;
                            }



                            /*======================================
                             *   Clear all logs ()
                             * ========================================*/

                            //PlatformLogManager.ClearLogs();

                            /*======================================
                             *   Log Initilization of Platform
                             * ========================================*/

                            stopwatch.Stop();

                            PlatformLogManager.LogActivity(
                                CategoryType.Platform,
                                ActivityType.Platform_Initialized,
                                "Platform initilized by: " + FirstName + " " + LastName + " (" + Email + ")",
                                "Initialization took " + String.Format("{0:0,0.00}", TimeSpan.FromMilliseconds(stopwatch.ElapsedMilliseconds).TotalMinutes) + " minute(s) to complete"
                                );


                            response.isSuccess      = true;
                            response.SuccessMessage = "Platform has been successfully initialized and '" + Email + "' has been registered as the initial platform administrator.";
                        }
                    }
                    catch (Exception e)
                    {
                        response.isSuccess    = false;
                        response.ErrorMessage = e.Message;
                        try
                        {
                            response.ErrorMessages.Add(e.InnerException.Message);
                        }
                        catch
                        {
                        }
                    }
                }

                return(response);
            }
            else
            {
                response.isSuccess    = false;
                response.ErrorMessage = "Platform is already initialized.";
                response.ErrorMessages.Add("If you are attempting to create a new installation on this envionemnt: You must first clear all platfrom components manually.");

                return(response);
            }
        }
Example #5
0
 public PaymentPlanManagerTests()
 {
     _paymentPlanManager = new PaymentPlanManager();
 }
 public PaymentPlanController()
 {
     _paymentPlanManager = new PaymentPlanManager();
 }
Example #7
0
        public DataAccessResponseType CreatePaymentPlan(string paymentPlanName, decimal monthlyRate, int maxUsers,
                                                        int maxCategorizationsPerSet, int maxProductsPerSet, int maxProperties, int maxValuesPerProperty, int maxTags,
                                                        bool allowSalesLeads, bool allowImageEnhancements, bool allowLocationData, bool allowCustomOrdering, bool allowThemes, int monthlySupportHours,
                                                        int maxImageGroups, int maxImageFormats, int maxImageGalleries, int maxImagesPerGallery,
                                                        bool visible,
                                                        string requesterId, RequesterType requesterType, string sharedClientKey)
        {
            // Ensure the clients are certified.
            if (sharedClientKey != Sahara.Core.Platform.Requests.RequestManager.SharedClientKey)
            {
                return(null);
            }

            #region Validate Request

            var requesterName  = string.Empty;
            var requesterEmail = string.Empty;

            var requestResponseType = RequestManager.ValidateRequest(requesterId,
                                                                     requesterType, out requesterName, out requesterEmail,
                                                                     Sahara.Core.Settings.Platform.Users.Authorization.Roles.SuperAdmin,
                                                                     null);

            if (!requestResponseType.isApproved)
            {
                //Request is not approved, send results:
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = requestResponseType.requestMessage
                });
            }
            #endregion

            var paymentPlan = new PaymentPlan
            {
                PaymentPlanName = paymentPlanName,
                MonthlyRate     = monthlyRate,
                MaxUsers        = maxUsers,

                MaxCategorizationsPerSet = maxCategorizationsPerSet,
                MaxProductsPerSet        = maxProductsPerSet,

                MaxProperties        = maxProperties,
                MaxValuesPerProperty = maxValuesPerProperty,

                MaxTags = maxTags,
                AllowImageEnhancements = allowImageEnhancements,
                MonthlySupportHours    = monthlySupportHours,
                //BasicSupport = basicSupport,
                //EnhancedSupport = enhancedSupport,
                AllowSalesLeads     = allowSalesLeads,
                AllowLocationData   = allowLocationData,
                AllowCustomOrdering = allowCustomOrdering,
                AllowThemes         = allowThemes,

                MaxImageGroups      = maxImageGroups,
                MaxImageFormats     = maxImageFormats,
                MaxImageGalleries   = maxImageGalleries,
                MaxImagesPerGallery = maxImagesPerGallery,

                Visible = visible
            };

            return(PaymentPlanManager.CreatePaymentPlan(paymentPlan));
        }
Example #8
0
 public PaymentFrequency GetPaymentFrequency(string frequencyId)
 {
     return(PaymentPlanManager.GetPaymentFrequency(frequencyId));
 }
Example #9
0
 public PaymentPlan GetPaymentPlan(string planName)
 {
     return(PaymentPlanManager.GetPaymentPlan(planName));
 }
Example #10
0
 public List <PaymentFrequency> GetPaymentFrequencies()
 {
     return(PaymentPlanManager.GetPaymentFrequencies());
 }
Example #11
0
 public List <PaymentPlan> GetPaymentPlans(bool includeHiddenPlans, bool orderByRateAsc)
 {
     return(PaymentPlanManager.GetPaymentPlans(includeHiddenPlans, orderByRateAsc));
 }
Example #12
0
        public static Account DataReader_to_Account(SqlDataReader reader)
        {
            Account account = new Account();

            account.AccountName    = (String)reader["AccountName"];
            account.AccountNameKey = (String)reader["AccountNameKey"];
            account.AccountID      = (Guid)reader["AccountID"];


            #region Legacy Document Database Properties

            /*
             * if (reader["DocumentDatabaseLink"] != DBNull.Value)
             * {
             *  account.DocumentDatabaseLink = (String)reader["DocumentDatabaseLink"];
             * }
             * else
             * {
             *  account.DocumentDatabaseLink = null;
             * }
             *
             * if (reader["PropertiesCollectionLink"] != DBNull.Value)
             * {
             *  account.PropertiesCollectionLink = (String)reader["PropertiesCollectionLink"];
             * }
             * else
             * {
             *  account.PropertiesCollectionLink = null;
             * }
             *
             *
             * if (reader["SelfLinkReferencesDocumentLink"] != DBNull.Value)
             * {
             *  account.SelfLinkReferencesDocumentLink = (String)reader["SelfLinkReferencesDocumentLink"];
             * }
             * else
             * {
             *  account.SelfLinkReferencesDocumentLink = null;
             * }
             */

            #endregion


            #region Transform Stripe Payments Properties

            if (reader["StripeCustomerID"] != DBNull.Value)
            {
                account.StripeCustomerID = (String)reader["StripeCustomerID"];
            }
            else
            {
                account.StripeCustomerID = null;
            }

            if (reader["StripeSubscriptionID"] != DBNull.Value)
            {
                account.StripeSubscriptionID = (String)reader["StripeSubscriptionID"];
            }
            else
            {
                account.StripeSubscriptionID = null;
            }


            if (reader["StripeCardID"] != DBNull.Value)
            {
                account.StripeCardID = (String)reader["StripeCardID"];
            }
            else
            {
                account.StripeCardID = null;
            }

            #endregion

            account.Active      = (Boolean)reader["Active"];
            account.Provisioned = (Boolean)reader["Provisioned"];

            account.CreatedDate = (DateTime)reader["CreatedDate"];

            account.Closed          = ((Boolean)reader["Closed"]);
            account.ClosureApproved = ((Boolean)reader["ClosureApproved"]);
            account.Delinquent      = ((Boolean)reader["Delinquent"]);


            if (reader["CardExpiration"] != DBNull.Value)
            {
                account.CardExpiration = (DateTime)reader["CardExpiration"];
            }

            if (reader["LockedDate"] != DBNull.Value)
            {
                account.Locked = true;
            }
            else
            {
                account.Locked = false;
            }

            if (reader["Logo"] != DBNull.Value)
            {
                account.Logo = (String)reader["Logo"];
            }
            else
            {
                account.Logo = null;
            }


            account.PaymentPlanName        = ((string)reader["PaymentPlanName"]);
            account.PaymentFrequencyMonths = ((int)reader["PaymentFrequencyMonths"]);



            if (reader["AccountEndDate"] != DBNull.Value)
            {
                account.AccountEndDate = (DateTime)reader["AccountEndDate"];
            }

            if (reader["PhoneNumber"] != DBNull.Value)
            {
                account.PhoneNumber = (String)reader["PhoneNumber"];
            }


            if (reader["SqlPartition"] != DBNull.Value)
            {
                account.SqlPartition = (String)reader["SqlPartition"];
            }

            if (reader["StoragePartition"] != DBNull.Value)
            {
                account.StoragePartition = (String)reader["StoragePartition"];
            }

            if (reader["SearchPartition"] != DBNull.Value)
            {
                account.SearchPartition = (String)reader["SearchPartition"];
            }

            /*
             * if (reader["DocumentPartition"] != DBNull.Value)
             * {
             *  account.DocumentPartition = (String)reader["DocumentPartition"];
             *  //account.ProductSearchIndex = Common.Methods.Strings.ConvertDocumentCollectionNameToSearchIndexName(account.DocumentPartition);
             * }*/


            if (reader["ProvisionedDate"] != DBNull.Value)
            {
                account.ProvisionedDate = (DateTime)reader["ProvisionedDate"];
            }

            //Assign PaymentPlan & Frequency Objects
            try
            {
                account.PaymentPlan      = PaymentPlanManager.GetPaymentPlan(account.PaymentPlanName);
                account.PaymentFrequency = PaymentPlanManager.GetPaymentFrequency(account.PaymentFrequencyMonths.ToString());
            }
            catch (Exception e)
            {
                #region Log Exception

                PlatformExceptionsHelper.LogExceptionAndAlertAdmins(
                    e,
                    "attempting to retreive paymentplan or paymentfrequency object during transformations for Account object",
                    System.Reflection.MethodBase.GetCurrentMethod(),
                    account.AccountID.ToString(),
                    account.AccountName);

                #endregion
            }


            return(account);
        }