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); }
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)); }
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)); }
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)); }
public Task <int> GetTimesIpMadeAction(string ip, UserActionTypes action) { return(_context.UserLogs.CountAsync(x => x.Ip == ip && x.Action == action.ToString())); }