Ejemplo n.º 1
0
        public static ValidationResponseType IsValidLastName(string lastName)
        {
            ValidationResponseType response = new ValidationResponseType();

            if (lastName == null || lastName == "")
            {
                response.isValid           = false;
                response.validationMessage = "Last name cannot be blank.";

                return(response);
            }
            if (lastName.Length < Settings.Accounts.Registration.UserLastNameMinimumLength || lastName.Length > Settings.Accounts.Registration.UserLastNameNameMaximunLength)
            {
                response.isValid           = false;
                response.validationMessage = "Last name must be between " + Settings.Accounts.Registration.UserLastNameMinimumLength + "-" + Settings.Accounts.Registration.UserLastNameNameMaximunLength + " characters in length.";

                return(response);
            }
            else if (lastName.Contains(" ")) //|| Disallow special characters: (Regex.IsMatch(lastName, "^[a-zA-Z0-9 ]*$")) == false)
            {
                response.isValid           = false;
                response.validationMessage = "Last name cannot contain spaces."; // or special charcters.";

                return(response);
            }
            else
            {
                response.isValid = true;
            }


            return(response);
        }
Ejemplo n.º 2
0
        public static ValidationResponseType IsValidPaymentPlanName(string PlanName)
        {
            ValidationResponseType response = new ValidationResponseType();

            //Check if name is null
            if (PlanName == null || PlanName == String.Empty)
            {
                response.isValid           = false;
                response.validationMessage = "Plan name is blank.";

                return(response);
            }

            //Check if name has any spaces
            if (PlanName.Contains("  "))
            {
                response.isValid           = false;
                response.validationMessage = "Plan name cannot contain any double empty spaces";

                return(response);
            }

            //Check if the character length conforsms to policy
            if (PlanName.Length < 2 || PlanName.Length > 25)
            {
                response.isValid           = false;
                response.validationMessage = "Plan name must be between " + 2 + "-" + 35 + " characters long.";

                return(response);
            }
            //We allow for spaces, dashes, ampersands and apostrophes, so we remove them before doing a regex for other special characters
            else if ((Regex.IsMatch(PlanName.Replace("(", "").Replace(")", "").Replace(" ", ""), @"^[a-zA-Z0-9]+$")) == false)
            {
                response.isValid           = false;
                response.validationMessage = "Plan name cannot contain special characters";

                return(response);
            }
            else
            {
                //Check if PlanName Exists ====================
                SqlBoolStatements sqlBoolStatements = new SqlBoolStatements();
                bool accountExists = sqlBoolStatements.PlanNameExists(PlanName);

                if (accountExists)
                {
                    response.isValid           = false;
                    response.validationMessage = "Plan with that name already exists.";

                    return(response);
                }
                else
                {
                    response.isValid = true;
                }
            }


            return(response);
        }
