private void BindData() { int product_id = 0; Int32.TryParse(Request.QueryString["product_id"], out product_id); if (product_id > 0) { using (var context = new WebsiteTTKEntities()) { //Get loged in user info System.Threading.Tasks.Task <Microsoft.AspNet.Identity.EntityFramework.IdentityUser> user = null; if (User.Identity.IsAuthenticated) { var userName = User.Identity.Name; var userStore = new Microsoft.AspNet.Identity.EntityFramework.UserStore <Microsoft.AspNet.Identity.EntityFramework.IdentityUser>(); var userManager = new Microsoft.AspNet.Identity.UserManager <Microsoft.AspNet.Identity.EntityFramework.IdentityUser>(userStore); user = userManager.FindByNameAsync(userName); } //Get product data ProductControllerModel model = ProductController.GetProductDetailData(product_id, user); if (model != null) { //Throw data to client for script to generate the interface of product var productDetailJson = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(model); ProductControllerModel_Data.InnerText = productDetailJson; //Because product slider cannot be modify after script carousel is loaded. //Thus, we generate the slider on server first to help slider load before carousel script run. MakeupProduct(model); } } } }
private void UpdateBasket(string userId, string hostUrl) { string basketUrl = hostUrl + "/basket.aspx"; int removeProductId = 0; Int32.TryParse(Request.QueryString["remove_product_id"], out removeProductId); int orderId = 0; Int32.TryParse(Request.QueryString["order_id"], out orderId); string ids = Helper.GetPlainTextFromHtml(Request.QueryString["ids"]); string quantities = Helper.GetPlainTextFromHtml(Request.QueryString["quantities"]); string coupon_code = Helper.GetPlainTextFromHtml(Request.QueryString["coupon_code"]); if (removeProductId > 0 && orderId > 0) { ProductControllerModel model = ProductController.RemoveProductFromOrder(removeProductId, orderId, userId, OrderStatus.Status.New); if (model.Success) { string resultMessage = ResultCode.RemoveProductFromBasketSuccessful.Value[1].ToString(); ClientScript.RegisterStartupScript(GetType(), "ShowAlert", "window.parent.ShowMessage(0,\"" + resultMessage + "\",true); window.parent.CloseUpdateBasket();", true); } else { ClientScript.RegisterStartupScript(GetType(), "ShowAlert", "window.parent.ShowMessage(0,\"" + model.Message + "\"); window.parent.CloseUpdateBasket();", true); } } else if (!String.IsNullOrEmpty(ids) && !String.IsNullOrEmpty(quantities) && orderId > 0) { ProductControllerModel model = ProductController.UpdateOrderQuantity(ids, quantities, orderId, userId, OrderStatus.Status.New); if (model.Success) { string resultMessage = ResultCode.BasketUpdatedSuccessful.Value[1].ToString(); ClientScript.RegisterStartupScript(GetType(), "ShowAlert", "window.parent.ShowMessage(0,\"" + resultMessage + "\",true); window.parent.CloseUpdateBasket();", true); } else { ClientScript.RegisterStartupScript(GetType(), "ShowAlert", "window.parent.ShowMessage(0,\"" + model.Message + "\"); window.parent.CloseUpdateBasket();", true); } } else if (!String.IsNullOrEmpty(coupon_code) && orderId > 0) { ProductControllerModel model = ProductController.UpdateOrderDiscount(coupon_code, orderId, userId, OrderStatus.Status.New); if (model.Success) { string resultMessage = ResultCode.CouponApplied.Value[1].ToString(); ClientScript.RegisterStartupScript(GetType(), "ShowAlert", "window.parent.ShowMessage(0,\"" + resultMessage + "\",true); window.parent.CloseUpdateBasket();", true); } else { ClientScript.RegisterStartupScript(GetType(), "ShowAlert", "window.parent.ShowMessage(0,\"" + model.Message + "\"); window.parent.CloseUpdateBasket();", true); } } else { Response.Redirect(basketUrl); } }
private void BindData(string userId, string hostUrl) { int product_id = 0; Int32.TryParse(Request.QueryString["product_id"], out product_id); //Get product data ProductControllerModel model = ProductController.AddProductToBasket(product_id, userId); BasketControllerModel basket = ProductController.GetBasket(product_id, userId); //Throw data to client for script to generate the interface of product var productDetailJson = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(basket); Server_Data.InnerText = productDetailJson; }
// var data = {}; //data.ids = recent_product_ids.join('|'); //$.ajax({ //type: "POST", // url: currentHostUrl + "/WebServices/ProductWebService.asmx/GetProducts", // cache: false, // contentType: "application/json; charset=utf-8", // data: JSON.stringify(data), // dataType: "json", // success: ShowProductsViewedRecently, // error: ajaxFailed // }); public List <ProductCurrency> GetProducts(string ids) { if (!String.IsNullOrEmpty(ids)) { int[] product_ids = Array.ConvertAll(ids.Split('|'), int.Parse); ProductControllerModel model = ProductController.GetProductCurrency(product_ids); return(model.ProductItems); } else { return(null); } }
public ActionResult Index() { List <UrunGrup> dbProductGroups = _productGroupData.GetProductGroups(); List <Urun> dbProducts = _productData.GetProducts(); var products = new List <Product>(); var productGroups = new List <ProductGroup>(); foreach (var dbUrunGrup in dbProductGroups) { var productGroup = Converter.Convert <UrunGrup, ProductGroup>(dbUrunGrup); var productMainGroup = productGroups.FirstOrDefault(pg => pg.UrunGrupId == productGroup.AnaGrupId); if (productMainGroup != null) { productGroup.AnaGrupAdi = productMainGroup.UrunGrupAdi; } productGroups.Add(productGroup); } foreach (var dbUrun in dbProducts) { var product = Converter.Convert <Urun, Product>(dbUrun); if (productGroups != null && productGroups.Count > 0) { var productGroup = productGroups.FirstOrDefault(pg => pg.UrunGrupId == product.FKUrunGrupId); if (productGroup != null) { product.UrunGrupText = productGroup.UrunGrupAdi; } } products.Add(product); } var productControllerModel = new ProductControllerModel { Products = products, ProductGroups = productGroups }; return(View(productControllerModel)); }
private void BindData() { int category_id = 0; Int32.TryParse(Request.QueryString["category_id"], out category_id); int store_id = 0; Int32.TryParse(Request.QueryString["store_id"], out store_id); string search_val = Request.QueryString["search_val"]; if (category_id > 0) { //Get product data ProductControllerModel model = ProductController.GetProductByCategory(category_id); if (model != null) { //Throw data to client for script to generate the interface of product var productDetailJson = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(model); Server_Data.InnerText = productDetailJson; } } else if (store_id > 0) { //Get product data ProductControllerModel model = ProductController.GetProductByCategory(0, store_id); if (model != null) { //Throw data to client for script to generate the interface of product var productDetailJson = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(model); Server_Data.InnerText = productDetailJson; } } else if (!String.IsNullOrEmpty(search_val)) { var searchResult = Helper.GetPlainTextFromHtml(search_val); //Get product data ProductControllerModel model = ProductController.GetProductByCategory(0, 0, searchResult); if (model != null) { //Throw data to client for script to generate the interface of product var productDetailJson = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(model); Server_Data.InnerText = productDetailJson; } } }
//Push data to client private void PushDataToClient() { string hostUrl = Helper.GetHostURL(); using (var context = new WebsiteTTKEntities()) { ProductControllerModel model = ProductController.GetHomePageData(); if (model != null) { //--Start: Makeup product silder from home page var product_slider = ""; foreach (var item in model.FeaturedProducts) { var product_image = "img/no_image.jpg"; var itemHtml = "<div class='item'><div class='product'><div class='flip-container'><div class='flipper'>"; int counter = 0; int image_counter = 0; if (item.product_images != null && item.product_images != "") { var images = item.product_images.Split(';'); for (int i = 0; i < images.Length; i++) { var image = images[i]; if (image != "") { if (counter == 0) { product_image = image; //Set the first image of this product. Which could use as the fron image itemHtml += "<div class='front'><a href='" + hostUrl + "/product-detail.aspx?product_id=" + item.product_id + "'>" + "<img src='" + hostUrl + "/" + image + "' alt='" + item.product_name + "' class='img-fluid'></a></div>"; image_counter++; } else if (counter == 1) { itemHtml += "<div class='back'><a href='" + hostUrl + "/product-detail.aspx?product_id=" + item.product_id + "'>" + "<img src='" + hostUrl + "/" + image + "' alt='" + item.product_name + "' class='img-fluid'></a></div>"; image_counter++; } counter++; } } if (image_counter == 1) { itemHtml += "<div class='back'><a href='" + hostUrl + "/product-detail.aspx?product_id=" + item.product_id + "'>" + "<img src='" + hostUrl + "/img/no_image.jpg' alt='" + item.product_name + "' class='img-fluid'></a></div>"; } } else { for (int i = 0; i < 2; i++) { if (i == 0) { itemHtml += "<div class='front'><a href='" + hostUrl + "/product-detail.aspx?product_id=" + item.product_id + "'>" + "<img src='" + hostUrl + "/img/no_image.jpg' alt='" + item.product_name + "' class='img-fluid'></a></div>"; } else if (i == 1) { itemHtml += "<div class='back'><a href='" + hostUrl + "/product-detail.aspx?product_id=" + item.product_id + "'>" + "<img src='" + hostUrl + "/img/no_image.jpg' alt='" + item.product_name + "' class='img-fluid'></a></div>"; } } } itemHtml += "</div></div><a href='" + hostUrl + "/product-detail.aspx?product_id=" + item.product_id + "' class='invisible'>" + "<img src='" + hostUrl + "/" + product_image + "' alt='" + item.product_name + "' class='img-fluid'></a><div class='text'>" + "<h3><a href='" + hostUrl + "/product-detail.aspx?product_id=" + item.product_id + "'>" + item.product_name + "</a></h3>" + "<p class='price'><del></del>" + Helper.FormatCurrency(item.list_price, item.currency_code) + " </p></div>"; if (item.is_sale != null) { if (item.is_sale.Value) { itemHtml += "<div class='ribbon sale'><div class='theribbon'>SALE</div><div class='ribbon-background'></div></div>"; } } if (item.is_new != null) { if (item.is_new.Value) { itemHtml += "<div class='ribbon new'><div class='theribbon'>NEW</div><div class='ribbon-background'></div></div>"; } } if (item.is_gift != null) { if (item.is_gift.Value) { itemHtml += "<div class='ribbon gift'><div class='theribbon'>GIFT</div><div class='ribbon-background'></div></div>"; } } //End of product item itemHtml += "</div></div>"; product_slider += itemHtml; } ttk_shop_slider.InnerHtml = product_slider; //--End: Makeup product silder from home page //--Start: Makeup collection silder from home page var collection_slider = ""; foreach (var item in model.Categories) { collection_slider += "<div class='col-md-12'><div class='box slideshow'>"; string collectionTitle = ""; if (!String.IsNullOrEmpty(item.category_name)) { collectionTitle = "<h3>" + item.category_name + "</h3>"; } string collectionDescription = ""; if (!String.IsNullOrEmpty(item.category_description)) { collectionDescription = "<p class='lead'>" + item.category_description + "</p>"; } collection_slider += collectionTitle + collectionDescription; var product_image = "img/no_image.jpg"; int counter = 0; if (item.category_images != null && item.category_images != "") { var images = item.category_images.Split(';'); for (int i = 0; i < images.Length; i++) { var image = images[i]; if (image != "") { if (counter == 0) { product_image = image; //Set the first image of this product. Which could use as the fron image collection_slider += "<div id='get-inspired' class='owl-carousel owl-theme'>"; collection_slider += "<div class='item'><a href='" + item.category_url + "'>" + "<img src='" + hostUrl + "/" + image + "' alt='" + item.category_name + "' class='img-fluid'></a></div>"; } else if (counter == images.Length - 1) { collection_slider += "<div class='item'><a href='" + item.category_url + "'>" + "<img src='" + hostUrl + "/" + image + "' alt='" + item.category_name + "' class='img-fluid'></a></div></div>"; } else { collection_slider += "<div class='item'><a href='" + item.category_url + "'>" + "<img src='" + hostUrl + "/" + image + "' alt='" + item.category_name + "' class='img-fluid'></a></div>"; } counter++; } } } //If this category has no image if (product_image == "img/no_image.jpg") { collection_slider += "<div id='get-inspired' class='owl-carousel owl-theme'>"; collection_slider += "<div class='item'><a href='" + item.category_url + "'>" + "<img src='" + hostUrl + "/" + product_image + "' alt='" + item.category_name + "' class='img-fluid'></a></div></div>"; } collection_slider += "</div></div>"; } collection_panel.InnerHtml = collection_slider; //--End: Makeup collection silder from home page } else { ttk_shop_slider.InnerHtml = "<h3>No featured product! Please add one.</h3>"; } } }
//Because product slider cannot be modify after script carousel is loaded. //Thus, we generate the slider on server first to help slider load before carousel script run. private void MakeupProduct(ProductControllerModel model) { string hostUrl = Helper.GetHostURL(); ProductCurrency qProduct = model.Product; List <wishlist> wishlists = model.Wishlists; var no_image = "img/no_image.jpg"; var product_image = "img/no_image.jpg"; var itemHtml = "<div class='col-md-6'>"; if (qProduct.product_images != null && qProduct.product_images != "") { itemHtml += "<div data-slider-id='1' class='owl-carousel shop-detail-carousel'>"; var images = qProduct.product_images.Split(';'); for (int i = 0; i < images.Length; i++) { var image = images[i]; if (image != "") { product_image = image; //Set the first image of this product. Which could use as the fron image itemHtml += "<div class='item'><img src='" + hostUrl + "/" + image + "' alt='" + qProduct.product_name + "' class='img-fluid'></div>"; } } } else { itemHtml += "<div class='item'><img src='" + hostUrl + "/" + no_image + "' alt='" + qProduct.product_name + "' class='img-fluid'></div>"; } itemHtml += "</div>"; if (qProduct.is_sale != null) { if (qProduct.is_sale.Value) { itemHtml += "<div class='ribbon sale'><div class='theribbon'>SALE</div><div class='ribbon-background'></div></div>"; } } if (qProduct.is_new != null) { if (qProduct.is_new.Value) { itemHtml += "<div class='ribbon new'><div class='theribbon'>NEW</div><div class='ribbon-background'></div></div>"; } } if (qProduct.is_gift != null) { if (qProduct.is_gift.Value) { itemHtml += "<div class='ribbon gift'><div class='theribbon'>GIFT</div><div class='ribbon-background'></div></div>"; } } itemHtml += "</div>"; //Create price bar itemHtml += "<div class='col-md-6'>"; itemHtml += "<div class='box'>"; itemHtml += "<h1 class='text-center'>" + qProduct.product_name + "</h1>"; itemHtml += "<p class='goToDescription'><a href='#details' class='scroll-to'>Scroll to product details, material & care and sizing</a></p>"; itemHtml += "<p class='goToDescription'><p class='price'>" + Helper.FormatCurrency(qProduct.list_price, qProduct.currency_code) + "</p>"; if (qProduct.colour_id > 0) { itemHtml += "<p class='goToDescription'><span class='colour' style='background: " + qProduct.colour_name + "; border-radius: 10px;'> </span> " + qProduct.colour_description + "</p>"; } itemHtml += "<p class='text-center buttons'><a onclick=\"return AddToCart('" + hostUrl + "/basket.aspx?product_id=" + qProduct.product_id + "');\" style='cursor: pointer;' class='btn btn-primary'><i class='fa fa-shopping-cart'></i>Add to cart</a><a style='cursor: pointer;' onclick=\"return AddToWishlist('" + qProduct.product_id + "');\" class='btn " + "btn-outline-primary'>"; if (wishlists != null) { itemHtml += "<i class='fa fa-heart' id='wishlist_icon'></i> Add to wishlist</a></p>"; } else { itemHtml += "<i class='fa fa-heart-o' id='wishlist_icon'></i> Add to wishlist</a></p>"; } itemHtml += "</div>"; //Create thumber buttons if (qProduct.product_images != null && qProduct.product_images != "") { itemHtml += "<div data-slider-id='1' class='owl-thumbs'>"; var images = qProduct.product_images.Split(';'); for (int i = 0; i < images.Length; i++) { var image = images[i]; if (image != "") { product_image = image; //Set the first image of this product. Which could use as the fron image itemHtml += "<button class='owl-thumb-item'><img src='" + hostUrl + "/" + image + "' alt='" + qProduct.product_name + "' class='img-fluid'></button>"; } } itemHtml += "</div>"; } else { itemHtml += "<div data-slider-id='1' class='owl-thumbs'><button class='owl-thumb-item'><img src='" + hostUrl + "/" + no_image + "' alt='" + qProduct.product_name + "' class='img-fluid'></button></div>"; } itemHtml += "</div>"; //End of product item productMain.InnerHtml = itemHtml; }
//Push data to client private void PushDataToClient(string userId, string hostUrl) { ProductControllerModel model = ProductController.GetWishlist(userId); var totalProducts = 0; if (model.ProductItems != null) { totalProducts = model.ProductItems.Count(); string html = ""; foreach (var item in model.ProductItems) { html += "<div class='col-lg-3 col-md-4'><div class='product'>"; var no_image = hostUrl + "/" + "img/no_image.jpg"; var product_image = ""; int counter = 0; if (item.product_images != null && item.product_images != "") { var images = item.product_images.Split(';'); for (int i = 0; i < images.Length; i++) { var image = images[i]; if (image != "") { if (counter == 0) { product_image = image; ///product-detail.aspx?product_id=327 html += "<div class='flip-container'>"; html += "<div class='flipper'><div class='front'><a href='" + hostUrl + "/product-detail.aspx?product_id=" + item.product_id + "'>" + "<img src='" + hostUrl + "/" + image + "' alt='" + item.product_name + "' class='img-fluid'></a></div>"; } else if (counter == 1) { html += "<div class='back'><a href='" + hostUrl + "/product-detail.aspx?product_id=" + item.product_id + "'>" + "<img src='" + hostUrl + "/" + image + "' alt='" + item.product_name + "' class='img-fluid'></a></div></div></div>"; } counter++; } } if (counter == 0) { html += "<div class='flip-container'>"; html += "<div class='flipper'><div class='front'><a href='" + hostUrl + "/product-detail.aspx?product_id=" + item.product_id + "'>" + "<img src='" + hostUrl + "/" + no_image + "' alt='" + item.product_name + "' class='img-fluid'></a></div>"; html += "<div class='back'><a href='" + hostUrl + "/product-detail.aspx?product_id=" + item.product_id + "'>" + "<img src='" + hostUrl + "/" + no_image + "' alt='" + item.product_name + "' class='img-fluid'></a></div></div></div>"; html += "<a href='" + hostUrl + "/product-detail.aspx?product_id=" + item.product_id + "' class='invisible'>" + "<img src='" + hostUrl + "/" + no_image + "' alt='" + item.product_name + "' class='img-fluid'></a>"; } else if (counter == 1) { html += "<div class='back'><a href='" + hostUrl + "/product-detail.aspx?product_id=" + item.product_id + "'>" + "<img src='" + hostUrl + "/" + no_image + "' alt='" + item.product_name + "' class='img-fluid'></a></div></div></div>"; html += "<a href='" + hostUrl + "/product-detail.aspx?product_id=" + item.product_id + "' class='invisible'>" + "<img src='" + hostUrl + "/" + no_image + "' alt='" + item.product_name + "' class='img-fluid'></a>"; } else { html += "<a href='" + hostUrl + "/product-detail.aspx?product_id=" + item.product_id + "' class='invisible'>" + "<img src='" + hostUrl + "/" + product_image + "' alt='" + item.product_name + "' class='img-fluid'></a>"; } html += "<div class='text'><h3><a href='" + hostUrl + "/product-detail.aspx?product_id=" + item.product_id + "'>" + item.product_name + "</a></h3>" + "<p class='price'><del></del>" + Helper.FormatCurrency(item.list_price, item.currency_code) + "</p>" + "<p class='buttons'><a href='" + hostUrl + "/product-detail.aspx?product_id=" + item.product_id + "' class='btn btn-outline-secondary'>View detail</a>" + "<a href='" + hostUrl + "/basket.aspx?product_id=" + item.product_id + "' class='btn btn-primary'><i class='fa fa-shopping-cart'></i>Add to cart</a></p>" + "</div>"; if (item.is_sale != null) { if (item.is_sale.Value) { html += "<div class='ribbon sale'><div class='theribbon'>SALE</div><div class='ribbon-background'></div></div>"; } } if (item.is_new != null) { if (item.is_new.Value) { html += "<div class='ribbon new'><div class='theribbon'>NEW</div><div class='ribbon-background'></div></div>"; } } if (item.is_gift != null) { if (item.is_gift.Value) { html += "<div class='ribbon gift'><div class='theribbon'>GIFT</div><div class='ribbon-background'></div></div>"; } } } html += "</div></div>"; } wishlist_region.InnerHtml = html; } if (model != null) { ProductControllerModel model1 = new ProductControllerModel(); model1.TotalProducts = totalProducts; var modelJson = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(model1); Wishlist_Data.InnerText = modelJson; } }
public ProductControllerModel AddToWishlist(string product_id) { ProductControllerModel model = ProductController.AddToWishlist(product_id); return(model); }