Пример #1
0
        public IActionResult Index()
        {
            HttpContext.Session.SetString("SessionName", "Laiman");
            var SessionName = HttpContext.Session.GetString("SessionName");

            ViewBag.device   = _detectionService.Device.Type;
            ViewBag.browser  = _detectionService.Browser.Name;
            ViewBag.platform = _detectionService.Platform.Name;
            ViewBag.engine   = _detectionService.Engine.Name;
            var visitor_ip = _accessor.HttpContext?.Connection?.RemoteIpAddress?.ToString();

            ViewBag.ip      = functions.FormatVisitorIP(visitor_ip);
            ViewBag.country = functions.GetIpInfo("188.130.155.151", "Country");
            ViewBag.session = SessionName;

            string product_id = "9DG52SMLA21F";

            //Get current ViewedProducts session
            var ViewedProducts = (HttpContext.Session.GetString("ViewedProducts") != null) ? HttpContext.Session.GetString("ViewedProducts") : "";

            //if not viewed already
            if (!functions.IsProductViewed(product_id, ViewedProducts))
            {
                //if not null set to session data else set to empty
                HttpContext.Session.SetString("ViewedProducts", ViewedProducts + ",product_id_" + product_id.ToString());
                ViewBag.view = "Logged View";
            }
            else
            {
                ViewBag.view = "Not Logged";
            }

            ViewBag.cartData = HttpContext.Session.GetString("ShoppingCart");

            return(View(_detectionService));
        }
Пример #2
0
        public async Task <IActionResult> Details(string id)
        {
            try
            {
                //Check if string pass in not empty
                if (!string.IsNullOrEmpty(id))
                {
                    //if product does not exists, return home
                    if (!_context.Products.Any(s => s.UniqueProductName == id))
                    {
                        return(RedirectToAction("Index", "Home"));
                    }

                    //get product id from product unique name
                    string product_id = _context.Products.Where(s => s.UniqueProductName == id).FirstOrDefault().ProductID;

                    var productsModel = await _context.Products.FirstOrDefaultAsync(m => m.ProductID == product_id);

                    //check if empty result
                    if (productsModel == null)
                    {
                        //TODO setup Notfound page
                        return(NotFound());
                    }

                    //Get all product images
                    ViewBag.ProductImages = _context.ProductImages.Where(s => s.ProductID == product_id).OrderBy(s => s.ID);

                    //Get product video (if any)
                    ViewBag.ProductVideos = _context.ProductVideos.Where(s => s.ProductID == product_id).OrderBy(s => s.ID);

                    //Get all product colors
                    ViewBag.ProductColors = _context.ProductColors.Where(s => s.ProductID == product_id);

                    //Get all product sizes
                    ViewBag.ProductSizes = _context.ProductSizes.Where(s => s.ProductID == product_id);



                    //log product view to ProductViews table
                    //Get current ViewedProducts session
                    var ViewedProducts = (HttpContext.Session.GetString("ViewedProducts") != null) ? HttpContext.Session.GetString("ViewedProducts") : "";

                    //if not viewed already
                    if (!functions.IsProductViewed(product_id, ViewedProducts))
                    {
                        //TODO get visitor id
                        var visitor_id = "Test-Visitor";
                        var visitor_ip = functions.FormatVisitorIP(_accessor.HttpContext?.Connection?.RemoteIpAddress?.ToString());
                        functions.LogProductView(product_id, visitor_id, visitor_ip, _detectionService.Browser.Name.ToString(), _detectionService.Device.Type.ToString(), null);

                        //if not null set to session data else set to empty
                        HttpContext.Session.SetString("ViewedProducts", ViewedProducts + ",product_id_" + product_id.ToString());
                    }

                    //Return view with product model data
                    return(View(productsModel));
                }
            }
            catch (Exception ex)
            {
                //TODO Log error
                Console.WriteLine(ex);
            }
            //return home if bad parameter passed
            return(RedirectToAction("Index", "Home"));
        }