Ejemplo n.º 3
0
        public static ValidationResponseType IsValidImageFormatName(string imageFormatName)
        {
            ValidationResponseType response = new ValidationResponseType();

            //Check if name is null
            if (imageFormatName == null || imageFormatName == String.Empty)
            {
                response.isValid           = false;
                response.validationMessage = "Name cannot be blank.";

                return(response);
            }

            //Check if Objcect Name is a system reserved name:
            foreach (string reservedName in Settings.Objects.Names.ReservedImageFormatNames)
            {
                if (Sahara.Core.Common.Methods.ObjectNames.ConvertToObjectNameKey(imageFormatName) == reservedName)
                {
                    response.isValid           = false;
                    response.validationMessage = imageFormatName + " is a reserved name.";

                    return(response);
                }
            }

            //Check if name has ANY whitespace(s)
            if (imageFormatName.Contains(" "))
            {
                response.isValid           = false;
                response.validationMessage = "Name cannot contain any spaces.";

                return(response);
            }

            //Check if the character length conforsms to policy
            if (imageFormatName.Length < Settings.Objects.Names.ObjectNameMinimumLength || imageFormatName.Length > Settings.Objects.Names.ObjectNameMaximunLength)
            {
                response.isValid           = false;
                response.validationMessage = "Name must be between " + Settings.Objects.Names.ObjectNameMinimumLength + "-" + Settings.Objects.Names.ObjectNameMaximunLength + " characters long.";

                return(response);
            }
            //We ONLY allow for letters
            else if ((Regex.IsMatch(imageFormatName, @"^[a-zA-Z0-9]+$")) == false)
            {
                response.isValid           = false;
                response.validationMessage = "Name can only contain letters and numbers. No special characters allowed.";

                return(response);
            }
            else
            {
                response.isValid = true;
            }


            return(response);
        }
 /// <summary>
 /// Constructor to init message, name, originalValue and type
 /// </summary>
 /// <param name="message">The message</param>
 /// <param name="name">The name of the validation</param>
 /// <param name="originalValue">The original value that was validated</param>
 /// <param name="type">The response type</param>
 public ValidationResponse(
     string message,
     string name,
     object originalValue,
     ValidationResponseType type)
 {
     Message       = message;
     Name          = name;
     OriginalValue = originalValue;
     Type          = type;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// method for determining that provided email address is valid
        /// </summary>
        /// <param name="email">email address to validate</param>
        /// <returns>true is valid, false if not valid</returns>
        public static ValidationResponseType IsValidEmail(string email)
        {
            ValidationResponseType response = new ValidationResponseType();

            //regular expression pattern for valid email
            //addresses, allows for the following domains:
            //com,edu,info,gov,int,mil,net,org,biz,name,museum,coop,aero,pro,tv
            string pattern = @"^[-a-zA-Z0-9][-.a-zA-Z0-9]*@[-.a-zA-Z0-9]+(\.[-.a-zA-Z0-9]+)*\.(com|edu|info|gov|int|mil|net|org|biz|name|museum|coop|aero|pro|tv|[a-zA-Z]{2}|[a-zA-Z]{3}|[a-zA-Z]{4})$";
            //Regular expression object
            Regex check = new Regex(pattern, RegexOptions.IgnorePatternWhitespace);

            //boolean variable to return to calling method
            response.isValid = false;


            //make sure an email address was provided
            if (string.IsNullOrEmpty(email))
            {
                response.isValid = false;
            }
            else
            {
                //use IsMatch to validate the address
                response.isValid = check.IsMatch(email);
            }
            //return the value to the calling method

            //Check if additional invalid characters exist

            /*
             * if(email.Contains(")") || email.Contains("(") || email.Contains(""))
             * {
             *
             * }*/


            if (!response.isValid)
            {
                response.validationMessage = "You must use a valid email address.";
                return(response);
            }
            else
            {
                response.isValid           = true;
                response.validationMessage = "Email is valid!";
                return(response);
            }
        }
Ejemplo n.º 6
0
        public static DataAccessResponseType CreateTag(Account account, string tagName)
        {
            #region Convert multiple spaces with single

            tagName = Regex.Replace(tagName, @"\s+", " ");

            #endregion

            #region Validate Tag Name:

            ValidationResponseType ojectNameValidationResponse = ValidationManager.IsValidTagName(tagName);
            if (!ojectNameValidationResponse.isValid)
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = ojectNameValidationResponse.validationMessage
                });
            }

            #endregion

            #region validate tag does not exist

            var tags = GetTags(account.AccountNameKey);
            foreach (string tag in tags)
            {
                if (tag.ToLower() == tagName.ToLower())
                {
                    return(new DataAccessResponseType {
                        isSuccess = false, ErrorMessage = "A tag with that name already exists."
                    });
                }
            }

            #endregion

            var tagEntity = new TagTableEntity(account.AccountID.ToString(), account.StoragePartition, tagName);

            var response = Internal.StoreTag(tagEntity, account.StoragePartition);

            if (response.isSuccess)
            {
                Caching.InvalidateTagsCache(account.AccountNameKey);
            }

            return(response);
        }
Ejemplo n.º 7
0
        public static ValidationResponseType IsValidPhoneNumber(string phoneNumber)
        {
            ValidationResponseType response = new ValidationResponseType();


            //string pattern = @"(\([2-9]\d\d\)|[2-9]\d\d) ?[-.,]? ?[2-9]\d\d ?[-.,]? ?\d{4}";
            //Regex check = new Regex(pattern);


            if (phoneNumber == null)
            {
                response.isValid           = false;
                response.validationMessage = "Phone number cannot be blank.";

                return(response);
            }
            if (phoneNumber.Replace("-", "").Replace("(", "").Replace(")", "").Replace(" ", "").Length < 10)
            {
                response.isValid           = false;
                response.validationMessage = "Please include area code or country code.";

                return(response);
            }
            if (phoneNumber.Length > 28)
            {
                response.isValid           = false;
                response.validationMessage = "Phone number is too long.";

                return(response);
            }
            //if (!check.IsMatch(phoneNumber.Replace(" ", "").Replace("-", "").Replace(".", "")))
            //{
            //response.isValid = false;
            //response.validationMessage = "Phone number is not valid. Please make sure you include area code and/or country codes.";

            //return response;
            //}
            else
            {
                response.isValid = true;
            }


            return(response);
        }
