Esempio n. 1
0
        private async Task <UserLogEntity> GetLogByPhrase(string phrase)
        {
            _sqlConnection.Open();
            SqlCommand cmd = new SqlCommand()
            {
                Connection  = _sqlConnection,
                CommandType = CommandType.Text,
                CommandText = "select * from UserLogs where Phrase = @phrase"
            };

            cmd.Parameters.Add(new SqlParameter("@phrase", phrase));
            SqlDataReader reader = await cmd.ExecuteReaderAsync();

            var log = new UserLogEntity();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    log =
                        new UserLogEntity()
                    {
                        ID         = int.Parse(reader["ID"].ToString()),
                        Ip         = reader["Ip"].ToString(),
                        Phrase     = reader["Phrase"].ToString(),
                        SearchTime = TimeSpan.Parse(reader["SearchTime"].ToString()),
                        Action     = reader["Action"].ToString()
                    };
                    break;
                }
            }
            return(log);
        }
Esempio n. 2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public UserLogEntity DataRowToModel(DataRow row)
        {
            UserLogEntity model = new UserLogEntity();

            if (row != null)
            {
                if (row["Ur_ID"] != null && row["Ur_ID"].ToString() != "")
                {
                    model.Ur_ID = int.Parse(row["Ur_ID"].ToString());
                }
                if (row["Us_ID"] != null && row["Us_ID"].ToString() != "")
                {
                    model.Us_ID = int.Parse(row["Us_ID"].ToString());
                }
                if (row["Us_operator"] != null)
                {
                    model.Us_operator = row["Us_operator"].ToString();
                }
                if (row["Us_object"] != null)
                {
                    model.Us_object = row["Us_object"].ToString();
                }
                if (row["Us_time"] != null && row["Us_time"].ToString() != "")
                {
                    model.Us_time = DateTime.Parse(row["Us_time"].ToString());
                }
            }
            return(model);
        }
