Ejemplo n.º 1
0
        public static ResultObje Saves(List <ParamValue> paramValues, string table)
        {
            var result = new ResultObje();

            try
            {
                using (var connection = DBHelper.Connection())
                {
                    var param = paramValues.Aggregate(
                        string.Empty, (current, paramValue) => current + string.Format("{0},", paramValue.Key));
                    var value = paramValues.Aggregate(
                        string.Empty, (current, paramValue) => current + string.Format("@{0},", paramValue.Key));

                    result.id = DataProcessingInsert.Insert(table, param, value, connection, paramValues);
                    connection.Close();
                    result.success = true;
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.Mesaj   = ex.Message;
                throw new Exception(ex.Message);
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The entity management update.
        /// </summary>
        /// <param name="entity">
        /// The entity.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        /// <exception cref="Exception">
        /// </exception>
        public static ResultObje Update(T entity)
        {
            var type = typeof(T);

            if (type.Name == "Object")
            {
                type = entity.GetType();
            }

            var result = new ResultObje();

            var pkProperty = type.GetProperties()
                             .Where(p => p.GetCustomAttributes(typeof(PrimaryKeyAttribute), true).Length > 0)
                             .FirstOrDefault();

            try
            {
                var table = (entity).GetType().BaseType.Name == "Object" ? entity.GetType().Name : (entity).GetType().BaseType.Name;

                string selectSql = string.Format("{0} * {1} {2} {3} {4}= @p1", SqlQueryEnum.SELECT, SqlQueryEnum.FROM,
                                                 table, SqlQueryEnum.WHERE, pkProperty.Name);

                var adapter = new SqlDataAdapter(selectSql, DBHelper.Connection());
                adapter.SelectCommand.Parameters.AddWithValue("@p1", pkProperty.GetValue(entity, null));

                var dTable = new System.Data.DataTable();

                adapter.Fill(dTable);

                var row = dTable.Rows[0];

                EntityValue <T> .GetValueRow(entity, dTable, type, ref row);

                var cmdBuilder = new SqlCommandBuilder(adapter);
                adapter.UpdateCommand = cmdBuilder.GetUpdateCommand();
                result.success        = true;
                try
                {
                    adapter.Update(new[] { row });
                }
                catch (Exception ex)
                {
                    result.success = false;
                    result.Mesaj   = ex.Message;
                    throw new Exception(ex.Message);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.Mesaj   = ex.Message;
                throw new Exception("Pk Attribute Olmadığı İçin Kayıt Yapılamaz. HATA KODU: " + ex.Message);
            }

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Daha İyi Bir Şekilde Yazılmalı
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="dbTablo"></param>
        /// <returns></returns>
        public static ResultObje Saves(List <T> entity, object dbTablo = null)
        {
            var result = new ResultObje();

            try
            {
                using (var connection = DBHelper.Connection())
                {
                    var tblName = entity.FirstOrDefault();
                    if (tblName != null && dbTablo == null)
                    {
                        dbTablo = (tblName).GetType().BaseType.Name == "Object" ? tblName.GetType().Name : (tblName).GetType().BaseType.Name;
                    }

                    foreach (var item in entity)
                    {
                        var param = string.Empty;
                        var value = string.Empty;

                        var paramValues = new List <ParamValue>();

                        var property = PropertiesTransactions <T> .DefaulRemoveValueProperty(item, dbTablo);

                        var props = new List <PropertyInfo>(property);

                        EntityValue <T> .GetValue(item, props, ref param, ref value, ref paramValues);

                        connection.Open();

                        result.id = DataProcessingInsert.Insert(dbTablo, param, value, connection, paramValues);

                        connection.Close();
                    }
                    result.success = true;
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.Mesaj   = ex.Message;
                throw new Exception(ex.Message);
            }
            return(result);
        }
Ejemplo n.º 4
0
        public static ResultObje Saves(T entity, string dbTablo = null)
        {
            var result = new ResultObje();

            try
            {
                if (string.IsNullOrEmpty(dbTablo))
                {
                    dbTablo = (entity).GetType().BaseType.Name == "Object" ? entity.GetType().Name : (entity).GetType().BaseType.Name;
                }

                using (var connection = DBHelper.Connection())
                {
                    var param = string.Empty;
                    var value = string.Empty;

                    var paramValues = new List <ParamValue>();

                    var property = PropertiesTransactions <T> .DefaulRemoveValueProperty(entity, dbTablo);

                    var props = new List <PropertyInfo>(property);

                    EntityValue <T> .GetValue(entity, props, ref param, ref value, ref paramValues);

                    connection.Open();

                    result.id = DataProcessingInsert.Insert(dbTablo, param, value, connection, paramValues);

                    connection.Close();

                    result.success = true;
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.Mesaj   = ex.Message;
                throw new Exception(ex.Message);
            }
            return(result);
        }