Ejemplo n.º 8
0
        public static ValidationResponseType IsValidPlatformUserPassword(string Password)
        {
            ValidationResponseType response = new ValidationResponseType();

            if (Password.Length < Settings.Platform.Users.Authentication.PasswordMinimumLength)
            {
                response.isValid           = false;
                response.validationMessage = "Password must be at least " + Settings.Platform.Users.Authentication.PasswordMinimumLength + " characters in length.";

                return(response);
            }
            else
            {
                response.isValid = true;
            }


            return(response);
        }
Ejemplo n.º 9
0
        public static ValidationResponseType IsValidPropertyName(string propertyName)
        {
            ValidationResponseType response = new ValidationResponseType();

            //Check if name is null
            if (propertyName == null || propertyName == String.Empty)
            {
                response.isValid           = false;
                response.validationMessage = "Property cannot be blank.";

                return(response);
            }

            //Check if Property Name is a system reserved name:
            foreach (string reservedName in Settings.Objects.Names.ReservedPropertyNames)
            {
                if (Sahara.Core.Common.Methods.PropertyNames.ConvertToPropertyNameKey(propertyName) == reservedName)
                {
                    response.isValid           = false;
                    response.validationMessage = propertyName + " is a reserved name.";

                    return(response);
                }
            }

            if (propertyName.ToLower().Contains("locationmetadata"))
            {
                response.isValid           = false;
                response.validationMessage = "Property cannot contain the term 'locationmetadata'.";

                return(response);
            }

            //Check if name has trailing whitespace(s)
            if (Regex.IsMatch(propertyName, @"\s+$"))
            {
                response.isValid           = false;
                response.validationMessage = "Property cannot contain empty spaces at the end.";

                return(response);
            }

            //Check if name has whitespace(s) at front
            if (propertyName[0].ToString() == " ")
            {
                response.isValid           = false;
                response.validationMessage = "Property cannot contain an empty space as the first character.";

                return(response);
            }

            //Check if the character length conforsms to policy
            if (propertyName.Length < Settings.Objects.Names.TagNameMinimumLength || propertyName.Length > Settings.Objects.Names.TagNameMaximunLength)
            {
                response.isValid           = false;
                response.validationMessage = "Property must be between " + Settings.Objects.Names.PropertyNameMinimumLength + "-" + Settings.Objects.Names.PropertyNameMaximunLength + " characters long.";

                return(response);
            }
            //We allow for spaces, dashes, ampersands and apostrophes, so we remove them before doing a regex for other special characters
            else if ((Regex.IsMatch(propertyName, "^[a-zA-Z0-9\\-\\s]*$")) == false)
            {
                response.isValid           = false;
                response.validationMessage = "Property cannot contain special characters";

                return(response);
            }
            else
            {
                response.isValid = true;
            }

            if (propertyName.Contains(","))
            {
                response.isValid           = false;
                response.validationMessage = "Property cannot contain commas";

                return(response);
            }


            return(response);
        }