Esempio n. 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(UserLogEntity model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into User_log(");
            strSql.Append("Us_ID,Us_operator,Us_object,Us_time)");
            strSql.Append(" values (");
            strSql.Append("@Us_ID,@Us_operator,@Us_object,@Us_time)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Us_ID",       SqlDbType.Int,       4),
                new SqlParameter("@Us_operator", SqlDbType.NVarChar, 50),
                new SqlParameter("@Us_object",   SqlDbType.NVarChar, 50),
                new SqlParameter("@Us_time",     SqlDbType.DateTime)
            };
            parameters[0].Value = model.Us_ID;
            parameters[1].Value = model.Us_operator;
            parameters[2].Value = model.Us_object;
            parameters[3].Value = model.Us_time;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(UserLogEntity model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update User_log set ");
            strSql.Append("Us_ID=@Us_ID,");
            strSql.Append("Us_operator=@Us_operator,");
            strSql.Append("Us_object=@Us_object,");
            strSql.Append("Us_time=@Us_time");
            strSql.Append(" where Ur_ID=@Ur_ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Us_ID",       SqlDbType.Int,        4),
                new SqlParameter("@Us_operator", SqlDbType.NVarChar,  50),
                new SqlParameter("@Us_object",   SqlDbType.NVarChar,  50),
                new SqlParameter("@Us_time",     SqlDbType.DateTime),
                new SqlParameter("@Ur_ID",       SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Us_ID;
            parameters[1].Value = model.Us_operator;
            parameters[2].Value = model.Us_object;
            parameters[3].Value = model.Us_time;
            parameters[4].Value = model.Ur_ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public async Task InsertLog(UserLog userLog)
        {
            var entity = new UserLogEntity
            {
                Ip         = userLog.Ip,
                SearchTime = userLog.SearchTime,
                Phrase     = userLog.SearchPhrase,
                Action     = userLog.Action
            };

            await _context.UserLogs.AddAsync(entity);
        }
        public void InsertToUserLog(string requestWord, string IpAddress)
        {
            UserLogEntity userLogEntity = new UserLogEntity()
            {
                Date      = DateTime.Now,
                RequestId = _requestRepository.GetByWord(requestWord).Id,
                UserId    = _userRepository.GetByIp(IpAddress).Id,
                UserIp    = IpAddress
            };

            _userLogRepository.Add(userLogEntity);
        }
Esempio n. 7
0
 public async Task SaveUserLog(string ip, string searchWord, string connString)
 {
     using (var db = new AnagramContext(connString))
     {
         var userLogEntity = new UserLogEntity {
             UserIP = ip, LogDate = DateTime.UtcNow
         };
         userLogEntity.CachedWordEntity = db.CachedWordEntities.First(s => s.SearchWord == searchWord);
         db.UserLogEntities.Add(userLogEntity);
         await db.SaveChangesAsync();
     }
 }
        public void InsertUserLog(string word, string ip, UserAction userAction)
        {
            //var ip = _efLogic.GetIP();
            var userLogEntity = new UserLogEntity
            {
                UserIp     = ip,
                SearchWord = word,
                SearchTime = DateTime.Now,
                UserAction = userAction.ToString()
            };

            _context.UserLog.Add(userLogEntity);
            _context.SaveChanges();
        }
Esempio n. 9
0
        /// <summary>
        /// login record
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="loginName"></param>
        /// <param name="sessionGUID"></param>
        /// <param name="context"></param>
        internal void WriteLoginInfo(int userID, string loginName, string sessionGUID, string ipaddress)
        {
            var logInfo = new UserLogEntity
            {
                UserID      = userID,
                LoginName   = loginName,
                SessionGUID = sessionGUID,
                IPAddress   = ipaddress
            };
            var url          = string.Format("{0}/LogData/Login", WebApiApplication.WebAPIHostUrl);
            var clientHelper = HttpClientHelper.CreateHelper(url);

            clientHelper.Post <UserLogEntity, ResponseResult <UserLogEntity> >(logInfo);
        }
Esempio n. 10
0
        public ResponseResult Logout(UserLogEntity log)
        {
            var result = ResponseResult.Default();

            try
            {
                LogService.Logout(log);
                result = ResponseResult.Success();
            }
            catch (System.Exception ex)
            {
                result = ResponseResult.Error(string.Format("用户注销记录日志失败, {0}", ex.Message));
            }
            return(result);
        }
Esempio n. 11
0
        public async Task CreateLog(UserLogEntity log)
        {
            _sqlConnection.Open();
            var        sqlQuery = "INSERT INTO UserLog (UserIp,SearchedWord,Time,Anagrams)  VALUES (@Ip,@Word,@Time,@Anagrams)";
            SqlCommand command  = new SqlCommand(sqlQuery, _sqlConnection);

            command.CommandType = CommandType.Text;
            command.Parameters.Add(new SqlParameter("@Word", log.SearchedWord));
            command.Parameters.Add(new SqlParameter("@Ip", log.UserIp));
            command.Parameters.Add(new SqlParameter("@Time", log.Time));
            command.Parameters.Add(new SqlParameter("@Anagrams", log.Anagrams));
            await command.ExecuteNonQueryAsync();

            _sqlConnection.Close();
        }
Esempio n. 12
0
 /// <summary>
 /// insert login record
 /// </summary>
 /// <param name="log"></param>
 /// <returns></returns>
 public void Login(UserLogEntity log)
 {
     try
     {
         var entity = new UserLogEntity();
         entity.UserID      = log.UserID;
         entity.LoginName   = log.LoginName;
         entity.LoginTime   = System.DateTime.Now;
         entity.LogoutTime  = null;
         entity.SessionGUID = log.SessionGUID;
         entity.IPAddress   = log.IPAddress;
         QuickRepository.Insert <UserLogEntity>(entity);
     }
     catch (System.Exception)
     {
         throw;
     }
 }
Esempio n. 13
0
        /// <summary>
        /// insert logout record
        /// </summary>
        /// <param name="log"></param>
        /// <returns></returns>
        public void Logout(UserLogEntity log)
        {
            try
            {
                var sql    = "SELECT * FROM SysUserLog WHERE SessionGUID = @sessionGUID";
                var entity = QuickRepository.Query <UserLogEntity>(sql,
                                                                   new {
                    sessionGUID = log.SessionGUID
                }).ToList <UserLogEntity>()[0];

                if (entity != null)
                {
                    entity.LogoutTime = System.DateTime.Now;
                    QuickRepository.Update <UserLogEntity>(entity);
                }
            }
            catch (System.Exception ex)
            {
                throw;
            }
        }
Esempio n. 14
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public UserLogEntity GetModel(int Ur_ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Ur_ID,Us_ID,Us_operator,Us_object,Us_time from User_log ");
            strSql.Append(" where Ur_ID=@Ur_ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Ur_ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = Ur_ID;

            UserLogEntity model = new UserLogEntity();
            DataSet       ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
 public async Task CreateLog(UserLogEntity log)
 {
     await _context.UserLog.AddAsync(log).ConfigureAwait(false);
 }
Esempio n. 16
0
        public void GetUserLogListByIp_ShouldReturnUserLogListByIp()
        {
            ipAddress = "::1";

            UserLogModel expected = new UserLogModel()
            {
                RequestedWord = "labas",
                UserIp        = "::1",
            };

            var sample = new UserLogEntity()
            {
                Id   = 1,
                User = new UserEntity()
                {
                    Id = 1, Ip = "::1"
                },
                Request = new RequestEntity()
                {
                    Id = 1, Word = "labas"
                },
                Date = DateTime.Now
            };


            _userLogRepository.GetUserLogListByIp(ipAddress).Returns(new List <UserLogEntity>
            {
                sample,
                new UserLogEntity()
                {
                    Id   = 2,
                    User = new UserEntity()
                    {
                        Id = 1, Ip = "::1"
                    },
                    Request = new RequestEntity()
                    {
                        Id = 2, Word = "Labas"
                    },
                    Date = DateTime.Now
                },
                new UserLogEntity()
                {
                    Id   = 3,
                    User = new UserEntity()
                    {
                        Id = 2, Ip = "::2"
                    },
                    Request = new RequestEntity()
                    {
                        Id = 2, Word = "Labas"
                    },
                    Date = DateTime.Now
                },
            });

            //////////////////////////////////
            //////////////////////////////////


            var result = _userService.GetUserLogListByIp(ipAddress);


            result.ShouldNotBeNull();

            sample.User.Ip.ShouldBeSameAs(expected.UserIp);
/*            sample.Request.Id.ShouldBeSameAs()*/


            _userLogRepository.Received().GetUserLogListByIp(ipAddress);
        }
Esempio n. 17
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(UserLogEntity model)
 {
     return(dal.Update(model));
 }
 public int Add(UserLogEntity userLogEntity)
 {
     _db.UserLogs.Add(userLogEntity);
     _db.SaveChanges();
     return(userLogEntity.Id);
 }
Esempio n. 19
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int  Add(UserLogEntity model)
 {
     return(dal.Add(model));
 }
 public UserLogEntity Update(UserLogEntity userLogEntity)
 {
     throw new NotImplementedException();
 }