Ejemplo n.º 1
0
        public virtual T TCommitData <T>(List <T> list, string proc, char action, short instance = 1, string ignoreParas = "")
        {
            string    fields = string.Empty;
            DataTable table  = CreateDataTable(list, ignoreParas);
            var       para   = DataTableToSqlParameterArray(table, action, ref fields);

            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    try
                    {
                        DapperConfiguration.OpenConnection(instance);

                        var data = (T)DapperConfiguration.db.Query <T>(proc, para, commandType: System.Data.CommandType.StoredProcedure);

                        DapperConfiguration.CloseConnection();

                        scope.Complete();
                        return(data);
                    }
                    catch (Exception ex)
                    {
                        Logger.LogError(ex);
                        return(default(T));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                return(default(T));
            }
        }
Ejemplo n.º 2
0
        public async Task <List <Slider> > GetAll()
        {
            using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                //A transactionscope must be disposed on the same thread that it was created
                try
                {
                    DapperConfiguration.OpenConnection(1);

                    var data = await DapperConfiguration.db.QueryAsync <Slider>("usp_spa_Slider",
                                                                                new { Id = GlobalVariables.IsTransParameter },
                                                                                commandType : System.Data.CommandType.StoredProcedure);

                    DapperConfiguration.CloseConnection();

                    scope.Complete();
                    return(data.ToList());
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex);
                    return(null);
                }
            }
        }
Ejemplo n.º 3
0
        public List <PostStateHistory> GetAll()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    DapperConfiguration.OpenConnection(1);

                    var data = DapperConfiguration.db.Query <PostStateHistory>("usp_PostStateHistory", commandType: System.Data.CommandType.StoredProcedure).ToList();

                    DapperConfiguration.CloseConnection();

                    scope.Complete();
                    return(data);
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog("Execute Category get data: " + ex.Message);
                    return(null);
                }
            }
        }
Ejemplo n.º 4
0
        public List <Advertise> GetAll()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    DapperConfiguration.OpenConnection(1);

                    var data = DapperConfiguration.db.Query <Advertise>("usp_spa_Advertise",
                                                                        new { Id = GlobalVariables.IsTransParameter },
                                                                        commandType: System.Data.CommandType.StoredProcedure).ToList();

                    DapperConfiguration.CloseConnection();

                    scope.Complete();
                    return(data);
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex);
                    return(null);
                }
            }
        }
Ejemplo n.º 5
0
        public Configuration GetById(byte id)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    DapperConfiguration.OpenConnection(1);

                    var data = DapperConfiguration.db.Query <Configuration>("usp_spa_CMSConfig",
                                                                            new { Id = id },
                                                                            commandType: System.Data.CommandType.StoredProcedure).FirstOrDefault();

                    DapperConfiguration.CloseConnection();

                    scope.Complete();
                    return(data);
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex);
                    return(null);
                }
            }
        }