public async Task <int> SaveCartProductAsync(Models.Cart.CartProduct cartProduct) { CartProduct cart; int idCart = 0; cart = new CartProduct { customersId = cartProduct.customersId, customersBasketId = cartProduct.customersBasketId, customersBasketDateAdded = cartProduct.customersBasketDateAdded, status = true }; await database.InsertAsync(cart); idCart = cart.ID; await SaveProductsAsync(cartProduct.customersBasketProduct, idCart); await SaveCartProductAttributesAsync(cartProduct.customersBasketProductAttributes, idCart); return(idCart); }
public async Task <List <Models.Cart.CartProduct> > GetCartProductAsync() { List <Models.Cart.CartProduct> cartProducts = new List <Models.Cart.CartProduct>(); var sourceCart = await database.Table <CartProduct>().ToListAsync(); foreach (var item in sourceCart) { Models.Cart.CartProduct cart = new Models.Cart.CartProduct { ID = item.ID, customersId = item.customersId, customersBasketId = item.customersBasketId, customersBasketDateAdded = item.customersBasketDateAdded }; var itemProduct = await database.Table <ProductDetails>().Where(i => i.CartProductID.Equals(item.ID)).ToListAsync(); //var itemProductAttribute = await database.Table<CartProductAttributes>().Where(i => i.CartProductID.Equals(item.ID)).ToListAsync(); var itemProductAttribute = await database.Table <CartProductAttributes>().ToListAsync(); foreach (var itemAttr in itemProductAttribute) { Models.Cart.CartProductAttributes cartProductAttributes = new Models.Cart.CartProductAttributes(); cartProductAttributes.customersBasketId = itemAttr.customersBasketId; cartProductAttributes.productsId = itemAttr.productsId; var itemProductAttributeOption = await database.Table <Option>().Where(i => i.CartProductAttributesID.Equals(itemAttr.ID)).ToListAsync(); var itemProductAttributeValues = await database.Table <Value>().Where(i => i.CartProductAttributesID.Equals(itemAttr.ID)).ToListAsync(); Models.Cart.Option option = new Models.Cart.Option(); foreach (var itemAttVal in itemProductAttributeValues) { Models.Cart.Value value = new Models.Cart.Value { id = itemAttVal.id, price = itemAttVal.price, price_prefix = itemAttVal.price_prefix, value = itemAttVal.value }; cartProductAttributes.values.Add(value); } foreach (var itemAttOpt in itemProductAttributeOption) { option.id = itemAttOpt.id; option.name = itemAttOpt.name; } cartProductAttributes.option = option; cart.customersBasketProductAttributes.Add(cartProductAttributes); } foreach (var itmP in itemProduct) { Product productDetails = new Product { ID = itmP.ID, CartProductID = itmP.CartProductID, products_id = itmP.products_id, products_quantity = itmP.products_quantity, products_image = itmP.products_image, products_model = itmP.products_model, products_price = itmP.products_price, discount_price = itmP.discount_price, products_date_added = itmP.products_date_added, products_last_modified = itmP.products_last_modified, products_date_available = itmP.products_date_available, products_weight = itmP.products_weight, products_weight_unit = itmP.products_weight_unit, products_status = itmP.products_status, products_ordered = itmP.products_ordered, products_liked = itmP.products_liked, language_id = itmP.language_id, products_name = itmP.products_name, products_description = itmP.products_description, products_url = itmP.products_url, products_viewed = itmP.products_viewed, products_tax_class_id = itmP.products_tax_class_id, tax_rates_id = itmP.tax_rates_id, tax_zone_id = itmP.tax_zone_id, tax_class_id = itmP.tax_class_id, tax_priority = itmP.tax_priority, tax_rate = itmP.tax_rate, tax_description = itmP.tax_description, tax_class_title = itmP.tax_class_title, tax_class_description = itmP.tax_class_description, categories_id = itmP.categories_id, categories_name = itmP.categories_name, categories_image = itmP.categories_image, categories_icon = itmP.categories_icon, parent_id = itmP.parent_id, sort_order = itmP.sort_order, isLiked = itmP.isLiked, manufacturers_id = itmP.manufacturers_id, manufacturers_name = itmP.manufacturers_name, manufacturers_image = itmP.manufacturers_image, manufacturers_url = itmP.manufacturers_url, date_added = itmP.date_added, last_modified = itmP.last_modified, isSale_product = itmP.isSale_product, attributes_price = itmP.attributes_price, final_price = itmP.final_price, total_price = itmP.total_price, customers_basket_quantity = itmP.customers_basket_quantity, comentProduct = itmP.comentProduct }; cart.customersBasketProduct = productDetails; } cartProducts.Add(cart); } return(cartProducts); }