Пример #1
0
        /// <summary>
        /// Add a new saved search or update an existing saved search to the database
        /// </summary>
        /// <param name="name"></param>
        /// <param name="description"></param>
        /// <param name="objectList"></param>
        /// <param name="update"></param>
        /// <returns>Any errors that occurred in the user addition</returns>
        public List <ValidationError> ValidateSavedSearch(int ID, string name, string description, List <SearchObject> objectList, bool updating)
        {
            List <ValidationError> validationErrors = new List <ValidationError>();

            try
            {
                SavedSearch search = new SavedSearch(_connectionString, _provider);

                // Perform validation
                if (name != String.Empty)
                {
                    if (description != String.Empty)
                    {
                        if (objectList.Count < 1)
                        {
                            //If everything has been passed then set the saved search object to contain all the features
                            search.Name          = name;
                            search.Description   = description;
                            search.searchObjects = objectList;
                        }
                        validationErrors.Add(new ValidationError("The search cannot be for nothing"));
                    }
                    else
                    {
                        validationErrors.Add(new ValidationError("Description field cannot be blank"));
                    }
                }
                else
                {
                    validationErrors.Add(new ValidationError("Search Name field cannot be blank"));
                }

                search.ID = ID;

                if (validationErrors.Count == 0)
                {
                    // Saves the user to the database and returns an array of errors (strings) if any occurred
                    search.Save(updating);
                }
            }
            catch (Exception ex)
            {
                validationErrors.Add(new ValidationError("Unexpected Error: " + ex.ToString().Replace('\'', '"')));
            }
            return(validationErrors);
        }
Пример #2
0
        public List <ValidationError> DeleteSavedSearch(int id)
        {
            List <ValidationError> errors = new List <ValidationError>();

            try
            {
                if (id != -1)
                {
                    SavedSearch savedSearchToDelete = new SavedSearch(_connectionString, _provider);
                    savedSearchToDelete.Delete(id);
                }
                else
                {
                    errors.Add(new ValidationError("Could not delete Saved Search. Invalid ID."));
                }
            }
            catch (Exception ex)
            {
                errors.Add(new ValidationError("Unexpected Error: " + ex.ToString().Replace('\'', '"')));
            }
            return(errors);
        }