public async Task <int> GetTimesIpMadeAction(string ip, UserActionTypes action)
        {
            _sqlConnection.Open();
            SqlCommand cmd = new SqlCommand
            {
                Connection  = _sqlConnection,
                CommandType = CommandType.Text,
                CommandText = "select count(*) as count from UserLogs where ip = @ip and Action = @action"
            };

            cmd.Parameters.Add(new SqlParameter("@ip", ip));
            cmd.Parameters.Add(new SqlParameter("@action", action.ToString()));

            SqlDataReader reader = await cmd.ExecuteReaderAsync();

            int result = -1;

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    result = int.Parse(reader["count"].ToString());
                    break;
                }
            }

            reader.Close();
            _sqlConnection.Close();

            return(result);
        }
Exemplo n.º 2
0
 internal UserAction(UserActionTypes type, int columnindex, int rowindex, object oldvalue, object newvalue)
 {
     this.m_UserActionType = type;
     this.m_ColumnIndex    = columnindex;
     this.m_RowIndex       = rowindex;
     this.m_OldValue       = oldvalue;
     this.m_NewValue       = newvalue;
 }
        public async Task InteractWithPost(int postId, int userId, UserActionTypes actionType, bool value)
        {
            PostAction postAction = new PostAction
            {
                PostId     = postId,
                UserId     = userId,
                Value      = value,
                ActionType = actionType.ToString()
            };

            await client.PostAsync($"{uri}/actions", PrepareObjectForRequest(postAction));
        }
Exemplo n.º 4
0
        public async Task InteractWithUser(int senderId, int receiverId, UserActionTypes actionType, object value)
        {
            UserAction userAction = new UserAction
            {
                SenderId   = senderId,
                ReceiverId = receiverId,
                ActionType = actionType.ToString(),
                Value      = value
            };


            await client.PostAsync($"{uri}/actions", PrepareObjectForRequest(userAction));
        }
Exemplo n.º 5
0
        public Task AddLog(TimeSpan timeElapsed, UserActionTypes actionType, string searchPhrase = null)
        {
            if (actionType == UserActionTypes.GetAnagrams &&
                (string.IsNullOrEmpty(searchPhrase) || TimeSpan.Zero == timeElapsed))
            {
                throw new Exception("Cannot add UserLog, because UserLog is empty");
            }
            else if (actionType != UserActionTypes.GetAnagrams && TimeSpan.Zero == timeElapsed)
            {
                throw new Exception("Cannot add UserLog, because UserLog is empty");
            }

            var log = new UserLog(GetUserIp(), searchPhrase, timeElapsed, actionType.ToString());

            return(_userLogRepository.InsertLog(log));
        }
Exemplo n.º 6
0
 public UserAction(UserActionTypes actionType, TestUser user)
 {
     this.ActionType = actionType;
     this.User       = user;
 }
Exemplo n.º 7
0
 public UserAction(UserActionTypes actionType)
 {
     this.ActionType = actionType;
 }
 public Task <int> GetTimesIpMadeAction(string ip, UserActionTypes action)
 {
     return(_context.UserLogs.CountAsync(x => x.Ip == ip && x.Action == action.ToString()));
 }