I have a database of 4000+ objects, most of which are duplicates. I would like to create a new view of them, and shorten the list by showing only 1 instance of each element by the first and last name. I have already created a method in my Repository that I think should work, as well as the button to display my new list. I think The best way to do this is using JavaScript or JQuery, but I'm not sure how to work it out.
This is my Duplicate User sorting method:
public List<CustomerUserNameDto> GetDuplicateUsers()
{
List<CustomerUserNameDto> userList = new List<CustomerUserNameDto>();
var list = _dbContext.CustomerUsers.ToList();
foreach (var customer in list )
{
CustomerUserNameDto dto = new CustomerUserNameDto();
dto.CustomerUserId = customer.CustomerUserId;
dto.FirstName = customer.FirstName;
dto.LastName = customer.LastName;
var check = userList.Find(y => y.FirstName == dto.FirstName && y.LastName == dto.LastName);
if (check == null)
{
userList.Add(dto);
}
}
return userList;
}
And the JavaScript I have so far:
function GetDuplicateUserList() {
var serviceURL = 'Main/GetCustomerUserList';
$('#CustomerUserList').html("Loading Data...");
$.ajax({
type: 'post',
dataType: 'text',
cache: false,
url: serviceURL,
success: function (data) {
$('#CustomerUserList').html(data);
},
error: function (jqXHR, textStatus, errorThrown) {
alert('Error - ' + errorThrown);
}
});
}
Any help would be appreciated.