コード例 #1
0
ファイル: QueryManager.cs プロジェクト: ChuckLafferty/bugnet
        /// <summary>
        /// Saves or updates the instance.
        /// </summary>
        /// <param name="projectId">The current project id</param>
        /// <param name="userName">The current user name</param>
        /// <param name="entity">The query to save or update</param>
        /// <returns></returns>
        public static bool SaveOrUpdate(string userName, int projectId, Query entity)
        {
            if (entity == null) throw new ArgumentNullException("entity");
            if (string.IsNullOrEmpty(entity.Name)) throw (new ArgumentException("The query name cannot be empty or null"));
            if (entity.Clauses.Count == 0) throw new ArgumentException("The query must have at least one query clause");

            return entity.Id > Globals.NEW_ID ?  
                DataProviderManager.Provider.UpdateQuery(entity.Id, userName, projectId, entity.Name, entity.IsPublic, entity.Clauses) :
            DataProviderManager.Provider.SaveQuery(userName, projectId, entity.Name, entity.IsPublic, entity.Clauses);
        }
コード例 #2
0
        /// <summary>
        /// This method is called when a user clicks the Save Query button.
        /// The method saves the query to a database table.
        /// </summary>
        void SaveQuery()
        {
            if (!Page.IsValid) return;

            var queryName = txtQueryName.Text.Trim();
            var userName = Security.GetUserName();

            if (queryName == String.Empty) return;

            var queryClauses = BuildQuery();

            if (queryClauses.Count == 0) return;

            var query = new Query
                            {
                                Id = _queryId,
                                Name = queryName,
                                IsPublic = chkGlobalQuery.Checked,
                                Clauses = queryClauses
                            };

            var success = QueryManager.SaveOrUpdate(userName, ProjectId, query);

            if (success)
                Response.Redirect(string.Format("QueryList.aspx?pid={0}", ProjectId));
            else
                Message1.ShowErrorMessage(GetLocalResourceObject("SaveQueryError").ToString());
        }