Ejemplo n.º 10
0
        public static ValidationResponseType IsValidAccountName(string AccountName)
        {
            AccountName = AccountName.Trim(); //<---We trim here, since registration will also trim

            ValidationResponseType response = new ValidationResponseType();

            //Check if name is null
            if (AccountName == null || AccountName == String.Empty)
            {
                response.isValid           = false;
                response.validationMessage = "Account name is blank.";

                return(response);
            }

            //Check if Accounts Name is a system reserved name:
            foreach (string reservedName in Settings.Accounts.Registration.ReservedAccountNames)
            {
                if (Sahara.Core.Common.Methods.AccountNames.ConvertToAccountNameKey(AccountName) == reservedName)
                {
                    response.isValid           = false;
                    response.validationMessage = AccountName + " is a reserved name.";

                    return(response);
                }
            }
            //Check if name has trailing whitespace(s)
            if (Regex.IsMatch(AccountName, @"\s+$"))
            {
                response.isValid           = false;
                response.validationMessage = "Name cannot contain empty spaces at the end.";

                return(response);
            }

            //Check if name has whitespace(s) at front
            if (AccountName[0].ToString() == " ")
            {
                response.isValid           = false;
                response.validationMessage = "Name cannot contain an empty space as the first character.";

                return(response);
            }

            //Check if the character length conforsms to policy
            if (AccountName.Length < Settings.Accounts.Registration.AccountNameMinimumLength || AccountName.Length > Settings.Accounts.Registration.AccountNameMaximunLength)
            {
                response.isValid           = false;
                response.validationMessage = "Name must be between " + Settings.Accounts.Registration.AccountNameMinimumLength + "-" + Settings.Accounts.Registration.AccountNameMaximunLength + " characters long.";

                return(response);
            }
            //We allow for spaces, dashes, ampersands and apostrophes, so we remove them before doing a regex for other special characters
            else if ((Regex.IsMatch(Sahara.Core.Common.Methods.AccountNames.ConvertToAccountNameKey(AccountName), "^[a-zA-Z0-9\\-]*$")) == false)
            {
                response.isValid           = false;
                response.validationMessage = "Name cannot contain special characters";

                return(response);
            }
            else
            {
                //Check if AccountName Exists ====================
                SqlBoolStatements sqlBoolStatements = new SqlBoolStatements();
                bool accountExists = sqlBoolStatements.AccountNameExists(AccountName);

                if (accountExists)
                {
                    response.isValid           = false;
                    response.validationMessage = "Account with that name already exists.";

                    return(response);
                }
                else
                {
                    response.isValid = true;
                }
            }

            //check if subdomain will be less than minimum character length after shortening (to avoid names like "--T--" being able to create subdomains like "t")
            if (Sahara.Core.Common.Methods.AccountNames.ConvertToAccountNameKey(AccountName).Length < Settings.Accounts.Registration.AccountNameMinimumLength)
            {
                response.isValid           = false;
                response.validationMessage = "Name must have at least " + Settings.Accounts.Registration.AccountNameMinimumLength + " alphanumeric characters.";

                return(response);
            }


            return(response);
        }
        public static DataAccessResponseType RegisterNewAccount(RegisterNewAccountModel model)
        {
            //trim the name of whitespaces (start & end):
            model.AccountName = model.AccountName.Trim();

            #region Refactoring notes

            /*
             *
             *  With some refactoring you can start them directly with a chosen payment plan by passing a planid parameter to the Registration site (and ultimatly into this method) along with C.C. info
             *
             *  This method will then check for a MonthlyRate > 0 and attempt to process the C.C.
             *  note: You would only add a Credit Card capture form to the Registration site if a plan with a MonthlyRate above 0 is selected -->
             *
             *
             *
             *  -- Adding a new "AllowRegistration" bool to the PaymentPlan object will allow for validation of selected plans coming in from users on this method for scenarios where users can choose a plan while signing up to avoid passing in ID's for plans such as "Unlimited" which must be approved by a Platform Admin
             *
             */

            #endregion

            var response = new DataAccessResponseType {
                isSuccess = true
            };

            try
            {
                #region Validate Account Info
                //Validate Registration Data:

                #region Refactoring notes

                /*
                 *
                 *
                 *  -- Adding a new "AllowRegistration" bool to the PaymentPlan object will allow for validation of selected plans coming in from users on AccountRegistrationManager for scenarios where users can choose a plan while signing up to avoid passing in ID's for plans such as "Unlimited" which must be approved by a Platform Admin
                 *
                 *              > response.ErrorMessages.Add("Not a valid payment plan for public registration");
                 *
                 */

                #endregion


                #region Validate Password(s) Match
                if (model.Password != model.ConfirmPassword)
                {
                    response.isSuccess = false;

                    response.ErrorMessages.Add("Password and password confirmation do not match");
                }
                #endregion

                #region Validate Account Name:

                ValidationResponseType accountNameValidationResponse = ValidationManager.IsValidAccountName(model.AccountName);
                if (!accountNameValidationResponse.isValid)
                {
                    response.isSuccess = false;

                    response.ErrorMessages.Add(accountNameValidationResponse.validationMessage);

                    //return response;
                }

                #endregion

                #region Validate User Name

                ValidationResponseType firstNameValidationResponse = ValidationManager.IsValidFirstName(model.FirstName);
                if (!firstNameValidationResponse.isValid)
                {
                    response.isSuccess = false;

                    response.ErrorMessages.Add(firstNameValidationResponse.validationMessage);

                    //return response;
                }

                ValidationResponseType lastNameValidationResponse = ValidationManager.IsValidLastName(model.LastName);
                if (!lastNameValidationResponse.isValid)
                {
                    response.isSuccess = false;

                    response.ErrorMessages.Add(lastNameValidationResponse.validationMessage);

                    //return response;
                }

                #endregion


                #region Validate Email Unique (Optional)

                /*
                 * var userValidation = AccountUserManager.GetUserIdentity(model.Email);
                 * if (userValidation != null)
                 * {
                 *  response.isSuccess = false;
                 *  response.ErrorMessages.Add("Another account is associated with that email address, please provide another");
                 * }
                 */

                #endregion


                //If validation(s) fails, return the response:
                if (response.isSuccess == false)
                {
                    //Log Platform Activity
                    string errors = string.Empty;

                    foreach (string error in response.ErrorMessages)
                    {
                        errors += error + "|";
                    }

                    PlatformLogManager.LogActivity(CategoryType.Registration,
                                                   ActivityType.Registration_Failed,
                                                   String.Format("Registration failed for: '{0}' by: {1} from: {2}", model.AccountName, model.Email, model.Origin),
                                                   String.Format("Errors:{0}", errors
                                                                 ));

                    //Return the response
                    response.ErrorMessage = "Could not register this account";
                    return(response);
                }

                #endregion


                // Generate AccountID ====================================
                Guid accountId = Guid.NewGuid();

                #region Register Initial AccountUser (AKA: AccountOwner)


                #region Validate & Create Account Owner User

                // Further validations and account owner creation:

                var registerUserResponse = AccountUserManager.RegisterAccountOwner(
                    model.FirstName,
                    model.LastName,
                    accountId.ToString(),
                    model.AccountName,
                    model.Email,
                    model.Password
                    );

                #endregion

                if (!registerUserResponse.isSuccess)
                {
                    //Log Platform Activity
                    string errors = string.Empty;

                    foreach (string error in registerUserResponse.ErrorMessages)
                    {
                        errors += error + "|";
                    }

                    PlatformLogManager.LogActivity(CategoryType.Registration,
                                                   ActivityType.Registration_Failed,
                                                   String.Format("Registration failed for: '{0}' by: {1} from: {2}", model.AccountName, model.Email, model.Origin),
                                                   String.Format("Errors:{0}", errors
                                                                 ));

                    //Return the response
                    response.isSuccess    = false;
                    response.ErrorMessage = registerUserResponse.ErrorMessage;

                    response.ErrorMessages = registerUserResponse.ErrorMessages;

                    return(response);
                }

                //Get user back from result
                var user = (AccountUserIdentity)registerUserResponse.ResponseObject;

                #endregion

                #region Create Account

                try
                {
                    // Create Accounts =============================================================

                    InsertStatements insertStatements = new InsertStatements();
                    var insertResult = insertStatements.InsertNewAccount(model, accountId);

                    if (insertResult.isSuccess)
                    {
                        // (Optional) for certain scenrios
                        //Add user to account, make them the owner, and assign them as SuperAdmin role:
                        //AccountManager.AddUserToAccount(user.Id, AccountID.ToString(), true); // <-- Only for certain scenarios

                        response.isSuccess      = true;
                        response.SuccessMessage = Sahara.Core.Settings.Copy.PlatformMessages.AccountRegistration.SuccessMessage;

                        var origin = "";
                        if (model.Origin != null)
                        {
                            origin = "<br/><br/><b>Origin:</b> " + model.Origin;
                        }

                        var name  = "<br/><br/><b>Name:</b> " + model.FirstName + " " + model.LastName;
                        var email = "<br/><br/><b>Email:</b> " + model.Email;

                        var phone = "";
                        if (model.PhoneNumber != null)
                        {
                            phone = "<br/><br/><b>Phone:</b> " + model.PhoneNumber;
                        }

                        try
                        {
                            //Send an alert to the platform admin(s):
                            EmailManager.Send(
                                Settings.Endpoints.Emails.PlatformEmailAddresses,
                                Settings.Endpoints.Emails.FromRegistration,
                                "Registration",
                                "New Registrant",
                                "A new account named <b>'" + model.AccountName + "'</b> has just been registered." + name + email + phone + origin,
                                true
                                );
                        }
                        catch
                        {
                        }

                        //Log The Activity ------------ :
                        //PlatformLogManager.LogActivity(CategoryType.Registration,
                        //ActivityType.Registration_Succeeded,
                        //String.Format("Registration completed for: '{0}' by: {1} from: {2}", model.AccountName, model.Email, model.Origin),
                        //String.Format("Name:'{0}', Email:'{1}', Origin:{2}", model.AccountName, model.Email, model.Origin));

                        PlatformLogManager.LogActivity(CategoryType.Account,
                                                       ActivityType.Account_Registered,
                                                       String.Format("Registration completed for: '{0}' by: {1} from: {2}", model.AccountName, model.Email, model.Origin),
                                                       String.Format("Name:'{0}', Email:'{1}', Origin:{2}", model.AccountName, model.Email, model.Origin),
                                                       accountId.ToString(),
                                                       model.AccountName,
                                                       null,
                                                       null,
                                                       null,
                                                       null,
                                                       model.Origin);


                        return(response);
                    }
                    else
                    {
                        #region Error Handling
                        string error = insertResult.ErrorMessage;

                        AccountUser outUser = null;

                        //rollback user creation:
                        AccountUserManager.DeleteUser(user.Id, false, out outUser);

                        //Log The Activity ------------ :
                        PlatformLogManager.LogActivity(CategoryType.Registration,
                                                       ActivityType.Registration_Failed,
                                                       String.Format("Registration failed for: '{0}' by: {1} from: {2}", model.AccountName, model.Email, model.Origin),
                                                       String.Format("Error:{0}", error));

                        //PlatformLogManager.LogActivity(ErrorLogActivity.PlatformError,
                        //String.Format("Registration failed for: '{0}' by: {1} from: {2}", model.AccountName, model.Email, model.Origin),
                        //String.Format("Error:{0}", error));


                        response.isSuccess    = false;
                        response.ErrorMessage = error;

                        response.ErrorMessages.Add(error);

                        return(response);

                        #endregion
                    }
                }
                catch (Exception e)
                {
                    #region Error Handling
                    string error = String.Empty;

                    AccountUser outUser = null;

                    //rollback user creation:
                    AccountUserManager.DeleteUser(user.Id, false, out outUser);

                    try
                    {
                        error = e.Message;
                    }
                    catch
                    {
                        error = "An error occured";
                    }

                    //rollback user:
                    //To Do: AccountUserManager.DeleteUser(model.Email);

                    string errorDetails = String.Format("Registration failed for: '{0}' by: {1} from: {2}", model.AccountName, model.Email, model.Origin);

                    //Log The Error(s) ------------ :
                    PlatformLogManager.LogActivity(CategoryType.Registration,
                                                   ActivityType.Registration_Error,
                                                   errorDetails,
                                                   String.Format("Error:{0}", error));



                    PlatformExceptionsHelper.LogExceptionAndAlertAdmins(
                        e,
                        "registering a new account for " + model.AccountName + " / " + model.Email + " / " + model.FirstName + " " + model.LastName + " from: " + model.Origin,
                        System.Reflection.MethodBase.GetCurrentMethod());


                    response.isSuccess    = false;
                    response.ErrorMessage = error;

                    response.ErrorMessages.Add(error);

                    return(response);

                    #endregion
                }



                #endregion
            }
            catch (Exception e)
            {
                //Log The Error(s) ------------ :
                PlatformLogManager.LogActivity(CategoryType.Registration,
                                               ActivityType.Registration_Error,
                                               String.Format("Registration failed for: '{0}' by: {1} from: {2}", model.AccountName, model.Email, model.Origin),
                                               String.Format("Error:{0}", e.Message));



                PlatformExceptionsHelper.LogExceptionAndAlertAdmins(
                    e,
                    "registering a new account for " + model.AccountName + " / " + model.Email + " / " + model.FirstName + " " + model.LastName + " from: " + model.Origin,
                    System.Reflection.MethodBase.GetCurrentMethod());



                response.isSuccess    = false;
                response.ErrorMessage = "An error occured when creating the account";

                response.ErrorMessages.Add(e.Message);

                try
                {
                    response.ErrorMessages.Add(e.InnerException.InnerException.Message);
                }
                catch
                {
                }

                return(response);
            }
        }
