/// <summary> /// Used to get <see cref="PointsGroupModel"/> from a persisted <see cref="PointsGroup"/>. /// </summary> private PointsGroupModel GetPointsGroupModel(PointsGroup pointsGroup, Item item) { return(new PointsGroupModel { PointsGroupId = pointsGroup.PointsGroupId, Name = pointsGroup.Name, AverageHorizontalDisplacement = pointsGroup.AverageHorizontalDisplacement, AverageVerticalDisplacement = pointsGroup.AverageVerticalDisplacement, ItemPermissionType = item.ItemPermissionTypeId, CalculationOutput = JsonConvert.DeserializeObject <CalculationOutputModel>(pointsGroup.ClusteringOutputJson) }); }
// GET: ClientFinder public async Task <IActionResult> Index(int actual) { List <PointsGroup> groups = new List <PointsGroup>(); var conn = _context.Database.GetDbConnection(); try { await conn.OpenAsync(); using (var command = conn.CreateCommand()) { string query = "SELECT Number, Firstname, Lastname, Membernumber, Viplevel, Points, Rateofpay, Guestpasses, Reservationpasses " + "FROM Owners " + "WHERE POINTS > 0 AND GUESTPASSES > 0 " + "GROUP BY Number, Firstname, Lastname, Membernumber, Viplevel, Points, Rateofpay, Guestpasses, Reservationpasses"; command.CommandText = query; DbDataReader reader = await command.ExecuteReaderAsync(); if (reader.HasRows) { while (await reader.ReadAsync()) { var row = new PointsGroup { Number = reader.GetInt32(0), Firstname = reader.GetString(1), Lastname = reader.GetString(2), Membernumber = reader.GetString(3), Viplevel = reader.GetString(4), Points = reader.GetInt32(5), Rateofpay = reader.GetDouble(6), Guestpasses = reader.GetInt16(7), Reservationpasses = reader.GetInt16(8), Compatibility = (Math.Abs(((float)reader.GetInt32(5) / (float)reader.GetInt16(7)) - actual) / ((float)reader.GetInt32(5) / (float)reader.GetInt16(7))) * 100 }; Console.WriteLine(row.Firstname + ": " + row.Compatibility); groups.Add(row); } } reader.Dispose(); } } finally { conn.Close(); } groups = groups.OrderByDescending(g => g.Compatibility).ToList(); return(View(groups)); }