I'm new to ASP.Net so any help greatly appreciated.
I've added a checkbox to a page, to choose between including archived customers or not:
<form>
<div class="form-group">
<label class="col-lg-3 control-label">Include Archived Customers</label>
<div class="col-lg-9">
<input class="form-control" style="transform:scale(0.5)" type="checkbox" ng-model="includeArchived" ng-change="includeFlagsChanged()" />
</div>
</div>
</form>
This is the script that I've tried to add to:
<script>
var app = angular.module("InvAggApp", ['angular-loading-bar']);
app.controller("customerLinkController", function ($scope, $http) {
$scope.includeArchived = false;
$http.get("/DataLink/CheckForXeroToken")
.then(function (response) {
$scope.response = response;
if (response.data.Success) {
$scope.hasXeroToken = response.data.hasXeroToken;
if ($scope.hasXeroToken) initialise();
} else {
$scope.error = response.data.Exception;
}
}, function (response) { $scope.error = response });
var initialise = function () {
$http.post("/DataLink/GetCustomerLinks")
.then(function (response) {
includeArchived: $scope.includeArchived
$scope.error = null;
$scope.response = response;
if (response.data.Success) {
$scope.customers = response.data.customers;
$scope.wcCustomers = response.data.wcCustomers;
} else {
$scope.error = response.data.Exception;
}
}, function (response) { $scope.error = response });
}
debugger;
$scope.includeFlagsChanged = function () {
$scope.includeArchived = includeArchived;
};
Then this where I need to use it, I'm wanting to replace the .Where(xc => xc.archived == false) to use the includeArchived value of checkbox
public async Task<JsonResult> GetCustomerLinks() {
try {
var xeroSession = new XeroSessionManager();
var xeroData = new XeroData(xeroSession);
var xeroCustomers = await xeroData.GetAllCustomers();
using (var cx = new BillingAssistantContext()) {
var wcCustomers = cx.Companies.Select(c => new { wcId = c.ID, wcName = c.Name }).OrderBy(c => c.wcName).ToArray();
var customers = xeroCustomers.Select(xc => {
var cl = cx.CustomerLinks.SingleOrDefault(l => l.XeroContactID == xc.ContactID);
return new {
xeroId = xc.ContactID, xeroName = xc.Name,
wcCustomerId = cl?.WCompanyID,
archived = cl?.Archived
};
}).Where(xc => xc.archived == false).OrderBy(xc => xc.xeroName).ToArray();
return new JsonResult {
Data = new {
Success = true,
customers = customers,
wcCustomers = wcCustomers,
}
};
}
Aucun commentaire:
Enregistrer un commentaire