Ejemplo n.º 12
0
        public static DataAccessResponseType  CreateImageFormat(Account account, string imageGroupTypeNameKey, string imageGroupNameKey, string imageFormatName, int width, int height, bool listing, bool gallery)
        {
            var response = new DataAccessResponseType();

            #region Validate Plan Restrictions

            if (GetCustomImageFormatCount(account.AccountNameKey) >= account.PaymentPlan.MaxImageFormats)
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "You have reached your account restriction of " + account.PaymentPlan.MaxImageFormats + " custom image formats"
                });
            }

            if (gallery && GetCustomImageGalleryCount(account.AccountNameKey) >= account.PaymentPlan.MaxImageGalleries)
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "You have reached your account restriction of " + account.PaymentPlan.MaxImageGalleries + " custom image galleries"
                });
            }

            #endregion

            #region Validate Platform Restrictions

            if (listing)
            {
                if (GetCustomImageFormatsAsListingCount(account.AccountNameKey) >= Settings.Objects.Limitations.MaximumImageFormatsAsListings)
                {
                    return(new DataAccessResponseType {
                        isSuccess = false, ErrorMessage = "You have reached the platform restriction of " + Settings.Objects.Limitations.MaximumImageFormatsAsListings + " listing images per inventory"
                    });
                }
            }

            #endregion

            #region Validate Input

            if (String.IsNullOrEmpty(imageGroupTypeNameKey))
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "imageGroupTypeNameKey cannot be empty"
                });
            }

            if (String.IsNullOrEmpty(imageGroupNameKey))
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "imageGroupNameKey cannot be empty"
                });
            }

            if (String.IsNullOrEmpty(imageFormatName))
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "imageFormatName cannot be empty"
                });
            }

            if (listing && gallery)
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "Image format cannot be both a Listing and a Gallery"
                });
            }

            if (height < 1)
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "Image height must be taller than 1px"
                });
            }
            if (width < 0)
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "Image width must be a positive number"
                });
            }
            //if (width < 1) //<-- 0 now means that this is a VARIABLE WIDTH image
            //{
            //return new DataAccessResponseType { isSuccess = false, ErrorMessage = "Image width must be wider than 1px" };
            //}

            if (height > 4000)
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "Image height cannot be taller than 4,000px"
                });
            }
            if (width > 4000)
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "Image width cannot be wider than 4,000px"
                });
            }

            #endregion

            #region Validate Image Format Name:

            ValidationResponseType ojectNameValidationResponse = ValidationManager.IsValidImageFormatName(imageFormatName);
            if (!ojectNameValidationResponse.isValid)
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = ojectNameValidationResponse.validationMessage
                });
            }

            #endregion

            //CREATE NAME KEY
            var imageFormatNameKey = Sahara.Core.Common.Methods.ObjectNames.ConvertToObjectNameKey(imageFormatName);

            #region Validate GroupType Exists

            var imageGroupTypes = GetImageFormatGroupTypes();

            bool typeExists = false;

            foreach (ImageFormatGroupTypeModel type in imageGroupTypes)
            {
                if (type.ImageFormatGroupTypeNameKey == imageGroupTypeNameKey)
                {
                    typeExists = true;
                }
            }

            if (!typeExists)
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "Format group type '" + imageGroupTypeNameKey + "' does not exists!"
                });
            }

            #endregion

            var imageFormats = GetImageFormats(account.AccountNameKey, imageGroupTypeNameKey);

            #region Validate Group Exists in this Type

            bool groupExistsInType = false;

            foreach (ImageFormatGroupModel group in imageFormats)
            {
                if (group.ImageFormatGroupTypeNameKey == imageGroupTypeNameKey && group.ImageFormatGroupNameKey == imageGroupNameKey)
                {
                    groupExistsInType = true;
                }
            }

            if (!groupExistsInType)
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "Format group '" + imageGroupNameKey + "' does not exists!"
                });
            }

            #endregion

            #region Validate Format name is unique to this group/type combo

            bool nameUniqueInGroup = true;

            foreach (ImageFormatGroupModel group in imageFormats)
            {
                if (group.ImageFormatGroupTypeNameKey == imageGroupTypeNameKey && group.ImageFormatGroupNameKey == imageGroupNameKey)
                {
                    foreach (ImageFormatModel format in group.ImageFormats)
                    {
                        if (format.ImageFormatName == imageFormatName || format.ImageFormatNameKey == imageFormatNameKey)
                        {
                            nameUniqueInGroup = false;
                        }
                    }
                }
            }

            if (!nameUniqueInGroup)
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "Format name '" + imageFormatNameKey + "' is not unique to the '" + imageGroupNameKey + "' group!"
                });
            }

            #endregion

            #region Create Model & ID

            var imageFormat = new ImageFormatModel
            {
                ImageFormatGroupTypeNameKey = imageGroupTypeNameKey,
                ImageFormatGroupNameKey     = imageGroupNameKey,

                ImageFormatID      = Guid.NewGuid(),
                ImageFormatName    = imageFormatName,
                ImageFormatNameKey = imageFormatNameKey,

                Height = height,
                Width  = width,

                Listing = listing,
                Gallery = gallery
            };

            #endregion

            //INSERT
            response = Sql.Statements.InsertStatements.InsertImageFormat(account.SqlPartition, account.SchemaName, imageFormat); //, account.PaymentPlan.MaxImageFormats);

            //CLear Cache
            if (response.isSuccess)
            {
                Caching.InvalidateImageFormatCaches(account.AccountNameKey);
            }

            return(response);
        }
