public IActionResult Delete(int?reisId) { if (reisId == null) { return(NotFound()); } ShoppingCartVM cartList = HttpContext.Session.GetObject <ShoppingCartVM>("ShoppingCart"); // remove item form shoppingcart var itemToRemove = cartList.Cart.FirstOrDefault(r => r.ReisId == reisId); if (itemToRemove != null) { cartList.Cart.Remove(itemToRemove); if (cartList.Cart.Count == 0) { cartList = null; } HttpContext.Session.SetObject("ShoppingCart", cartList); // remove item from database try { var toDeleteTreinritreis = treinritreisService.FindByReisId(Convert.ToInt16(reisId)); foreach (TreinritReis treinritreis in toDeleteTreinritreis) { //Vrij plaatsen terugzetten Treinrit treinrit = treinritService.FindById(treinritreis.TreinritId); treinrit.Vrijeplaatsen = treinrit.Vrijeplaatsen + 1; treinritService.Update(treinrit); treinritreisService.Delete(treinritreis); } reisService.Delete(reisService.FindById(Convert.ToInt16(reisId))); } catch (Exception e) { Console.Write(e); } } return(View("index", cartList)); }
public IActionResult RemoveReis(int?id) { if (id == null) { return(NotFound()); } var toDeleteTreinritreis = treinritreisService.FindByReisId(Convert.ToInt16(id)); foreach (TreinritReis treinritreis in toDeleteTreinritreis) { //Vrij plaatsen terugzetten Treinrit treinrit = treinritService.FindById(treinritreis.TreinritId); treinrit.Vrijeplaatsen = treinrit.Vrijeplaatsen + 1; treinritService.Update(treinrit); treinritreisService.Delete(treinritreis); } reisService.Delete(reisService.FindById(Convert.ToInt16(id))); return(RedirectToAction("Index", "Reis")); }