예제 #1
0
        /// <summary>
        /// Custom save for current project (ICBS)
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        public virtual int Add <TEntity>(TEntity entity, string productUid = null)
        {
            try
            {
                if ((this.CheckForDuplicate && !this.HasDuplicate(entity)) || !this.CheckForDuplicate)
                {
                    string procedureName = GetTableName(entity) + "_add";

                    System.Collections.ObjectModel.Collection <DBParameters> parameters = AddParameters(entity);

                    AppConfiguration appSettings = new AppConfiguration(productUid);
                    /*Execute Stored Procedure*/
                    object primaryKeyValue = DBClient.ExecuteProcedure(procedureName, ExecuteType.ExecuteScalar, parameters, appSettings.GetConnectionString);

                    return(Convert.ToInt32(primaryKeyValue, CultureInfo.InvariantCulture));
                }
                else
                {
                    return(-1);
                }
            }
            catch (Exception)
            {
                return(-1);
            }
        }
예제 #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, string productUid = null)
        {
            AppConfiguration appSettings = new AppConfiguration(productUid);
            var list = DBClient.ExecuteProcedure <TEntity>(procedureName, parameters, appSettings.GetConnectionString);

            if (list != null && list.Any() && !string.IsNullOrEmpty(GetPropertyValue(list[0], "total_records")))
            {
                this.SetPaginationInformation(Convert.ToInt32(GetPropertyValue(list[0], "total_records"), CultureInfo.InvariantCulture));
            }
            return(list);
        }
예제 #3
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>
        private bool HasDuplicate <TEntity>(TEntity entity, string productUid = null)
        {
            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
                });
            }

            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
            });
            AppConfiguration appSettings = new AppConfiguration();
            DataSet          ds          = (DataSet)DBClient.ExecuteProcedure("UspGeneralCheckDuplicate", ExecuteType.ExecuteDataSet, parameters, appSettings.GetConnectionString);

            return(ds.Tables[0].Rows.Count > 0);
        }
예제 #4
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>(int primaryKey, string productUid = null)
        {
            TEntity entityObject = default(TEntity);

            entityObject = Activator.CreateInstance <TEntity>();
            /*define Stored Procedure Name*/
            string procedureName = string.Empty;

            if (entityObject != null)
            {
                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())
                });
                AppConfiguration appSettings = new AppConfiguration(productUid);
                DBClient.ExecuteProcedure(procedureName, ExecuteType.ExecuteNonQuery, parameters, appSettings.GetConnectionString);
                return(0);
            }
            catch (System.Data.SqlClient.SqlException sqlEx)
            {
                if (sqlEx.Number == 50000 || sqlEx.Number == 547)
                {
                    return(-1);
                }
                else
                {
                    throw;
                }
            }
        }
예제 #5
0
        public virtual IList <TEntity> ExecuteProcedureWithPerameterwithoutPagination <TEntity>(string procedureName, System.Collections.ObjectModel.Collection <DBParameters> parameters, string productUid = null)
        {
            AppConfiguration appSettings = new AppConfiguration(productUid);

            return(DBClient.ExecuteProcedure <TEntity>(procedureName, parameters, appSettings.GetConnectionString));
        }
예제 #6
0
        /// <summary>
        /// Executes the procedurewith out parameter.
        /// </summary>
        /// <param name="procedureName">Name of the procedure.</param>
        /// <param name="executeType">Type of the execute.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="dic">The dic.</param>
        /// <returns></returns>
        public virtual object ExecuteProcedurewithOutParameter(string procedureName, ExecuteType executeType, System.Collections.ObjectModel.Collection <DBParameters> parameters, out Dictionary <string, string> dic, string productUid = null)
        {
            AppConfiguration appSettings = new AppConfiguration(productUid);

            return(DBClient.ExecuteProcedurewithOutParameter(procedureName, executeType, parameters, appSettings.GetConnectionString, out dic));
        }
예제 #7
0
        /// <summary>
        /// Execute Procedure for custom methods without pagination
        /// </summary>
        /// <param name="procedureName"></param>
        /// <returns>returns data table</returns>
        public virtual DataTable ExecuteProcedurewithoutPaginationDatatable(string procedureName, System.Collections.ObjectModel.Collection <DBParameters> parameter, string productUid = null)
        {
            AppConfiguration appSettings = new AppConfiguration(productUid);

            return(DBClient.ExecuteProcedureDatatable(procedureName, parameter, appSettings.GetConnectionString));
        }
예제 #8
0
        /// <summary>
        /// Execute Procedure for custom methods without pagination
        /// </summary>
        /// <typeparam name="TEntity">Entity Type which require to be return as list</typeparam>
        /// <param name="procedureName">procedure name</param>
        /// <returns>return procedure output</returns>
        public virtual IList <TEntity> ExecuteProcedurewithoutPagination <TEntity>(string procedureName, string productUid = null)
        {
            AppConfiguration appSettings = new AppConfiguration(productUid);

            return(DBClient.ExecuteProcedure <TEntity>(procedureName, null, appSettings.GetConnectionString));
        }