Ejemplo n.º 13
0
        public static DataAccessResponseType CreateImageGroup(Account account, string imageGroupTypeNameKey, string imageGroupName)
        {
            var response = new DataAccessResponseType();

            #region Validate Input

            #region Validate Image Group Name:

            ValidationResponseType ojectNameValidationResponse = ValidationManager.IsValidImageGroupName(imageGroupName);
            if (!ojectNameValidationResponse.isValid)
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = ojectNameValidationResponse.validationMessage
                });
            }

            #endregion


            if (String.IsNullOrEmpty(imageGroupTypeNameKey))
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "imageGroupTypeNameKey cannot be empty"
                });
            }

            if (String.IsNullOrEmpty(imageGroupName))
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "imageGroupName cannot be empty"
                });
            }

            #endregion

            #region Validate Plan Restrictions

            if (GetCustomImageGroupCount(account.AccountNameKey) >= account.PaymentPlan.MaxImageGroups)
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "You have reached your account restriction of " + account.PaymentPlan.MaxImageGroups + " custom image groups"
                });
            }

            #endregion

            //CREATE NAME KEY
            var imageGroupNameKey = Sahara.Core.Common.Methods.ObjectNames.ConvertToObjectNameKey(imageGroupName);

            #region Validate GroupType Exists

            var imageGroupTypes = GetImageFormatGroupTypes();

            bool typeExists = false;

            foreach (ImageFormatGroupTypeModel type in imageGroupTypes)
            {
                if (type.ImageFormatGroupTypeNameKey == imageGroupTypeNameKey)
                {
                    typeExists = true;
                }
            }

            if (!typeExists)
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "Format group type '" + imageGroupTypeNameKey + "' does not exists!"
                });
            }

            #endregion

            #region Validate GroupName is unique to this type

            var imageFormats = GetImageFormats(account.AccountNameKey, imageGroupTypeNameKey);

            bool nameUniqueInType = true;

            foreach (ImageFormatGroupModel group in imageFormats)
            {
                if (group.ImageFormatGroupTypeNameKey == imageGroupTypeNameKey && group.ImageFormatGroupNameKey == imageGroupNameKey)
                {
                    nameUniqueInType = false;
                }
            }

            if (!nameUniqueInType)
            {
                return(new DataAccessResponseType {
                    isSuccess = false, ErrorMessage = "Group name '" + imageGroupNameKey + "' is not unique to the '" + imageGroupTypeNameKey + "' type!"
                });
            }

            #endregion

            #region Create Model & ID

            var imageGroup = new ImageFormatGroupModel
            {
                ImageFormatGroupTypeNameKey = imageGroupTypeNameKey,

                ImageFormatGroupID      = Guid.NewGuid(),
                ImageFormatGroupName    = imageGroupName,
                ImageFormatGroupNameKey = imageGroupNameKey
            };

            imageGroup.ImageFormatGroupID = Guid.NewGuid();

            #endregion

            //INSERT
            response = Sql.Statements.InsertStatements.InsertImageGroup(account.SqlPartition, account.SchemaName, imageGroup); //, account.PaymentPlan.MaxImageGroups);

            //CLear Cache
            if (response.isSuccess)
            {
                Caching.InvalidateImageFormatCaches(account.AccountNameKey);
            }

            return(response);
        }
