Esempio n. 1
0
        /// <summary>
        /// Delete the matching record with primary key value
        /// </summary>
        /// <typeparam name="TEntity">Model Type</typeparam>
        /// <param name="primaryKey">primary key value of record to be delete</param>
        /// <returns>return deleted entity primary key value</returns>
        public virtual int Delete <TEntity>(long primaryKey)
        {
            TEntity entityObject = default(TEntity);

            entityObject = Activator.CreateInstance <TEntity>();
            /*define Stored Procedure Name*/
            string procedureName = this.ProcedurePrefix + GetTableName(entityObject) + "Delete";

            /*Execute Stored Procedure*/
            try
            {
                /*Add Primary Key as Parameter*/
                System.Collections.ObjectModel.Collection <DBParameters> parameters = new System.Collections.ObjectModel.Collection <DBParameters>();
                parameters.Add(new DBParameters()
                {
                    Name   = GetKeyName(entityObject),
                    Value  = primaryKey,
                    DBType = GetPropertyType(primaryKey.GetType())
                });
                DBClient.ExecuteProcedure(procedureName, ExecuteType.ExecuteNonQuery, parameters, this.DatabaseConnection);
                return(0);
            }
            catch (System.Data.SqlClient.SqlException sqlEx)
            {
                if (sqlEx.Number == 50000 || sqlEx.Number == 547)
                {
                    return(-1);
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Execute Procedure for custom methods
        /// </summary>
        /// <typeparam name="TEntity">Entity Type which require to be return as list</typeparam>
        /// <param name="procedureName">procedure name</param>
        /// <param name="parameters">parameter list</param>
        /// <returns>return procedure output</returns>
        public virtual IList <TEntity> ExecuteProcedure <TEntity>(string procedureName, System.Collections.ObjectModel.Collection <DBParameters> parameters)
        {
            var list = DBClient.ExecuteProcedure <TEntity>(procedureName, parameters, this.DatabaseConnection);

            if (list != null && list.Count() > 0)
            {
                this.SetPaginationInformation(Convert.ToInt32(GetPropertyValue(list[0], "TotalRecords"), CultureInfo.InvariantCulture));
            }

            return(list);
        }
Esempio n. 3
0
        /// <summary>
        /// Save the Current Model
        /// </summary>
        /// <typeparam name="TEntity">Model Type</typeparam>
        /// <param name="entity">Model to Save</param>
        /// <param name="procedureName">custom procedure name</param>
        /// <returns>Save records id value</returns>
        public virtual int Save <TEntity>(TEntity entity, string procedureName)
        {
            if ((this.CheckForDuplicate && !this.HasDuplicate(entity)) || !this.CheckForDuplicate)
            {
                System.Collections.ObjectModel.Collection <DBParameters> parameters = AddParameters(entity);

                /*Execute Stored Procedure*/
                object primaryKeyValue = DBClient.ExecuteProcedure(procedureName, ExecuteType.ExecuteScalar, parameters, this.DatabaseConnection);

                return(Convert.ToInt32(primaryKeyValue, CultureInfo.InvariantCulture));
            }
            else if (this.CheckForDuplicate || this.HasDuplicate(entity))
            {
                return(-2);
            }
            else
            {
                return(-1);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Check Duplicate Records in Database
        /// </summary>
        /// <typeparam name="TEntity">Model Type</typeparam>
        /// <param name="entity">Entity Model</param>
        /// <returns>returns entity is duplicate or not</returns>
        public bool HasDuplicate <TEntity>(TEntity entity)
        {
            System.Collections.ObjectModel.Collection <DBParameters> parameters = new System.Collections.ObjectModel.Collection <DBParameters>();
            parameters.Add(new DBParameters()
            {
                Name = "tableName", Value = GetTableName(entity), DBType = DbType.String
            });
            parameters.Add(new DBParameters()
            {
                Name = "columnName", Value = this.Col1Name, DBType = DbType.String
            });
            parameters.Add(new DBParameters()
            {
                Name = "columnNameValue", Value = GetPropertyValue(entity, this.Col1Name).Replace("'", "''"), DBType = DbType.String
            });
            if (!string.IsNullOrEmpty(this.Col2Name))
            {
                parameters.Add(new DBParameters()
                {
                    Name = "columnName2", Value = this.Col2Name, DBType = DbType.String
                });

                parameters.Add(new DBParameters()
                {
                    Name = "columnName2Value", Value = GetPropertyValue(entity, this.Col2Name).Replace("'", "''"), DBType = DbType.String
                });

                parameters.Add(new DBParameters()
                {
                    Name = "IsCombinationCheck", Value = this.CombinationCheckRequired, DBType = DbType.Boolean
                });
            }

            if (!string.IsNullOrEmpty(this.Col3Name))
            {
                parameters.Add(new DBParameters()
                {
                    Name = "columnName3", Value = this.Col3Name, DBType = DbType.String
                });

                parameters.Add(new DBParameters()
                {
                    Name = "columnName3Value", Value = GetPropertyValue(entity, this.Col3Name).Replace("'", "''"), DBType = DbType.String
                });
            }

            if (!string.IsNullOrEmpty(this.Col4Name))
            {
                parameters.Add(new DBParameters()
                {
                    Name = "columnName4", Value = this.Col4Name, DBType = DbType.String
                });

                parameters.Add(new DBParameters()
                {
                    Name = "columnName4Value", Value = GetPropertyValue(entity, this.Col4Name).Replace("'", "''"), DBType = DbType.String
                });
            }

            if (!string.IsNullOrEmpty(this.Col5Name))
            {
                parameters.Add(new DBParameters()
                {
                    Name = "columnName5", Value = this.Col5Name, DBType = DbType.String
                });

                parameters.Add(new DBParameters()
                {
                    Name = "columnName5Value", Value = GetPropertyValue(entity, this.Col5Name).Replace("'", "''"), DBType = DbType.String
                });
            }

            parameters.Add(new DBParameters()
            {
                Name = "primaryKey", Value = GetKeyName(entity), DBType = DbType.String
            });

            parameters.Add(new DBParameters()
            {
                Name = "primaryKeyValue", Value = GetKeyValue(entity).ToString(), DBType = DbType.String
            });

            DataSet ds = (DataSet)DBClient.ExecuteProcedure("CUSPGeneralCheckDuplicate", ExecuteType.ExecuteDataSet, parameters, this.DatabaseConnection);

            return(ds.Tables[0].Rows.Count > 0);
        }
Esempio n. 5
0
 /// <summary>
 /// Execute Procedure for custom methods
 /// </summary>
 /// <param name="procedureName">procedure name</param>
 /// <param name="executeType">execute type</param>
 /// <param name="parameters">parameter list</param>
 /// <returns>return procedure output</returns>
 public virtual object ExecuteProcedure(string procedureName, ExecuteType executeType, System.Collections.ObjectModel.Collection <DBParameters> parameters)
 {
     return(DBClient.ExecuteProcedure(procedureName, executeType, parameters, this.DatabaseConnection));
 }