public Task<DanhSachLoginHistoryOutput> GetAll(FilterLoginHistoryInput input) { int total = _loginHistoryTable.GetTotal(input); IEnumerable<LoginHistory> paging = _loginHistoryTable.GetPaging(input); return Task.FromResult(new DanhSachLoginHistoryOutput { DanhSachLoginHistories = paging, TotalCount = total }); }
public async Task<DanhSachLoginHistoryOutput> GetAll(FilterLoginHistoryInput filter) { return await this._loginHistoryBll.GetAll(filter); }
private string GetSqlFilterConditions(FilterLoginHistoryInput input, out Dictionary<string, object> parameters) { var list1 = new List<string>(); parameters = new Dictionary<string, object>(); if (input.Type != null && input.Type.Length > 0) list1.Add("Type in (" + string.Join(",", input.Type) + ")"); if (!string.IsNullOrEmpty(input.UserName)) { list1.Add("UserName LIKE @UserName"); parameters.Add("@UserName", "%" + Utils.EncodeForLike(input.UserName) + "%"); } if (input.LoginTimeFrom.HasValue) { list1.Add("LoginTime >= @LoginTimeFrom"); parameters.Add("@LoginTimeFrom", input.LoginTimeFrom.Value.ToLocalTime()); } if (input.LoginTimeTo.HasValue) { list1.Add("LoginTime <= @LoginTimeTo"); parameters.Add("@LoginTimeTo", input.LoginTimeTo.Value.ToLocalTime()); } if (input.LoginStatus != null && input.LoginStatus.Length > 0) list1.Add("LoginStatus in (" + string.Join(",", input.LoginStatus) + ")"); if (!string.IsNullOrEmpty(input.RefreshToken)) { list1.Add("RefreshToken LIKE @RefreshToken"); parameters.Add("@RefreshToken", "%" + Utils.EncodeForLike(input.RefreshToken) + "%"); } if (input.AppId != null && input.AppId.Length > 0) { var list2 = new List<string>(); if (input.AppId.Where(string.IsNullOrEmpty).Any()) list2.Add("AppId IS NULL"); IEnumerable<string> source = input.AppId.Where(m => !string.IsNullOrEmpty(m)).Select(m => Regex.Replace(m, "[^(0-9a-zA-Z_\\-\\:)]", string.Empty)); if (source.Any()) list2.Add("AppId in (" + string.Join(",", source.Select(m => string.Format("'{0}'", m))) + ")"); list1.Add("(" + string.Join(" OR ", list2) + ")"); } if (!string.IsNullOrEmpty(input.ClientUri)) { list1.Add("ClientUri LIKE @ClientUri"); parameters.Add("@ClientUri", "%" + Utils.EncodeForLike(input.ClientUri) + "%"); } if (!string.IsNullOrEmpty(input.ClientIP)) { list1.Add("ClientIP LIKE @ClientIP"); parameters.Add("@ClientIP", "%" + Utils.EncodeForLike(input.ClientIP) + "%"); } if (!string.IsNullOrEmpty(input.ClientUA)) { list1.Add("ClientUA LIKE @ClientUA"); parameters.Add("@ClientUA", "%" + Utils.EncodeForLike(input.ClientUA) + "%"); } if (!string.IsNullOrEmpty(input.ClientDevice)) { list1.Add("ClientDevice LIKE @ClientDevice"); parameters.Add("@ClientDevice", "%" + Utils.EncodeForLike(input.ClientDevice) + "%"); } if (!string.IsNullOrEmpty(input.ClientApiKey)) { list1.Add("ClientApiKey LIKE @ClientApiKey"); parameters.Add("@ClientApiKey", "%" + Utils.EncodeForLike(input.ClientApiKey) + "%"); } return string.Join(" AND ", list1.ToArray()); }
public IEnumerable<LoginHistory> GetPaging(FilterLoginHistoryInput input) { Dictionary<string, object> parameters; string filterConditions = GetSqlFilterConditions(input, out parameters); string str = "select * from LoginHistory"; if (!string.IsNullOrEmpty(filterConditions)) str = str + " WHERE " + filterConditions; string commandText = str + " order by Created DESC limit @rowNumber, @pageSize"; parameters.Add("@rowNumber", input.PageSize * input.PageNumber); parameters.Add("@pageSize", input.PageSize); return _database.Query(commandText, parameters).Select(dictionary => new LoginHistory { Id = int.Parse(dictionary["Id"]), Type = int.Parse(dictionary["Type"]), UserName = dictionary["UserName"], LoginTime = DateTime.Parse(dictionary["LoginTime"]), LoginStatus = int.Parse(dictionary["LoginStatus"]), RefreshToken = dictionary["RefreshToken"], AppId = dictionary["AppId"], ClientUri = dictionary["ClientUri"], ClientIP = dictionary["ClientIP"], ClientUA = dictionary["ClientUA"], ClientDevice = dictionary["ClientDevice"], ClientApiKey = dictionary["ClientApiKey"], Created = DateTime.Parse(dictionary["Created"]) }).ToList(); }
public int GetTotal(FilterLoginHistoryInput input) { Dictionary<string, object> parameters; string filterConditions = GetSqlFilterConditions(input, out parameters); string commandText = "select count(*) from LoginHistory"; if (!string.IsNullOrEmpty(filterConditions)) commandText = commandText + " WHERE " + filterConditions; return int.Parse(_database.QueryValue(commandText, parameters).ToString()); }