public IActionResult AddToCart(ProductSpecificationViewModel viewModel, int productId) { var amount = viewModel.Product.Amount; int userId = Convert.ToInt32(User.Claims.FirstOrDefault(c => c.Type == "UserID")?.Value); _cartLogic.AddToCart(productId, userId, amount); return(RedirectToAction("Products", "Product")); }
/// <summary> /// Add Product To Cart /// </summary> /// <param name="product"></param> /// <returns></returns> public ActionResult AddToCart(Guid product) { CartDTO cartDTO = new CartDTO(); Guid id = new Guid(product.ToString()); CartLogic.AddToCart(new Guid(Session["id"].ToString()), id); return(RedirectToAction("Cart")); }
public async void AddToCart(Product product) { try { if (Application.Current.Properties.ContainsKey("isLoggedIn")) { Config.ShowDialog(); Dictionary <string, string> addToCart = new Dictionary <string, string>(); addToCart.Add("product_id", product.id.ToString()); addToCart.Add("user_id", Application.Current.Properties["user_id"].ToString()); addToCart.Add("quantity", "1"); addToCart.Add("scheduled", "0"); //addToCart.Add("product_variation_id", product.selected_variant_id.ToString()); if (product.selected_variant_id == 0) { addToCart.Add("product_variation_id", product.get_product_variations[0].id.ToString()); } else { addToCart.Add("product_variation_id", product.selected_variant_id.ToString()); } //if (productVariation != null) addToCart.Add("product_variation_id", productVariation.id.ToString()); addToCart.Add("from_date", DateTime.Now.ToString("yyyy-MM-dd")); addToCart.Add("to_date", DateTime.Now.ToString("yyyy-MM-dd")); var response = await CartLogic.AddToCart(addToCart); if (response.status == 200) { HomeVM.MyCartCounter = response.cart_count; MessagingCenter.Send((App)Application.Current, "NavigationBar", _pageTitle); MessagingCenter.Send((App)Application.Current, "getCartCountHomeOnly"); Config.HideDialog(); Config.SnackbarMessage(response.message); getData(); } else { Config.HideDialog(); Config.SnackbarMessage(response.message); } } else { Config.HideDialog(); await Navigation.PushAsync(new LoginPage()); } } catch (Exception ex) { Config.ErrorStore("ProductsPage-AddToCart", ex.Message); Config.HideDialog(); Config.ErrorSnackbarMessage(Config.ApiErrorMessage); } }
private async void addToCart_Tapped(object sender, EventArgs e) { try { if (Application.Current.Properties.ContainsKey("isLoggedIn")) { Config.ShowDialog(); var productVariation = _product.get_product_variations .FirstOrDefault(x => x.weightUnit == weight.Items[weight.SelectedIndex]); Dictionary <string, string> addToCart = new Dictionary <string, string>(); addToCart.Add("product_id", _product.id.ToString()); addToCart.Add("user_id", Application.Current.Properties["user_id"].ToString()); addToCart.Add("quantity", quantity.Text); addToCart.Add("scheduled", "0"); if (productVariation != null) { addToCart.Add("product_variation_id", productVariation.id.ToString()); } addToCart.Add("from_date", DateTime.Now.ToString("yyyy-MM-dd")); addToCart.Add("to_date", DateTime.Now.ToString("yyyy-MM-dd")); var response = await CartLogic.AddToCart(addToCart); if (response.status == 200) { Config.HideDialog(); Config.SnackbarMessage(response.message); HomeVM.MyCartCounter = response.cart_count; MessagingCenter.Send((App)Application.Current, "NavigationBar", _pageTitle); MessagingCenter.Send((App)Application.Current, "getCartCountHomeOnly"); CustomNavigationBarVM.MenuIcon = "back.png"; await Navigation.PushAsync(new CartPage()); //await DisplayAlert("Success", response.message, "Ok"); } else { Config.HideDialog(); Config.SnackbarMessage(response.message); } } else { Config.HideDialog(); await Navigation.PushAsync(new LoginPage()); } } catch (Exception ex) { Config.ErrorStore("ProductDetailPage-addToCart_Tapped", ex.Message); Config.HideDialog(); await DisplayAlert("Alert", Config.ApiErrorMessage, "Ok"); } }
private async void btnOrder_Clicked(object sender, EventArgs e) { try { var button = (StackLayout)sender; if (button.GestureRecognizers.Count() > 0) { Config.ShowDialog(); var label = (TapGestureRecognizer)button.GestureRecognizers[0]; var product = (PastOrder)label.CommandParameter; Dictionary <string, string> addToCart = new Dictionary <string, string>(); addToCart.Add("product_id", product.product_id.ToString()); addToCart.Add("user_id", Application.Current.Properties["user_id"].ToString()); addToCart.Add("quantity", product.quantity.ToString()); addToCart.Add("scheduled", "0"); addToCart.Add("product_variation_id", product.product_variation_id); addToCart.Add("from_date", DateTime.Now.ToString("yyyy-MM-dd")); addToCart.Add("to_date", DateTime.Now.ToString("yyyy-MM-dd")); var response = await CartLogic.AddToCart(addToCart); if (response.status == 200) { Config.HideDialog(); HomeVM.MyCartCounter = response.cart_count; MessagingCenter.Send((App)Application.Current, "NavigationBar", ""); Config.SnackbarMessage(response.message); } else { Config.HideDialog(); Config.ErrorSnackbarMessage(Config.ApiErrorMessage); } } } catch (Exception ex) { Config.ErrorStore("PastOrderPage-btnOrder_Clicked", ex.Message); Config.HideDialog(); Config.ErrorSnackbarMessage(Config.ApiErrorMessage); } }