public RedirectToActionResult RemoveCake(Guid id) { var cake = _CakeRepository.GetCakeById(id); _CakeRepository.RemoveCake(cake); return(RedirectToAction("Index")); }
public async Task <IActionResult> AddToShoppingCart(int cakeId) { var selectedCake = await _cakeRepository.GetCakeById(cakeId); if (selectedCake == null) { return(NotFound()); } await _shoppingCart.AddToCartAsync(selectedCake); return(RedirectToAction("Index")); }
public RedirectToActionResult RemoveCake(Guid id) { var cake = _CakeRepository.GetCakeById(id); if (cake != null) { _CakeRepository.RemoveCake(cake); return(RedirectToAction("Index")); } else { return(RedirectToAction("NotFoundAction")); } }
public async Task<IActionResult> Details(int id) { var cake = await _cakeRepository.GetCakeById(id); return View(cake); }
public async Task Post([Microsoft.AspNetCore.Mvc.FromBody] Order data, string cakeId, string qty) { // Simple Error Checking for Cakes that are not currently in the Database. Currently there are 5 cakes. // Can improve functionality by checking the database and the most recent max number of cakes if (Int32.Parse(cakeId) > 5) { var message = new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent("You are out of range of available Cakes.") }; throw new HttpResponseException(message); } for (int i = 0; i < Int32.Parse(qty); i++) { Cake cake = await _cakeRepository.GetCakeById(Int32.Parse(cakeId)); await _shoppingCart.AddToCartAsync(cake); } // Place Requested Order await _orderRepository.CreateOrderAsync(data); // Empty Temporary Shopping cart entries await _shoppingCart.ClearCartAsync(); }
public IActionResult Details(int id) { var cake = _cakeRepository.GetCakeById(id); if (cake == null) { return(NotFound()); } return(View(cake)); }
public async Task <IActionResult> EditCake(int id) { var cake = await _cakeRepository.GetCakeById(id); var cakeDto = _mapper.Map <Cake, CakeDto>(cake); var category = await _categoryRepository.GetCategories(); return(View(new CakeCreateUpdateViewModel { Categories = category, CakeDto = cakeDto })); }
public RedirectToActionResult AddToCart(Guid id) { var pie = _pieRepository.GetPieById(id); var cake = _cakeRepository.GetCakeById(id); if (pie != null) { _shoppingCart.AddToCart(pie, 1); } else if (cake != null) { _shoppingCart.AddToCart(cake, 1); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Details(int id) { CakeDetailRatingViewModel ratingModel = new CakeDetailRatingViewModel(); var rating = await _ratingRepository.GetUserRatingByCakeAsync(id); ratingModel.CakeId = id; if (rating != null) { ratingModel.Value = rating.Value; } var cake = await _cakeRepository.GetCakeById(id); ratingModel.cake = cake; return(View(ratingModel)); }
public async Task <RedirectToActionResult> AddToCartAsync(Guid id) { var shoppingCart = await _shoppingCartRepository.GetCartAsync(); Pie pie = _pieRepository.GetPieById(id); Cake cake = _cakeRepository.GetCakeById(id); if (pie != null) { _shoppingCartRepository.AddToCart(pie, 1); } else if (cake != null) { _shoppingCartRepository.AddToCart(cake, 1); } return(RedirectToAction("Index")); }
public async Task <Cake> LoadCake(ICakeRepository cakeRepository) { return(await cakeRepository.GetCakeById(CakeId)); }
public Cake GetCakeById(int id) { return(_cakeRepository.GetCakeById(id)); }