Ejemplo n.º 14
0
        public static DataAccessResponseType CreateProperty(Account account, string propertyTypeNameKey, string propertyName)
        {
            //TO DO: Always clear/update caches AND update counts!

            var response = new DataAccessResponseType();

            #region Validate Property Name:

            ValidationResponseType propertyNameValidationResponse = ValidationManager.IsValidPropertyName(propertyName);
            if (!propertyNameValidationResponse.isValid)
            {
                response.isSuccess    = false;
                response.ErrorMessage = propertyNameValidationResponse.validationMessage;
                response.ErrorMessages.Add(propertyNameValidationResponse.validationMessage);

                return(response);
            }

            #endregion

            var property = new PropertyModel
            {
                PropertyTypeNameKey = propertyTypeNameKey,
                PropertyID          = Guid.NewGuid(),
                PropertyName        = propertyName,
                PropertyNameKey     = Sahara.Core.Common.Methods.PropertyNames.ConvertToPropertyNameKey(propertyName),
                SearchFieldName     = Sahara.Core.Common.Methods.PropertyNames.ConvertToPropertyNameKey(propertyName, true),
                Facetable           = false,
                Sortable            = false,
                Listing             = false,
                Details             = true
            };

            #region Check if this name already exists

            var propertyExists = GetProperty(account, property.PropertyNameKey);

            if (propertyExists != null)
            {
                response.isSuccess    = false;
                response.ErrorMessage = "A property with that name already exists.";

                return(response);
            }

            #endregion



            response = Sql.Statements.InsertStatements.InsertProperty(account.SqlPartition, account.SchemaName, property);

            var searchUpdateResponse = new DataAccessResponseType();

            if (response.isSuccess)
            {
                //Clear Category Caches:
                Caching.InvalidateAllPropertyCachesForAccount(account.AccountNameKey);

                //Update Search Index Fields
                searchUpdateResponse = ProductSearchManager.AddProductPropertyToSearchIndexFields(account.SearchPartition, account.ProductSearchIndex, property.SearchFieldName, propertyTypeNameKey);
            }

            if (!searchUpdateResponse.isSuccess)
            {
                #region Rollback and send Error

                //Delete the property
                Sql.Statements.DeleteStatements.DeleteProperty(account.SqlPartition, account.SchemaName, property.PropertyID.ToString());

                //Return the error
                return(searchUpdateResponse);

                #endregion
            }

            //Clear Caches & Send Response:
            Caching.InvalidateAllPropertyCachesForAccount(account.AccountNameKey);
            response.SuccessMessage = property.PropertyID.ToString(); //<--Returned for logging purposes

            return(response);
        }