Skip to content

Commit 0af22fd

Browse files
committed
Petite modif sur le panier
1 parent 0934b3d commit 0af22fd

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

Zenergy/Zenergy/Controllers/ApiControllers/CartContentsController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public async Task<IHttpActionResult> PutCartContent(int userId, CartContentModel
6262
{
6363
return NotFound();
6464
}
65-
if (cartContent.productQuantity < 0) return BadRequest("Please choose a positive product quantity!");
65+
if (cartContent.productQuantity < 1) return BadRequest("Please choose a positive product quantity!");
6666
//Verify if the quantity in the cartContent if inferior to the available quantity for the product
6767
int enoughProductInStock = db.product.Where(p => p.productId == cartContent.productId).FirstAsync().Result.availableQty.Value;
6868
if (cartContent.productQuantity > enoughProductInStock)

Zenergy/Zenergy/Scripts/Controllers/cartPageController.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
zenergyApp.controller("cartPageController", ["$scope", "$resource", "$uibModal", "$location", "tokenService", function ($scope, $resource, $uibModal, $location, tokenService) {
1+
zenergyApp.controller("cartPageController", ["$scope", "$resource", "$uibModal", "$location", "tokenService", "$route", function ($scope, $resource, $uibModal, $location, tokenService, $route) {
22

33
if ($scope.isAuthanticated()) {
44

@@ -8,11 +8,11 @@
88
method: 'PUT' // this method issues a PUT request
99
},
1010
removeFromBasket: {
11-
method: 'DELETE', isArray: true
11+
method: 'DELETE', isArray: true
1212
}
1313
});
1414

15-
$scope.cartContents = CartContents.query({userId : tokenService.getUserId()}, function () {
15+
$scope.cartContents = CartContents.query({ userId: tokenService.getUserId() }, function () {
1616
console.log($scope.cartContents);
1717
});
1818

@@ -21,7 +21,7 @@
2121
for (var i = 0; i < $scope.cartContents.length; i++) {
2222
var c = $scope.cartContents[i];
2323
if ($scope.isMember())
24-
total += ((c.product.productPrice -((c.product.productPrice * c.product.memberReduction) / 100)) * c.productQuantity);
24+
total += ((c.product.productPrice - ((c.product.productPrice * c.product.memberReduction) / 100)) * c.productQuantity);
2525
else
2626
total += (c.product.productPrice * c.productQuantity);
2727
}
@@ -36,10 +36,9 @@
3636
});
3737
};
3838

39-
$scope.setQuantity = function(c,i)
40-
{
39+
$scope.setQuantity = function (c, i) {
4140
c.productQuantity = c.productQuantity + i;
42-
c.$update({ userId: c.userId },
41+
c.$update({ userId: c.userId },
4342
function (response) {
4443
},
4544
function (response) {
@@ -48,18 +47,23 @@
4847
}
4948

5049
$scope.proceed = function () {
51-
var BasketValidation = $resource('api/users/'+tokenService.getUserId()+'/basket/validate', {}, {
50+
var BasketValidation = $resource('api/users/' + tokenService.getUserId() + '/basket/validate', {}, {
5251
update: {
5352
method: 'PUT' // this method issues a PUT request
5453
}
5554
});
5655

57-
BasketValidation.update({});
56+
BasketValidation.update({},
57+
function (response) {
58+
$route.reload();
59+
},
60+
function (response) {
61+
});
5862
};
5963

6064

6165

6266
}
6367
else
64-
$location.path("/")
68+
$location.path("/");
6569
}]);

0 commit comments

Comments
 (0)