Example #1
0
        protected void Logging(string logger, DateTime createTime, LogLevel level, string message,
                               string stackTrace, UserClientInfo userClient = null, IDbTransaction trans = null)
        {
            var sql =
                @"INSERT INTO {0} (Logger, CreateTime, LogLevel, Message, IsException, StackTrace, Thread, Method, UserID, UserIP, UserBrowser, UserOS) 
                               VALUES (@logger, @createTime, @logLevel, @message, @isException, @stackTrace, @thread, @method, @userID, @userIP, @userBrowser, @userOS)";

            sql = string.Format(sql, Repository.GetTableAttr <Log>().Name);

            SqlParameter[] para =
            {
                new SqlParameter("@logger",      logger),
                new SqlParameter("@createTime",  createTime),
                new SqlParameter("@logLevel",    level.ToString()),
                new SqlParameter("@message",     message),
                new SqlParameter("@isException", !string.IsNullOrEmpty(stackTrace)),
                new SqlParameter("@stackTrace",  stackTrace),
                new SqlParameter("@thread",      string.Empty),
                new SqlParameter("@method",      string.Empty),
                new SqlParameter("@userID",      userClient?.UserID ?? -1),
                new SqlParameter("@userIP",      userClient != null ? userClient.UserIP : "127.0.0.1"),
                new SqlParameter("@userBrowser", userClient != null ? userClient.UserBrowser : string.Empty),
                new SqlParameter("@userOS",      userClient != null ? userClient.UserOS : string.Empty)
            };

            // no logging method
            using (IDapperHelper dapper = DapperHelper.GetInstance())
            {
                dapper.Execute(sql, para.ToDapperParameters(), null, ignoreLog: true);
            }
        }
Example #2
0
        public int Delete(int JobId)
        {
            var data = _dapperHelper.Execute($"Delete [Job] where JObId={JobId}", null,
                                             commandType: CommandType.Text);

            return(data);
        }
Example #3
0
        public int Insert <T>(T instance) where T : class, IDao
        {
            var listCol     = new List <string>();
            var listColPara = new List <string>();
            var sqlPara     = new DynamicParameters(new { });

            foreach (var pi in instance.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                var attrCol = GetColumnAttr(pi);

                if (attrCol != null)
                {
                    var value = pi.GetValue(instance, null);

                    listCol.Add(attrCol.Name);
                    listColPara.Add("@" + attrCol.Name);

                    sqlPara.Add(attrCol.Name, value == null && pi.PropertyType == typeof(string) ? string.Empty : value);
                }
            }

            var attr = GetTableAttr <T>();

            if (listCol.Count > 0 && listColPara.Count > 0 && sqlPara.ParameterNames.Any())
            {
                if (instance is IEntity)
                {
                    // skip the property of the self-increase main-key
                    var primary = instance.GetType().GetProperty("ID");

                    if (primary.PropertyType != typeof(int))
                    {
                        listCol.Add(attr.Key);
                        listColPara.Add("@key");
                        sqlPara.Add("key", primary.GetValue(instance, null));
                    }
                }

                string sql = $@"INSERT INTO {attr.Name} ({string.Join(", ", listCol.ToArray())}) 
                                     VALUES ({string.Join(", ", listColPara.ToArray())})";

                return(_dapper.Execute(sql, sqlPara));
            }

            return(-1);
        }
        public int DeleteCompany(int ID)
        {
            var data = _dapperHelper.Execute("Delete College where ID ='" + ID + "'", null, commandType: CommandType.Text);

            return(data);
        }
        /// <summary>
        /// This method is used for delete the employee details
        /// </summary>
        /// <param name="EmployeeId"></param>
        /// <returns></returns>
        public int Delete(int EmployeeId)
        {
            var data = _dapperHelper.Execute($"Delete [Employee] where EmployeeId={EmployeeId}", null, commandType: CommandType.Text);

            return(data);
        }
Example #6
0
        public int DeleteDepartment(int ID)
        {
            var data = _dapperHelper.Execute("Delete Department where ID ='" + ID + "'", null, commandType: CommandType.Text);

            return(data);
        }
Example #7
0
        public int DeleteRoleAuthor(int ID)
        {
            var data = _dapperHelper.Execute("Delete [RoleAuthor] where ID ='" + ID + "'", null, commandType: CommandType.Text);

            return(data);
        }