working on it ...

Filters

Explore Public Snippets

Sort by

Found 694 snippets

    public by JKCPR modified Mar 31, 2018  349  0  4  0

    Fibonacci meh

    Loops over the Fibonnaci sequence...might be useful in an interview.
     
    function fibonacci(num, memo) {
      memo = memo || {};
    
      return memo[num]? memo[num]: num < 2? 1: memo[num] = fibonacci(num - 1, memo) + fibonacci(num - 2, memo);
    }
        for(var i=0;i<100;i=i+1){
            this.console.log(fibonacci(i));
        }

    public by JKCPR modified May 12, 2017  308  1  5  1

    is your DOM classy? Wouldn't your console like to know...

    Intended as Dev Tool to be utilised in the browser console so that refactoring your messy CSS can be less hurty.
    ;( 
      function (){
      "use strict";
    
      //get ALL DOM elements => BODY > *, BODY *
      var elms = document.body.getElementsByTagName("*"),
          i = elms.length,
          arr = [],
          classArray;
      
      //iterate, isolate, finally indicate
      while( i-- ) {
          classArray = elms[i].className.split(/\s+/);
          if (classArray.length > 1) {
              arr.push( classArray[1] );
          }
      }
      
      console.log( arr.join(',') );
      return arr;
      
    })();

    public by jbaro modified Oct 25, 2016  5119  0  5  0

    customize embebed google maps

    /*********
    ******** params:
    ** lat: latitude
    ** lng:longitude
    ** elid: id of container
    ** iconpath: path to marker icon if necesary
    ** style: styles json
    ******** Note:
    ** You need to load google map library
    ** <script src="https://maps.googleapis.com/maps/api/js?key=YOURAPIKEY"><\/script>
    ***********/
    
    
    function initMap(lat,lng,elid,iconpath,style) {
    
    	// Create an array of styles.
    	var styles = style;
    	// Create a new StyledMapType object, passing it the array of styles,
    	// as well as the name to be displayed on the map type control.
    	var styledMap = new google.maps.StyledMapType(styles,{name: "Styled Map"});
    	// Create a map object, and include the MapTypeId to add
    	// to the map type control.
    	var myLatLng = new google.maps.LatLng(lat,lng);
    	var mapOptions = {
    		zoom: 11,
    		center: myLatLng,
    		disableDefaultUI: true,//avoid controls
    		scrollwheel: false,//avoid scrollwheel zoom
    		//draggable: false,//avoid draggable map
    		mapTypeControlOptions: {
    			mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style']
    		}
    	};
    	var map = new google.maps.Map(document.getElementById(elid),mapOptions);
    	if(iconpath){
    		var marker = new google.maps.Marker({
    		  position: myLatLng,
    		  map: map,
    		  icon: iconpath
    		});
    	}
    	//Associate the styled map with the MapTypeId and set it to display.
    	map.mapTypes.set('map_style', styledMap);
    	map.setMapTypeId('map_style');
    }
    
    //silver styles example
    var mapsbw = [
    		{
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#f5f5f5"
    			}
    		  ]
    		},
    		{
    		  "elementType": "labels.icon",
    		  "stylers": [
    			{
    			  "visibility": "off"
    			}
    		  ]
    		},
    		{
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#616161"
    			}
    		  ]
    		},
    		{
    		  "elementType": "labels.text.stroke",
    		  "stylers": [
    			{
    			  "color": "#f5f5f5"
    			}
    		  ]
    		},
    		{
    		  "featureType": "administrative.land_parcel",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#bdbdbd"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#eeeeee"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#757575"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi.park",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#e5e5e5"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi.park",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#9e9e9e"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#ffffff"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.arterial",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#757575"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.highway",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#dadada"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.highway",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#616161"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.local",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#9e9e9e"
    			}
    		  ]
    		},
    		{
    		  "featureType": "transit.line",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#e5e5e5"
    			}
    		  ]
    		},
    		{
    		  "featureType": "transit.station",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#eeeeee"
    			}
    		  ]
    		},
    		{
    		  "featureType": "water",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#c9c9c9"
    			}
    		  ]
    		},
    		{
    		  "featureType": "water",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#9e9e9e"
    			}
    		  ]
    		}
    	  ];
    //init example
    initMap(42.8107705, -1.6616108,'map','./img/gm_marker.png',mapsbw);
    
                                  

    public by jbaro modified Oct 25, 2016  332636  8  2  0

    Google maps customized

    Load a google map customized
    /*********
    lat: latitude
    lng:longitude
    elid: id of container
    iconpath: path to marker icon if necesary
    style: styles json
    ***********/
    
    
    function initMap(lat,lng,elid,iconpath,style) {
    
    	// Create an array of styles.
    	var styles = style;
    	// Create a new StyledMapType object, passing it the array of styles,
    	// as well as the name to be displayed on the map type control.
    	var styledMap = new google.maps.StyledMapType(styles,{name: "Styled Map"});
    	// Create a map object, and include the MapTypeId to add
    	// to the map type control.
    	var myLatLng = new google.maps.LatLng(lat,lng);
    	var mapOptions = {
    		zoom: 11,
    		center: myLatLng,
    		mapTypeControlOptions: {
    			mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style']
    		}
    	};
    	var map = new google.maps.Map(document.getElementById(elid),mapOptions);
    	if(iconpath){
    		var marker = new google.maps.Marker({
    		  position: myLatLng,
    		  map: map,
    		  icon: iconpath
    		});
    	}
    	//Associate the styled map with the MapTypeId and set it to display.
    	map.mapTypes.set('map_style', styledMap);
    	map.setMapTypeId('map_style');
    }
    
    //silver styles example
    var mapsbw = [
    		{
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#f5f5f5"
    			}
    		  ]
    		},
    		{
    		  "elementType": "labels.icon",
    		  "stylers": [
    			{
    			  "visibility": "off"
    			}
    		  ]
    		},
    		{
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#616161"
    			}
    		  ]
    		},
    		{
    		  "elementType": "labels.text.stroke",
    		  "stylers": [
    			{
    			  "color": "#f5f5f5"
    			}
    		  ]
    		},
    		{
    		  "featureType": "administrative.land_parcel",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#bdbdbd"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#eeeeee"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#757575"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi.park",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#e5e5e5"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi.park",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#9e9e9e"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#ffffff"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.arterial",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#757575"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.highway",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#dadada"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.highway",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#616161"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.local",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#9e9e9e"
    			}
    		  ]
    		},
    		{
    		  "featureType": "transit.line",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#e5e5e5"
    			}
    		  ]
    		},
    		{
    		  "featureType": "transit.station",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#eeeeee"
    			}
    		  ]
    		},
    		{
    		  "featureType": "water",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#c9c9c9"
    			}
    		  ]
    		},
    		{
    		  "featureType": "water",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#9e9e9e"
    			}
    		  ]
    		}
    	  ];
    //init example
    initMap(42.8107705, -1.6616108,'map','./img/gm_marker.png',mapsbw);

    public by jbaro modified Oct 25, 2016  637  8  3  0

    Google maps customized

    Load a google map customized
    /*********
    lat: latitude
    lng:longitude
    elid: id of container
    iconpath: path to marker icon if necesary
    style: styles
    ***********/
    
    
    function initMap(lat,lng,elid,iconpath,style) {
    
    	// Create an array of styles.
    	var styles = style;
    	// Create a new StyledMapType object, passing it the array of styles,
    	// as well as the name to be displayed on the map type control.
    	var styledMap = new google.maps.StyledMapType(styles,{name: "Styled Map"});
    	// Create a map object, and include the MapTypeId to add
    	// to the map type control.
    	var myLatLng = new google.maps.LatLng(lat,lng);
    	var mapOptions = {
    		zoom: 11,
    		center: myLatLng,
    		mapTypeControlOptions: {
    			mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style']
    		}
    	};
    	var map = new google.maps.Map(document.getElementById(elid),mapOptions);
    	if(iconpath){
    		var marker = new google.maps.Marker({
    		  position: myLatLng,
    		  map: map,
    		  icon: iconpath
    		});
    	}
    	//Associate the styled map with the MapTypeId and set it to display.
    	map.mapTypes.set('map_style', styledMap);
    	map.setMapTypeId('map_style');
    }
    
    //silver styles example
    var mapsbw = [
    		{
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#f5f5f5"
    			}
    		  ]
    		},
    		{
    		  "elementType": "labels.icon",
    		  "stylers": [
    			{
    			  "visibility": "off"
    			}
    		  ]
    		},
    		{
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#616161"
    			}
    		  ]
    		},
    		{
    		  "elementType": "labels.text.stroke",
    		  "stylers": [
    			{
    			  "color": "#f5f5f5"
    			}
    		  ]
    		},
    		{
    		  "featureType": "administrative.land_parcel",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#bdbdbd"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#eeeeee"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#757575"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi.park",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#e5e5e5"
    			}
    		  ]
    		},
    		{
    		  "featureType": "poi.park",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#9e9e9e"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#ffffff"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.arterial",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#757575"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.highway",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#dadada"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.highway",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#616161"
    			}
    		  ]
    		},
    		{
    		  "featureType": "road.local",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#9e9e9e"
    			}
    		  ]
    		},
    		{
    		  "featureType": "transit.line",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#e5e5e5"
    			}
    		  ]
    		},
    		{
    		  "featureType": "transit.station",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#eeeeee"
    			}
    		  ]
    		},
    		{
    		  "featureType": "water",
    		  "elementType": "geometry",
    		  "stylers": [
    			{
    			  "color": "#c9c9c9"
    			}
    		  ]
    		},
    		{
    		  "featureType": "water",
    		  "elementType": "labels.text.fill",
    		  "stylers": [
    			{
    			  "color": "#9e9e9e"
    			}
    		  ]
    		}
    	  ];
    //init example
    initMap(42.8107705, -1.6616108,'map','./img/gm_marker.png',mapsbw);

    public by bablefish modified Feb 11, 2016  2300  0  6  0

    Set selected option in a valuelist

    Using a javascript function with the leave code number as a parameter, how do I select the appropriate option in the list?
    function SelectElement(valueToSelect)
    {    
        var element = document.getElementById('leaveCode');
        element.value = valueToSelect;
    }

    external by Selvakumar Murugesan modified Feb 19, 2018  5  0  1  0

    Notes on Ractive JS

    Notes on Ractive JS: Ractive JS
    Ractive JS - it has the combination of both angular & react great features
    Mustach Templates
    Events & Method Calls -Proxy 
    LifeCycle Events - Render
    2 Way Data Binding
    Observers
    Transitions & Animations
    
    
    

    external by Github modified Feb 18, 2018  11  0  1  0

    Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-v0.4.21-nightly.2018.2.16+commit.3f7e82d0.js&optimize=fals...

    Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-v0.4.21-nightly.2018.2.16+commit.3f7e82d0.js&optimize=false&gist=: ballot.sol
    pragma solidity ^0.4.4;
    
    contract Token {
    
        /// @return total amount of tokens
        function totalSupply() constant returns (uint256 supply) {}
    
        /// @param _owner The address from which the balance will be retrieved
        /// @return The balance
        function balanceOf(address _owner) constant returns (uint256 balance) {}
    
        /// @notice send `_value` token to `_to` from `msg.sender`
        /// @param _to The address of the recipient
        /// @param _value The amount of token to be transferred
        /// @return Whether the transfer was successful or not
        function transfer(address _to, uint256 _value) returns (bool success) {}
    
        /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
        /// @param _from The address of the sender
        /// @param _to The address of the recipient
        /// @param _value The amount of token to be transferred
        /// @return Whether the transfer was successful or not
        function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
    
        /// @notice `msg.sender` approves `_addr` to spend `_value` tokens
        /// @param _spender The address of the account able to transfer the tokens
        /// @param _value The amount of wei to be approved for transfer
        /// @return Whether the approval was successful or not
        function approve(address _spender, uint256 _value) returns (bool success) {}
    
        /// @param _owner The address of the account owning tokens
        /// @param _spender The address of the account able to transfer the tokens
        /// @return Amount of remaining tokens allowed to spent
        function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
    
        event Transfer(address indexed _from, address indexed _to, uint256 _value);
        event Approval(address indexed _owner, address indexed _spender, uint256 _value);
        
    }
    
    
    
    contract StandardToken is Token {
    
        function transfer(address _to, uint256 _value) returns (bool success) {
            //Default assumes totalSupply can't be over max (2^256 - 1).
            //If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap.
            //Replace the if with this one instead.
            //if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
            if (balances[msg.sender] >= _value && _value > 0) {
                balances[msg.sender] -= _value;
                balances[_to] += _value;
                Transfer(msg.sender, _to, _value);
                return true;
            } else { return false; }
        }
    
        function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
            //same as above. Replace this line with the following if you want to protect against wrapping uints.
            //if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
            if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
                balances[_to] += _value;
                balances[_from] -= _value;
                allowed[_from][msg.sender] -= _value;
                Transfer(_from, _to, _value);
                return true;
            } else { return false; }
        }
    
        function balanceOf(address _owner) constant returns (uint256 balance) {
            return balances[_owner];
        }
    
        function approve(address _spender, uint256 _value) returns (bool success) {
            allowed[msg.sender][_spender] = _value;
            Approval(msg.sender, _spender, _value);
            return true;
        }
    
        function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
          return allowed[_owner][_spender];
        }
    
        mapping (address => uint256) balances;
        mapping (address => mapping (address => uint256)) allowed;
        uint256 public totalSupply;
    }
    
    
    //name this contract whatever you'd like
    contract Digitelcoin is StandardToken {
    
        function () {
            //if ether is sent to this address, send it back.
            throw;
        }
    
        /* Public variables of the token */
    
        /*
        NOTE:
        The following variables are OPTIONAL vanities. One does not have to include them.
        They allow one to customise the token contract & in no way influences the core functionality.
        Some wallets/interfaces might not even bother to look at this information.
        */
        string public name;                   //fancy name: eg Simon Bucks
        uint8 public decimals;                //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether.
        string public symbol;                 //An identifier: eg SBX
        string public version = 'H1.0';       //human 0.1 standard. Just an arbitrary versioning scheme.
    
    //
    // CHANGE THESE VALUES FOR YOUR TOKEN
    //
    
    //make sure this function name matches the contract name above. So if you're token is called TutorialToken, make sure the //contract name above is also TutorialToken instead of ERC20Token
    
        function Digitelcoin(
            ) {
            balances[msg.sender] = 30000000000000000;               // Give the creator all initial tokens (100000 for example)
            totalSupply = 300000000000000000;                        // Update total supply (100000 for example)
            name = "Digitelcoin";                                   // Set the name for display purposes
            decimals = 8;                            // Amount of decimals for display purposes
            symbol = "DGTC";                               // Set the symbol for display purposes
        }
    
        /* Approves and then calls the receiving contract */
        function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
            allowed[msg.sender][_spender] = _value;
            Approval(msg.sender, _spender, _value);
    
            //call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
            //receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
            //it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
            if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
            return true;
        }
    }
    
    

    external by joshi-kumar modified Feb 17, 2018  6  0  1  0

    Chart js

    Chart js: Chart js
    Controller
    
    using DotNet.Highcharts.Options;
    using Nop.Core.Domain.Customers;
    using Nop.Plugin.OneRead.AnalyticsAndReports.Domain;
    using Nop.Plugin.OneRead.AnalyticsAndReports.Models;
    using Nop.Plugin.OneRead.AnalyticsAndReports.Services;
    using Nop.Services.Common;
    using Nop.Services.Customers;
    using Nop.Web.Framework.Controllers;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Web.Mvc;
    
    namespace Nop.Plugin.OneRead.AnalyticsAndReports.Controllers
    {
        public class AnalyticsAndReportsController : BasePluginController
        {
            #region Global Obj
    
            private readonly IAnalyticsAndReportService _analyticsAndReportService;
            private readonly ICustomerService _customerService;
            private readonly IGenericAttributeService _genericAttributeService;
    
            #endregion
    
            #region Cons
    
            public AnalyticsAndReportsController(IAnalyticsAndReportService analyticsAndReportService, ICustomerService customerService, IGenericAttributeService genericAttributeService)
            {
    
                this._analyticsAndReportService = analyticsAndReportService;
                this._customerService = customerService;
                this._genericAttributeService = genericAttributeService;
            }
            public ActionResult InsertAnalytic(int productId = 0, int typeId = 0, int categoryId = 0)
            {
                if (productId > 0)
                    _analyticsAndReportService.InsretProductAnalytics(productId, typeId);
    
                if (categoryId > 0)
                    _analyticsAndReportService.InsretCategoryAnalytics(categoryId, typeId);
    
    
                return null;
            }
            public ActionResult InsertAnalytics(int productId = 0, int typeId = 0, int categoryId = 0)
            {
                if (productId > 0)
                    _analyticsAndReportService.InsretProductAnalytics(productId, typeId);
    
                if (categoryId > 0)
                    _analyticsAndReportService.InsretCategoryAnalytics(categoryId, typeId);
    
    
                return Json("", JsonRequestBehavior.AllowGet);
            }
    
            #endregion
    
            #region High-charts
    
            public ActionResult HighCharts()
            {
                DateTimeModel model = new DateTimeModel();
                return View(model);
            }
    
            [HttpGet]
            public JsonResult DisplayChart(int viewtypeid, DateTime startDate, DateTime endDate, int actionType = 0)
            {
                List<HighChartModel> list = new List<HighChartModel>();
                List<HighChartModel> list_d = new List<HighChartModel>();
    
                List<int> existing = new List<int>();
                List<int> existing_d = new List<int>();
    
                var record = new List<AnalyticsAndReportsProduct>();
                var record_d = new List<AnalyticsAndReportsProduct>();
    
                if (actionType == 10 || actionType==40 || actionType == 50) //10 for Browse and download,40 for age group, 50 for downloaded by country 
                {
                    record = _analyticsAndReportService.GetBrowesProduct();
                    record_d = _analyticsAndReportService.GetDownloadProduct();
                }
                else if (actionType == 30)//30 for publish
                {
                    record = _analyticsAndReportService.GetPublishProduct();
                }
    
    
    
                #region downloaded by country
                if (actionType == 50)
                {
                   // list = AgeGroupBrowsedProduct(record, list);
                    list_d = ProductDownloadedByCountry(record_d, list_d);
    
                    return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet);
                }
                #endregion
    
                #region age group
                if (actionType==40)
                {
                    list = AgeGroupBrowsedProduct(record, list);
                    list_d = AgeGroupDownloadedProduct(record_d,list_d);
    
                    return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet);
                }
                 #endregion
    
                #region year view
                if (viewtypeid == 10)
                {
                    list = ProductBrowseOrPublishYearView(list, record, existing);
    
                    if (actionType == 10)
                    {
                        list_d = ProductDownloadedYearView(list_d, record_d, existing_d);
                    }
                    return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet);
                }
                #endregion year
    
                #region month view
    
                else if (viewtypeid == 20)
                {
                    list = ProductBrowseOrPublishMonthView(list, record, existing);
                   
                    if (actionType == 10)
                    {
                       list_d = ProductDownloadedMonthView(list_d, record_d, existing_d);
                    }
                    return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet);
                }
                #endregion year
    
                #region week view
         
                else if (viewtypeid == 30)
                {
                  list =  ProductBrowseOrPublishWeekView(list, record);
                    if(actionType==10)
                    {
                      list_d =   ProductDownloadedWeekView(list_d, record_d);
                    }
                    return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet);
                }
                #endregion year
    
                #region Date range
    
                else if (viewtypeid == 0)
                {
                    int startYear = startDate.Year;
                    int endYear = endDate.Year;
                    int startMonth = startDate.Month;
                    int endMonth = endDate.Month;
    
                    var dateRangeRecord = (from m in record
                                           where m.CreatedOnUtc >= startDate && m.CreatedOnUtc <= endDate
                                           orderby m.CreatedOnUtc.Month ascending
                                           select m).ToList();
    
                    var dateRangeRecord_d = (from m in record_d
                                           where m.CreatedOnUtc >= startDate && m.CreatedOnUtc <= endDate
                                           orderby m.CreatedOnUtc.Month ascending
                                           select m).ToList();
    
                    if (startMonth == endMonth && startYear == endYear) //Display weekly or day bases
                    {
                        double days = (endDate - startDate).TotalDays;
    
                        if (days < 10)
                        {
                            list = ProductBrowseOrPublishDateRangeDaysView(list, existing, dateRangeRecord);
    
                            if(actionType==10)
                            {
                                list_d = ProductDownloadedDaysView(list_d, existing_d, dateRangeRecord_d);
                            }
                            return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet);
                        }
                        else
                        {
                            int diff = Convert.ToInt32(days / 7);
                            double mod = Convert.ToInt32(days % 7);
                            if (mod != 0 && mod < 4)
                            {
                                diff = diff + 1;
                            }
    
                            list = ProductBrowseOrPublishDateRangeWeekView(startDate, list, ref dateRangeRecord, days, diff);
                         
                            if(actionType==10)
                            {
                                list_d = ProductDownloadedDateRangeWeekView(startDate, list_d, dateRangeRecord_d, diff);
                            }
                            return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet);
                        }
                    }
                    else if (startYear == endYear) //Display monthly
                    {
                        list = ProductBrowseOrPublishDateRangeMonthView(list, existing, dateRangeRecord);
    
                        if(actionType==10)
                        {
                          list_d =  ProductDownloadedDateRangeMonthView(list_d, existing_d, dateRangeRecord_d);
                        }
                        return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet);
                    }
                    else if (startYear < endYear) // Display yearly 
                    {
                        list = ProductBrowseOrPublishDateRangeYearView(list, record, existing, dateRangeRecord);
    
                         if (actionType == 10)
                            {
                                list_d = ProductDownloadedDateRangeYearView(list_d, record_d, existing_d, dateRangeRecord_d);
                            }
                         return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet);
                    }
                }
                #endregion Date range
    
               return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet);
            }
          
            [HttpGet]
            public JsonResult DisplayCategoryChart(int viewtypeid, DateTime startDate, DateTime endDate)
            {
                List<HighChartModel> list = new List<HighChartModel>();
                //var record = new List<AnalyticsAndReportsCategory>();
                var record = _analyticsAndReportService.GetBrowesCategory();
                List<int> existing = new List<int>();
    
                #region year view
                if (viewtypeid == 10)
                {
                    list = CategoryBrowseYearView(list, record, existing);
                    return Json(list, JsonRequestBehavior.AllowGet);
                }
                #endregion year
    
                #region month view
                else if (viewtypeid == 20)
                {
                    list = CategorytBrowseMonthView(list, record, existing);
                    return Json(list, JsonRequestBehavior.AllowGet);
                }
                #endregion year
    
                #region week view
                else if (viewtypeid == 30)
                {
                    list = CategorytBrowseWeekView(list, record);
                    return Json(list, JsonRequestBehavior.AllowGet);
                }
                #endregion year
    
                #region Date range
    
                else if (viewtypeid == 0)
                {
                    int startYear = startDate.Year;
                    int endYear = endDate.Year;
                    int startMonth = startDate.Month;
                    int endMonth = endDate.Month;
    
                    var dateRangeRecord = (from m in record
                                           where m.CreatedOnUtc.Date >= startDate && m.CreatedOnUtc.Date <= endDate
                                           orderby m.CreatedOnUtc.Month ascending
                                           select m).ToList();
    
                    if (startMonth == endMonth && startYear == endYear) //Display weekly or dayly bases
                    {
                        double days = (endDate - startDate).TotalDays;
                        if (days < 10)
                        {
                            list = CategorytBrowseDateRangeDaysView(list, existing, dateRangeRecord);
                            return Json(list, JsonRequestBehavior.AllowGet);
                        }
                        else
                        {
                            list = CategorytBrowseDateRangeWeekView(startDate, list, dateRangeRecord, days);
                            return Json(list, JsonRequestBehavior.AllowGet);
                        }
                    }
                    else if (startYear == endYear) //Display monthly
                    {
                        list = CategorytBrowseDateRangeMonthView(list, existing, dateRangeRecord);
                        return Json(list, JsonRequestBehavior.AllowGet);
                    }
                    else if (startYear < endYear) // Display yearly 
                    {
                        list = CategorytBrowseDateRangeYearView(list, record, existing, dateRangeRecord);
                        return Json(list, JsonRequestBehavior.AllowGet);
                    }
    
                }
                #endregion Date range
    
                return Json(list, JsonRequestBehavior.AllowGet);
            }
    
            [HttpGet]
            public JsonResult DisplayCustomerChart(int viewtypeid, DateTime startDate, DateTime endDate, int actionType = 0)
            {
                List<HighChartModel> list = new List<HighChartModel>();
                List<HighChartModel> list_d = new List<HighChartModel>();
    
                List<int> existing = new List<int>();
                List<int> existing_d = new List<int>();
    
                var record = new List<AnalyticsAndReportsProduct>();
                var record_d = new List<AnalyticsAndReportsProduct>();
    
                var allCustomers = _customerService.getAllCustomer();
    
                #region user Demographics
                if (actionType == 60)
                {
                    list = UserDemographicsView(allCustomers, list);
    
                    return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet);
                }
                #endregion
    
                #region User Timeline
                else if (actionType == 70)
                {
                    #region year view
                    if (viewtypeid == 10)
                    {
                        list = ActiveUserYearView(allCustomers ,list);
                        list_d = NewUserYearView(allCustomers, list_d);
                        
                        return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet);
                    }
                    #endregion year
    
                    #region month view
    
                    else if (viewtypeid == 20)
                    {
                        list = ActiveUserMonthView(allCustomers, list);
                        list_d = NewUserMonthView(allCustomers, list_d);
    
                        return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet);
                    }
                    #endregion year
    
                    #region week view
    
                    else if (viewtypeid == 30)
                    {
                        list = ActiveUserWeekView(allCustomers, list);
                        list_d = NewUserWeekView(allCustomers, list_d);
    
                        return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet);
                    }
                    #endregion year
    
                    #region Date range
    
                    else if (viewtypeid == 0)
                    {
                        int startYear = startDate.Year;
                        int endYear = endDate.Year;
                        int startMonth = startDate.Month;
                        int endMonth = endDate.Month;
    
                        var customers = (from m in allCustomers
                                               where m.CreatedOnUtc >= startDate && m.CreatedOnUtc <= endDate
                                               orderby m.CreatedOnUtc.Month ascending
                                               select m).ToList();
    
                        //var allCustumer_ = (from m in allCustomers
                        //                         where m.CreatedOnUtc >= startDate && m.CreatedOnUtc <= endDate
                        //                         orderby m.CreatedOnUtc.Month ascending
                        //                         select m).ToList();
    
                        if (startMonth == endMonth && startYear == endYear) //Display weekly or day bases
                        {
                            double days = (endDate - startDate).TotalDays;
    
                            if (days < 10)
                            {
                                list = ActiveUserDateRangeDaysView(customers, list);
                                list_d = NewUserDateRangeDaysView(customers, list_d);
    
                              
                                return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet);
                            }
                            else
                            {
                                int diff = Convert.ToInt32(days / 7);
                                double mod = Convert.ToInt32(days % 7);
                                if (mod != 0 && mod < 4)
                                {
                                    diff = diff + 1;
                                }
    
                                list = ActiveUserDateRangeWeekView(startDate, list, ref customers, days, diff);
                                list_d = NewUserDateRangeWeekView(startDate, list_d, ref customers, days, diff);
    
                               
                                return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet);
                            }
                        }
                        else if (startYear == endYear) //Display monthly
                        {
                            list = ActiveUserDateRangeMonthView(list, existing, customers);
                            list_d = NewUserDateRangeMonthView(list_d, existing_d, customers); 
    
                            return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet);
                        }
                        else if (startYear < endYear) // Display yearly 
                        {
    
                            list   = ActiveUserDateRangeYearView(list, allCustomers, existing, customers);
                            list_d = NewUserDateRangeYearView(list_d, allCustomers, existing_d, customers);
    
                            return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet);
                        }
                    }
                    #endregion Date range
                }
                #endregion
    
                return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet);
            }
    
           
          
         
          
    
            #endregion
    
            #region Utilities
    
    
            private static List<HighChartModel> ProductDownloadedDateRangeWeekView(DateTime startDate, List<HighChartModel> list_d, List<AnalyticsAndReportsProduct> dateRangeRecord_d, int diff)
            {
                DateTime preWeeks_d = startDate;
                DateTime EndDate_d = preWeeks_d.AddDays(7).AddSeconds(-1);
                for (int i = 0; i < diff; i++)
                {
                    int c = (from q in dateRangeRecord_d
                             where q.CreatedOnUtc <= EndDate_d
                             select q).Count();
                    DateTime preEndDate = DateTime.Today;
                    preEndDate = EndDate_d;
                    EndDate_d = EndDate_d.AddDays(7);
    
                    dateRangeRecord_d = (from w in dateRangeRecord_d
                                         where w.CreatedOnUtc > preEndDate
                                         select w).ToList();
    
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(preEndDate.Date.AddDays(-6).ToString("ddMMM") + " To " + EndDate_d.Date.AddDays(-7).ToString("ddMMM"));
                    list_d.Add(r);
                }
    
                return list_d;
            }
    
            private static List<HighChartModel> ProductBrowseOrPublishDateRangeWeekView(DateTime startDate, List<HighChartModel> list, ref List<AnalyticsAndReportsProduct> dateRangeRecord, double days,int diff)
            {
                DateTime preWeeks = startDate;
                DateTime Today = DateTime.Today;
                DateTime StartDate = preWeeks;
                DateTime EndDate = preWeeks.AddDays(7).AddSeconds(-1);
    
    
              
                for (int i = 0; i < diff; i++)
                {
                    int c = (from q in dateRangeRecord
                             where q.CreatedOnUtc <= EndDate
                             select q).Count();
                    DateTime preEndDate = DateTime.Today;
                    preEndDate = EndDate;
                    EndDate = EndDate.AddDays(7);
    
                    dateRangeRecord = (from w in dateRangeRecord
                                       where w.CreatedOnUtc > preEndDate
                                       select w).ToList();
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(preEndDate.Date.AddDays(-6).ToString("ddMMM") + " To " + EndDate.Date.AddDays(-7).ToString("ddMMM"));
                    list.Add(r);
                }
                return list;
            }
    
            private static List<HighChartModel> ProductDownloadedDaysView(List<HighChartModel> list_d, List<int> existing_d, List<AnalyticsAndReportsProduct> dateRangeRecord_d)
            {
                foreach (var rc in dateRangeRecord_d)
                {
                    var day = rc.CreatedOnUtc.Day;
                    if (existing_d.Contains(day))
                        continue;
    
                    int c = (from q in dateRangeRecord_d
                             where q.CreatedOnUtc.Date == rc.CreatedOnUtc.Date
                             select q).Count();
    
                    existing_d.Add(day);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.Date.ToString("ddMMM"));
                    list_d.Add(r);
                }
                list_d = list_d.OrderBy(i => i.Value).ToList();
                return list_d;
            }
    
            private static List<HighChartModel> ProductBrowseOrPublishDateRangeDaysView(List<HighChartModel> list, List<int> existing, List<AnalyticsAndReportsProduct> dateRangeRecord)
            {
                foreach (var rc in dateRangeRecord)
                {
                    var day = rc.CreatedOnUtc.Day;
                    if (existing.Contains(day))
                        continue;
    
                    int c = (from q in dateRangeRecord
                             where q.CreatedOnUtc.Date == rc.CreatedOnUtc.Date
                             select q).Count();
    
                    existing.Add(day);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.Date.ToString("ddMMM"));
                    list.Add(r);
                }
                list = list.OrderBy(i => i.Value).ToList();
                return list;
            }
    
            private static List<HighChartModel> ProductDownloadedDateRangeMonthView(List<HighChartModel> list_d, List<int> existing_d, List<AnalyticsAndReportsProduct> dateRangeRecord_d)
            {
                var monthrecord_d = (from m in dateRangeRecord_d
                                     where m.CreatedOnUtc.Year == DateTime.UtcNow.Year
                                     orderby m.CreatedOnUtc.Month ascending
                                     select m).ToList();
    
                foreach (var rc in monthrecord_d)
                {
                    var month = rc.CreatedOnUtc.Month;
    
                    if (existing_d.Contains(month))
                        continue;
    
                    int c = (from q in monthrecord_d
                             where q.CreatedOnUtc.Month == month
                             select q.ProducId).Count();
                    existing_d.Add(month);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM"));
                    list_d.Add(r);
                }
                return list_d;
            }
    
            private static List<HighChartModel> ProductBrowseOrPublishDateRangeMonthView(List<HighChartModel> list, List<int> existing, List<AnalyticsAndReportsProduct> dateRangeRecord)
            {
                var monthrecord = (from m in dateRangeRecord
                                   where m.CreatedOnUtc.Year == DateTime.UtcNow.Year
                                   orderby m.CreatedOnUtc.Month ascending
                                   select m).ToList();
    
                foreach (var rc in monthrecord)
                {
                    var month = rc.CreatedOnUtc.Month;
    
                    if (existing.Contains(month))
                        continue;
    
                    int c = (from q in monthrecord
                             where q.CreatedOnUtc.Month == month
                             select q.ProducId).Count();
                    existing.Add(month);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM"));
                    list.Add(r);
    
                }
                return list;
            }
    
            private static List<HighChartModel> ProductDownloadedDateRangeYearView(List<HighChartModel> list_d, List<AnalyticsAndReportsProduct> record_d, List<int> existing_d, List<AnalyticsAndReportsProduct> dateRangeRecord_d)
            {
                foreach (var rc in dateRangeRecord_d)
                {
                    var year = rc.CreatedOnUtc.Year;
    
                    if (existing_d.Contains(year))
                        continue;
    
                    int c = (from q in record_d
                             where q.CreatedOnUtc.Year == year
                             select q.ProducId).Count();
                    existing_d.Add(year);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.Year);
                    list_d.Add(r);
                }
                list_d = list_d.OrderBy(i => i.Value).ToList();
                return list_d;
            }
    
            private static List<HighChartModel> ProductBrowseOrPublishDateRangeYearView(List<HighChartModel> list, List<AnalyticsAndReportsProduct> record, List<int> existing, List<AnalyticsAndReportsProduct> dateRangeRecord)
            {
                foreach (var rc in dateRangeRecord)
                {
                    var year = rc.CreatedOnUtc.Year;
    
                    if (existing.Contains(year))
                        continue;
    
                    int c = (from q in record
                             where q.CreatedOnUtc.Year == year
                             select q.ProducId).Count();
                    existing.Add(year);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.Year);
                    list.Add(r);
    
    
                }
                list = list.OrderBy(i => i.Value).ToList();
                return list;
            }
    
            private static List<HighChartModel> ProductDownloadedWeekView(List<HighChartModel> list_d, List<AnalyticsAndReportsProduct> record_d)
            {
                DateTime preWeeks_d = DateTime.Now.AddDays(-27);
    
                var weekrecord_d = (from m in record_d
                                    where m.CreatedOnUtc >= preWeeks_d && m.CreatedOnUtc <= DateTime.UtcNow
                                    orderby m.CreatedOnUtc.Month ascending
                                    select m).ToList();
    
                //DateTime EndDate_d = preWeeks_d.AddDays(7).AddSeconds(-1);
                DateTime EndDate_d = preWeeks_d.AddDays(7).AddSeconds(-1);
                //DateTime EndDate = preWeeks.AddDays(7);
                int addDays_d = 0;
    
    
                for (int i = 0; i < 4; i++)
                {
                    int c = (from q in weekrecord_d
                             where q.CreatedOnUtc <= EndDate_d
                             select q).Count();
                    DateTime preEndDate = DateTime.Today;
                    preEndDate = EndDate_d;
                    EndDate_d = EndDate_d.AddDays(7);
                    weekrecord_d = (from w in weekrecord_d
                                    where w.CreatedOnUtc >= preEndDate
                                    select w).ToList();
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(preEndDate.Date.AddDays(-7).ToString("ddMMM") + " To " + EndDate_d.Date.AddDays(-8).ToString("ddMMM"));
                    list_d.Add(r);
                }
                return list_d;
            }
    
            private static List<HighChartModel> ProductBrowseOrPublishWeekView(List<HighChartModel> list, List<AnalyticsAndReportsProduct> record)
            {
                DateTime preWeeks = DateTime.Now.AddDays(-27);
    
                var weekrecord = (from m in record
                                  where m.CreatedOnUtc >= preWeeks && m.CreatedOnUtc <= DateTime.UtcNow
                                  orderby m.CreatedOnUtc.Month ascending
                                  select m).ToList();
    
                DateTime Today = DateTime.Today;
                DateTime StartDate = preWeeks;
                //DateTime EndDate = preWeeks.AddDays(7).AddSeconds(-1);
                DateTime EndDate = preWeeks.AddDays(7).AddSeconds(-1);
                //DateTime EndDate = preWeeks.AddDays(7);
                int addDays = 0;
    
    
                for (int i = 0; i < 4; i++)
                {
                    int c = (from q in weekrecord
                             where q.CreatedOnUtc <= EndDate
                             select q).Count();
                    DateTime preEndDate = DateTime.Today;
                    preEndDate = EndDate;
                    EndDate = EndDate.AddDays(7);
                    weekrecord = (from w in weekrecord
                                  where w.CreatedOnUtc >= preEndDate
                                  select w).ToList();
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(preEndDate.Date.AddDays(-6).ToString("ddMMM") + " To " + EndDate.Date.AddDays(-7).ToString("ddMMM"));
                    list.Add(r);
                }
    
                return list;
            }
    
            private static List<HighChartModel> ProductDownloadedMonthView(List<HighChartModel> list_d, List<AnalyticsAndReportsProduct> record_d, List<int> existing_d)
            {
                var monthrecord_d = (from m in record_d
                                     where m.CreatedOnUtc.Year == DateTime.UtcNow.Year
                                     orderby m.CreatedOnUtc.Month ascending
                                     select m).ToList();
    
                foreach (var rc in monthrecord_d)
                {
                    var month = rc.CreatedOnUtc.Month;
    
                    if (existing_d.Contains(month))
                        continue;
    
                    int c = (from q in monthrecord_d
                             where q.CreatedOnUtc.Month == month
                             select q.ProducId).Count();
                    existing_d.Add(month);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM"));
                    list_d.Add(r);
                }
                return list_d;
            }
    
            private static List<HighChartModel> ProductBrowseOrPublishMonthView(List<HighChartModel> list, List<AnalyticsAndReportsProduct> record, List<int> existing)
            {
                var monthrecord = (from m in record
                                   where m.CreatedOnUtc.Year == DateTime.UtcNow.Year
                                   orderby m.CreatedOnUtc.Month ascending
                                   select m).ToList();
    
                foreach (var rc in monthrecord)
                {
                    var month = rc.CreatedOnUtc.Month;
    
                    if (existing.Contains(month))
                        continue;
    
                    int c = (from q in monthrecord
                             where q.CreatedOnUtc.Month == month
                             select q.ProducId).Count();
                    existing.Add(month);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM"));
                    list.Add(r);
                }
                return list;
            }
    
            private static List<HighChartModel> ProductDownloadedYearView(List<HighChartModel> list_d, List<AnalyticsAndReportsProduct> record_d, List<int> existing_d)
            {
                foreach (var rc in record_d)
                {
                    var year = rc.CreatedOnUtc.Year;
    
                    if (existing_d.Contains(year))
                        continue;
    
                    int c = (from q in record_d
                             where q.CreatedOnUtc.Year == year
                             select q.ProducId).Count();
                    existing_d.Add(year);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.Year);
                    list_d.Add(r);
    
    
                }
                list_d = list_d.OrderBy(i => i.Value).ToList();
                return list_d;
            }
    
            private static List<HighChartModel> ProductBrowseOrPublishYearView(List<HighChartModel> list, List<AnalyticsAndReportsProduct> record, List<int> existing)
            {
                foreach (var rc in record)
                {
                    var year = rc.CreatedOnUtc.Year;
    
                    if (existing.Contains(year))
                        continue;
    
                    int c = (from q in record
                             where q.CreatedOnUtc.Year == year
                             select q.ProducId).Count();
                    existing.Add(year);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.Year);
                    list.Add(r);
    
    
                }
                list = list.OrderBy(i => i.Value).ToList();
                return list;
            }
    
            private List<HighChartModel> AgeGroupBrowsedProduct(List<AnalyticsAndReportsProduct> record,List<HighChartModel> list)
            {
                List<int> existing = new List<int>();
    
                //List<int> cusId = new List<int>();
                int age;
                string ageGroup = null;
                var cusId = from x in record
                        group x.CustomerId by x.CustomerId into g
                        let count = g.Count()
                        select new { Value = g.Key, Count = count };
    
                list = prepareListValue(list);
                foreach (var rc in cusId)
                {
                  
                    var custInfo = _customerService.GetCustomerById(rc.Value);
    
                  
                   var dateOfBirth = custInfo.GetAttribute<DateTime?>(SystemCustomerAttributeNames.DateOfBirth);
                    if (dateOfBirth.HasValue)
                    {
                         age = DateTime.UtcNow.Year - dateOfBirth.Value.Year;
                         ageGroup = GetAgeGroup(age);
                     }
                    else
                    {
                        ageGroup = "UnKnown";
                    }
    
                    foreach (var item in list.Where(w => w.Value == ageGroup))
                    {
                        item.Item = Convert.ToInt32(rc.Count);
                    }
                }
                list = list.OrderBy(i => i.Value).ToList();
    
                return list;
            }
    
            private List<HighChartModel> AgeGroupDownloadedProduct(List<AnalyticsAndReportsProduct> record_d, List<HighChartModel> list_d)
            {
                List<int> existing = new List<int>();
    
                //List<int> cusId = new List<int>();
                int age;
                string ageGroup = null;
                var cusId = from x in record_d
                            group x.CustomerId by x.CustomerId into g
                            let count = g.Count()
                            select new { Value = g.Key, Count = count };
    
                list_d = prepareListValue(list_d);
                foreach (var rc in cusId)
                {
    
                    var custInfo = _customerService.GetCustomerById(rc.Value);
    
    
                    var dateOfBirth = custInfo.GetAttribute<DateTime?>(SystemCustomerAttributeNames.DateOfBirth);
                    if (dateOfBirth.HasValue)
                    {
                        age = DateTime.UtcNow.Year - dateOfBirth.Value.Year;
                        ageGroup = GetAgeGroup(age);
                    }
                    else
                    {
                        ageGroup = "UnKnown";
                    }
                    foreach (var item in list_d.Where(w => w.Value == ageGroup))
                    {
                        item.Item = Convert.ToInt32(rc.Count);
                    }
                }
                list_d = list_d.OrderBy(i => i.Value).ToList();
    
                return list_d;
            }
           
            private List<HighChartModel> prepareListValue(List<HighChartModel> list)
            {
                HighChartModel model=new HighChartModel();
    
                list.Add(new HighChartModel { Item = 0.0, Value = "00-08" });
                list.Add(new HighChartModel { Item = 0.0, Value = "09-16" });
                list.Add(new HighChartModel { Item = 0.0, Value = "17-24" });
                list.Add(new HighChartModel { Item = 0.0, Value = "25-32" });
                list.Add(new HighChartModel { Item = 0.0, Value = "33-40" });
                list.Add(new HighChartModel { Item = 0.0, Value = "41-48" });
                list.Add(new HighChartModel { Item = 0.0, Value = "49-56" });
                list.Add(new HighChartModel { Item = 0.0, Value = "57-64" });
                list.Add(new HighChartModel { Item = 0.0, Value = "65-100" });
                list.Add(new HighChartModel { Item = 0.0, Value = "UnKnown" });
                
                return list;
            }
    
            private string GetAgeGroup(int p)
            {
               
                if (p >= 0 && p <= 8)
                {
                    return "00-08";
                }
                else if (p >= 9 && p <= 16)
                {
                    return "09-16";
                }
                else if (p >= 17 && p <= 24)
                {
                    return "17-24";
                }
                else if (p >= 25 && p <= 32)
                {
                    return "25-32";
                }
                else if (p >= 33 && p <= 40)
                {
                    return "33-40";
                }
                else if (p >= 41 && p <= 48)
                {
                    return "41-48";
                }
                else if (p >= 49 && p <= 56)
                {
                    return "49-56";
                }
                else if (p >= 56 && p <= 64)
                {
                    return "57-64";
                }
                else
                {
                    return "65-100";
                }
                // string ageGroup;
               //switch (p)
               //{
               //    case 00-08:
               //        ageGroup = "00 - 08";
               //        break;
    
               //    case 09-16:
               //        ageGroup = "09 - 16";
               //        break;
    
               //    case 18-24:
               //        ageGroup = "17 - 24";
               //        break;
               //    case 25 - 32:
               //        ageGroup = "25 - 32";
               //        break;
               //    case 33 - 40:
               //        ageGroup = "33 - 40";
               //        break;
               //    case 41 - 48:
               //        ageGroup = "41 - 48";
               //        break;
               //    case 49 - 56:
               //        ageGroup = "49 - 56";
               //        break;
    
               //    case 57 - 64:
               //        ageGroup = "57 - 64";
               //        break;
    
               //    case 64 - 100:
               //        ageGroup = "64 - 100";
               //        break;
               //}
    
            }
    
            private static List<HighChartModel> CategorytBrowseDateRangeYearView(List<HighChartModel> list, List<AnalyticsAndReportsCategory> record, List<int> existing, List<AnalyticsAndReportsCategory> dateRangeRecord)
            {
                foreach (var rc in dateRangeRecord)
                {
                    var year = rc.CreatedOnUtc.Year;
    
                    if (existing.Contains(year))
                        continue;
    
                    int c = (from q in record
                             where q.CreatedOnUtc.Year == year
                             select q.CategoryId).Count();
                    existing.Add(year);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.Year);
                    list.Add(r);
    
    
                }
                list = list.OrderBy(i => i.Value).ToList();
                return list;
            }
    
            private static List<HighChartModel> CategorytBrowseDateRangeMonthView(List<HighChartModel> list, List<int> existing, List<AnalyticsAndReportsCategory> dateRangeRecord)
            {
                var monthrecord = (from m in dateRangeRecord
                                   where m.CreatedOnUtc.Year == DateTime.UtcNow.Year
                                   orderby m.CreatedOnUtc.Month ascending
                                   select m).ToList();
    
                foreach (var rc in monthrecord)
                {
                    var month = rc.CreatedOnUtc.Month;
    
                    if (existing.Contains(month))
                        continue;
    
                    int c = (from q in monthrecord
                             where q.CreatedOnUtc.Month == month
                             select q.CategoryId).Count();
                    existing.Add(month);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM"));
                    list.Add(r);
                }
                return list;
            }
    
            private static List<HighChartModel> CategorytBrowseDateRangeWeekView(DateTime startDate, List<HighChartModel> list, List<AnalyticsAndReportsCategory> dateRangeRecord, double days)
            {
                DateTime preWeeks = startDate;
    
                DateTime Today = DateTime.Today;
                DateTime StartDate = preWeeks;
                DateTime EndDate = preWeeks.AddDays(7).AddSeconds(-1);
    
                int diff = Convert.ToInt32(days / 7);
                double mod = Convert.ToInt32(days % 7);
                if (mod != 0 && mod < 4)
                {
                    diff = diff + 1;
                }
                for (int i = 0; i < diff; i++)
                {
                    int c = (from q in dateRangeRecord
                             where q.CreatedOnUtc.Date <= EndDate
                             select q).Count();
                    DateTime preEndDate = DateTime.Today;
                    preEndDate = EndDate;
                    EndDate = EndDate.AddDays(7);
    
                    dateRangeRecord = (from w in dateRangeRecord
                                       where w.CreatedOnUtc.Date > preEndDate.Date
                                       select w).ToList();
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(preEndDate.Date.AddDays(-6).ToString("ddMMM") + " To " + EndDate.Date.AddDays(-7).ToString("ddMMM"));
                    list.Add(r);
                }
                return list;
            }
    
            private static List<HighChartModel> CategorytBrowseDateRangeDaysView(List<HighChartModel> list, List<int> existing, List<AnalyticsAndReportsCategory> dateRangeRecord)
            {
    
                foreach (var rc in dateRangeRecord)
                {
                    var day = rc.CreatedOnUtc.Day;
                    if (existing.Contains(day))
                        continue;
    
                    int c = (from q in dateRangeRecord
                             // where q.CreatedOnUtc 
                             where q.CreatedOnUtc.Date == rc.CreatedOnUtc.Date
                             select q).Count();
    
                    existing.Add(day);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.Date.ToString("ddMMM"));
                    list.Add(r);
    
    
                }
                list = list.OrderBy(i => i.Value).ToList();
                return list;
            }
    
            private static List<HighChartModel> CategorytBrowseWeekView(List<HighChartModel> list, List<AnalyticsAndReportsCategory> record)
            {
                DateTime preWeeks = DateTime.Now.AddDays(-27);
    
                var weekrecord = (from m in record
                                  where m.CreatedOnUtc >= preWeeks && m.CreatedOnUtc <= DateTime.UtcNow
                                  orderby m.CreatedOnUtc.Month ascending
                                  select m).ToList();
    
                DateTime Today = DateTime.Today;
                DateTime StartDate = preWeeks;
                DateTime EndDate = preWeeks.AddDays(7).AddSeconds(-1);
    
                for (int i = 0; i < 4; i++)
                {
                    int c = (from q in weekrecord
                             // where q.CreatedOnUtc 
                             where q.CreatedOnUtc <= EndDate
                             select q).Count();
                    DateTime preEndDate = DateTime.Today;
                    preEndDate = EndDate;
                    EndDate = EndDate.AddDays(7);
                    //addDays = addDays + 7;
    
                    weekrecord = (from w in weekrecord
                                  where w.CreatedOnUtc >= preEndDate
                                  select w).ToList();
                    // existing.Add(month);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(preEndDate.Date.AddDays(-6).ToString("ddMMM") + " To " + EndDate.Date.AddDays(-7).ToString("ddMMM"));
                    list.Add(r);
                }
                return list;
            }
    
            private static List<HighChartModel> CategorytBrowseMonthView(List<HighChartModel> list, List<AnalyticsAndReportsCategory> record, List<int> existing)
            {
                var monthrecord = (from m in record
                                   where m.CreatedOnUtc.Year == DateTime.UtcNow.Year
                                   orderby m.CreatedOnUtc.Month ascending
                                   select m).ToList();
    
                foreach (var rc in monthrecord)
                {
                    var month = rc.CreatedOnUtc.Month;
    
                    if (existing.Contains(month))
                        continue;
    
                    int c = (from q in monthrecord
                             where q.CreatedOnUtc.Month == month
                             select q.CategoryId).Count();
                    existing.Add(month);
                    //monthrecord = (from m in monthrecord where rc.CreatedOnUtc.Month != month select m).ToList();
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM"));
                    list.Add(r);
                }
                return list;
            }
    
            private static List<HighChartModel> CategoryBrowseYearView(List<HighChartModel> list, List<AnalyticsAndReportsCategory> record, List<int> existing)
            {
                foreach (var rc in record)
                {
                    var year = rc.CreatedOnUtc.Year;
    
                    if (existing.Contains(year))
                        continue;
    
                    int c = (from q in record
                             where q.CreatedOnUtc.Year == year
                             select q.CategoryId).Count();
                    existing.Add(year);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.Year);
                    list.Add(r);
    
    
                }
                list = list.OrderBy(i => i.Value).ToList();
                return list;
            }
    
            private List<HighChartModel> ProductDownloadedByCountry(List<AnalyticsAndReportsProduct> record_d, List<HighChartModel> list_d)
            {
                List<int> existing = new List<int>();
                var cusId = (from x in record_d
                            group x.CustomerId by x.CustomerId into g
                            let count = g.Count()
                             select new 
                             { Value = g.Key,
                               Count = count
                             }).OrderByDescending(c=>c.Count).Take(20);
    
                foreach (var rc in cusId)
                {
                    HighChartModel model = new HighChartModel();
                    string country =null;
                    var custInfo = _customerService.GetCustomerById(rc.Value);
    
                    if (custInfo != null && custInfo.BillingAddress != null && custInfo.BillingAddress.Country != null && custInfo.BillingAddress.Country.Name !=null)
                     country =  custInfo.BillingAddress.Country.Name;
                
                   
                    if (!string.IsNullOrEmpty(country))
                    {
                        var exist = list_d.Where(w => w.Value == country).FirstOrDefault();
                        if (exist == null)
                        {
                            model.Item = rc.Count;
                            model.Value = country;
                            list_d.Add(model);
                        }
                        else
                        {
                            exist.Item += rc.Count;
                        }
                      
                    }
                    else
                    {
                        var exist = list_d.Where(w => w.Value == country).FirstOrDefault();
                        if (exist == null)
                        {
                            model.Item = rc.Count;
                            model.Value = "UnKnown";
                            list_d.Add(model);
                        }
                        else
                        {
                            exist.Item += rc.Count;
                        }
                    }
                }
                list_d = list_d.OrderBy(i => i.Value).ToList();
    
                return list_d;
            }
    
            private List<HighChartModel> UserDemographicsView(List<Customer> allCustomers, List<HighChartModel> list)
            {
                List<int> existing = new List<int>();
    
                int age;
                string ageGroup = null;
    
                list = prepareListValue(list);
                foreach (var rc in allCustomers)
                {
    
                    var custInfo = _customerService.GetCustomerById(rc.Id);
    
    
                    var dateOfBirth = custInfo.GetAttribute<DateTime?>(SystemCustomerAttributeNames.DateOfBirth);
                    if (dateOfBirth.HasValue)
                    {
                        age = DateTime.UtcNow.Year - dateOfBirth.Value.Year;
                        ageGroup = GetAgeGroup(age);
                    }
                    else
                    {
                        ageGroup = "UnKnown";
                    }
    
                    foreach (var item in list.Where(w => w.Value == ageGroup))
                    {
                        item.Item =item.Item+1;
                    }
                }
                list = list.OrderBy(i => i.Value).ToList();
    
                return list;
            }
    
            private List<HighChartModel> ActiveUserYearView(List<Customer> allCustomers ,List<HighChartModel> list)
            {
                List<int> existing = new List<int>();
                allCustomers = (from c in allCustomers
                                where c.Active
                                select c).ToList();
    
                foreach (var rc in allCustomers)
                {
                    var year = Convert.ToString(rc.CreatedOnUtc.Year);
    
                    var exist = list.Where(w => w.Value == year).FirstOrDefault();
                    if (exist == null)
                    {
                        HighChartModel r = new HighChartModel();
                        r.Item = 1;
                        r.Value = Convert.ToString(rc.CreatedOnUtc.Year);
    
                        list.Add(r);
                    }
                    else
                    {
                        exist.Item++;
                    }
    
                }
                list = list.OrderBy(i => i.Value).ToList();
    
                list = ActivePrapareList(list);
    
    
                return list;
    
            }
    
            private List<HighChartModel> NewUserYearView(List<Customer> allCustomers, List<HighChartModel> list_d)
            {
                List<int> existing = new List<int>();
    
                foreach (var rc in allCustomers)
                {
                    var year = Convert.ToString(rc.CreatedOnUtc.Year);
    
                    var exist = list_d.Where(w => w.Value == year).FirstOrDefault();
                    if (exist == null)
                    {
                        HighChartModel r = new HighChartModel();
                        r.Item = 1;
                        r.Value = Convert.ToString(rc.CreatedOnUtc.Year);
    
                        list_d.Add(r);
                    }
                    else
                    {
                        exist.Item++;
                    }
    
                }
                list_d = list_d.OrderBy(i => i.Value).ToList();
    
                return list_d;
            }
    
            private List<HighChartModel> ActiveUserMonthView(List<Customer> allCustomers, List<HighChartModel> list)
            {
                List<int> existing = new List<int>();
    
                int currentYear = DateTime.UtcNow.Year;
    
                allCustomers = (from c in allCustomers
                                where c.CreatedOnUtc.Year == currentYear && c.Active
                                orderby c.CreatedOnUtc.Month ascending
                                select c).ToList();
    
                foreach (var rc in allCustomers)
                {
                    var month = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM"));
    
                    var exist = list.Where(w => w.Value == month).FirstOrDefault();
                    if (exist == null)
                    {
                        HighChartModel r = new HighChartModel();
                        r.Item = 1;
                        r.Value = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM"));
    
                        list.Add(r);
                    }
                    else
                    {
                        exist.Item++;
                    }
    
                }
    
                list = ActivePrapareList(list);
    
                return list;
            }
    
            private List<HighChartModel> NewUserMonthView(List<Customer> allCustomers, List<HighChartModel> list_d)
            {
                List<int> existing = new List<int>();
    
                int currentYear = DateTime.UtcNow.Year;
    
                allCustomers = (from c in allCustomers
                                where c.CreatedOnUtc.Year == currentYear && c.Active
                                orderby c.CreatedOnUtc.Month ascending
                                select c).ToList();
    
                foreach (var rc in allCustomers)
                {
                    var month = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM"));
    
                    var exist = list_d.Where(w => w.Value == month).FirstOrDefault();
                    if (exist == null)
                    {
                        HighChartModel r = new HighChartModel();
                        r.Item = 1;
                        r.Value = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM"));
    
                        list_d.Add(r);
                    }
                    else
                    {
                        exist.Item++;
                    }
    
                }
                return list_d;
            }
    
            private List<HighChartModel> ActiveUserWeekView(List<Customer> allCustomers, List<HighChartModel> list)
            {
                DateTime preWeeks = DateTime.Now.AddDays(-27);
    
                  allCustomers = (from m in allCustomers
                                  where m.CreatedOnUtc >= preWeeks && m.CreatedOnUtc <= DateTime.UtcNow
                                  orderby m.CreatedOnUtc.Month ascending
                                  select m).ToList();
                DateTime Today = DateTime.Today;
                DateTime StartDate = preWeeks;
                DateTime EndDate = preWeeks.AddDays(7).AddSeconds(-1);
    
                for (int i = 0; i < 4; i++)
                {
                    int c = (from q in allCustomers
                             where q.CreatedOnUtc <= EndDate
                             select q).Count();
                    DateTime preEndDate = DateTime.Today;
                    preEndDate = EndDate;
                    EndDate = EndDate.AddDays(7);
                    //addDays = addDays + 7;
    
                    allCustomers = (from w in allCustomers
                                  where w.CreatedOnUtc >= preEndDate
                                  select w).ToList();
                    // existing.Add(month);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(preEndDate.Date.AddDays(-6).ToString("ddMMM") + " To " + EndDate.Date.AddDays(-7).ToString("ddMMM"));
                    list.Add(r);
                }
               list =  ActivePrapareList(list);
                return list;
            }
    
            private static List<HighChartModel> ActivePrapareList(List<HighChartModel> list)
            {
                string cValue = null;
                int counter = 0;
    
                foreach (var l in list)
                {
                    string pValue = cValue;
                    cValue = l.Value;
    
                    if (counter > 0)
                    {
                        double prevItem = (from p in list
                                           where p.Value == pValue
                                           select p.Item).FirstOrDefault();
    
                        l.Item = l.Item + prevItem;
                    }
                    counter++;
                }
                return list;
            }
    
            private List<HighChartModel> NewUserWeekView(List<Customer> allCustomers, List<HighChartModel> list_d)
            {
                DateTime preWeeks = DateTime.Now.AddDays(-27);
    
                allCustomers = (from m in allCustomers
                                where m.CreatedOnUtc >= preWeeks && m.CreatedOnUtc <= DateTime.UtcNow
                                orderby m.CreatedOnUtc.Month ascending
                                select m).ToList();
                DateTime Today = DateTime.Today;
                DateTime StartDate = preWeeks;
                DateTime EndDate = preWeeks.AddDays(7).AddSeconds(-1);
    
                for (int i = 0; i < 4; i++)
                {
                    int c = (from q in allCustomers
                             where q.CreatedOnUtc <= EndDate
                             select q).Count();
                    DateTime preEndDate = DateTime.Today;
                    preEndDate = EndDate;
                    EndDate = EndDate.AddDays(7);
                    //addDays = addDays + 7;
    
                    allCustomers = (from w in allCustomers
                                    where w.CreatedOnUtc >= preEndDate
                                    select w).ToList();
                    // existing.Add(month);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(preEndDate.Date.AddDays(-6).ToString("ddMMM") + " To " + EndDate.Date.AddDays(-7).ToString("ddMMM"));
                    list_d.Add(r);
                }
                string cValue = null;
                int counter = 0;
    
                return list_d;
            }
    
            private List<HighChartModel> ActiveUserDateRangeDaysView(List<Customer> allCustomers, List<HighChartModel> list)
            {
    
                List<int> existing = new List<int>();
                foreach (var rc in allCustomers)
                {
                    var day = rc.CreatedOnUtc.Day;
                    if (existing.Contains(day))
                        continue;
    
                    int c = (from q in allCustomers
                             // where q.CreatedOnUtc 
                             where q.CreatedOnUtc.Date == rc.CreatedOnUtc.Date
                             select q).Count();
    
                    existing.Add(day);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.Date.ToString("ddMMM"));
                    list.Add(r);
    
    
                }
                list = list.OrderBy(i => i.Value).ToList();
                list = ActivePrapareList(list);
                return list;
            }
    
            private List<HighChartModel> NewUserDateRangeDaysView(List<Customer> allCustomers, List<HighChartModel> list_d)
            {
                List<int> existing = new List<int>();
                foreach (var rc in allCustomers)
                {
                    var day = rc.CreatedOnUtc.Day;
                    if (existing.Contains(day))
                        continue;
    
                    int c = (from q in allCustomers
                             // where q.CreatedOnUtc 
                             where q.CreatedOnUtc.Date == rc.CreatedOnUtc.Date
                             select q).Count();
    
                    existing.Add(day);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.Date.ToString("ddMMM"));
                    list_d.Add(r);
    
    
                }
                list_d = list_d.OrderBy(i => i.Value).ToList();
    
                return list_d;
            }
    
            private static List<HighChartModel> ActiveUserDateRangeWeekView(DateTime startDate, List<HighChartModel> list, ref List<Customer> allCustomer, double days, int diff)
            {
                DateTime preWeeks = startDate;
                DateTime Today = DateTime.Today;
                DateTime StartDate = preWeeks;
                DateTime EndDate = preWeeks.AddDays(7).AddSeconds(-1);
    
    
    
                for (int i = 0; i < diff; i++)
                {
                    int c = (from q in allCustomer
                             where q.CreatedOnUtc <= EndDate
                             select q).Count();
                    DateTime preEndDate = DateTime.Today;
                    preEndDate = EndDate;
                    EndDate = EndDate.AddDays(7);
    
                    allCustomer = (from w in allCustomer
                                       where w.CreatedOnUtc > preEndDate
                                       select w).ToList();
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(preEndDate.Date.AddDays(-6).ToString("ddMMM") + " To " + EndDate.Date.AddDays(-7).ToString("ddMMM"));
                    list.Add(r);
                }
                list = ActivePrapareList(list);
                return list;
            }
    
            private static List<HighChartModel> NewUserDateRangeWeekView(DateTime startDate, List<HighChartModel> list_d, ref List<Customer> allCustomer, double days, int diff)
            {
                DateTime preWeeks = startDate;
                DateTime Today = DateTime.Today;
                DateTime StartDate = preWeeks;
                DateTime EndDate = preWeeks.AddDays(7).AddSeconds(-1);
    
    
    
                for (int i = 0; i < diff; i++)
                {
                    int c = (from q in allCustomer
                             where q.CreatedOnUtc <= EndDate
                             select q).Count();
                    DateTime preEndDate = DateTime.Today;
                    preEndDate = EndDate;
                    EndDate = EndDate.AddDays(7);
    
                    allCustomer = (from w in allCustomer
                                   where w.CreatedOnUtc > preEndDate
                                   select w).ToList();
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(preEndDate.Date.AddDays(-6).ToString("ddMMM") + " To " + EndDate.Date.AddDays(-7).ToString("ddMMM"));
                    list_d.Add(r);
                }
                return list_d;
            }
    
            private List<HighChartModel> ActiveUserDateRangeMonthView(List<HighChartModel> list, List<int> existing, List<Customer> allCustomers)
            {
                allCustomers = (from m in allCustomers
                                     where m.CreatedOnUtc.Year == DateTime.UtcNow.Year
                                     orderby m.CreatedOnUtc.Month ascending
                                     select m).ToList();
    
                foreach (var rc in allCustomers)
                {
                    var month = rc.CreatedOnUtc.Month;
    
                    if (existing.Contains(month))
                        continue;
    
                    int c = (from q in allCustomers
                             where q.CreatedOnUtc.Month == month
                             select q).Count();
    
                    existing.Add(month);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM"));
                    list.Add(r);
                }
    
                list = ActivePrapareList(list);
    
                return list; 
            }
    
            private List<HighChartModel> NewUserDateRangeMonthView(List<HighChartModel> list_d, List<int> existing_d, List<Customer> allCustomers)
            {
                allCustomers = (from m in allCustomers
                                where m.CreatedOnUtc.Year == DateTime.UtcNow.Year
                                orderby m.CreatedOnUtc.Month ascending
                                select m).ToList();
    
                foreach (var rc in allCustomers)
                {
                    var month = rc.CreatedOnUtc.Month;
    
                    if (existing_d.Contains(month))
                        continue;
    
                    int c = (from q in allCustomers
                             where q.CreatedOnUtc.Month == month
                             select q).Count();
    
                    existing_d.Add(month);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM"));
                    list_d.Add(r);
                }
    
                return list_d; 
            }
    
            private List<HighChartModel> ActiveUserDateRangeYearView(List<HighChartModel> list, List<Customer> allCustomers, List<int> existing, List<Customer> customers)
            {
                foreach (var rc in customers)
                {
                    var year = rc.CreatedOnUtc.Year;
    
                    if (existing.Contains(year))
                        continue;
    
                    int c = (from q in allCustomers
                             where q.CreatedOnUtc.Year == year
                             select q).Count();
                    existing.Add(year);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.Year);
                    list.Add(r);
                }
                list = list.OrderBy(i => i.Value).ToList();
    
                list = ActivePrapareList(list);
    
                return list;
            }
    
            private List<HighChartModel> NewUserDateRangeYearView(List<HighChartModel> list_d, List<Customer> allCustomers, List<int> existing_d, List<Customer> customers)
            {
                foreach (var rc in customers)
                {
                    var year = rc.CreatedOnUtc.Year;
    
                    if (existing_d.Contains(year))
                        continue;
    
                    int c = (from q in allCustomers
                             where q.CreatedOnUtc.Year == year
                             select q).Count();
                    existing_d.Add(year);
                    HighChartModel r = new HighChartModel();
                    r.Item = Convert.ToDouble(c);
                    r.Value = Convert.ToString(rc.CreatedOnUtc.Year);
                    list_d.Add(r);
                }
                list_d = list_d.OrderBy(i => i.Value).ToList();
    
                return list_d;
            }
            #endregion
    
        }
    }
    
    ****************************************************************************************************************
    [HighChart.cshtml]
    
    @model Nop.Plugin.OneRead.AnalyticsAndReports.Models.DateTimeModel
    @Html.ValidationSummary(false)
    @using Nop.Web.Framework.Events;
    @using Nop.Core.Infrastructure;
    @using Nop.Services.Events;
    @using Nop.Web.Framework.ViewEngines.Razor;
    @{
        Layout = "/Administration/Views/Shared/_AdminLayout.cshtml";
        Html.AppendCssFileParts("~/Content/kendo/2014.1.318/kendo.common.min.css");
        Html.AppendCssFileParts("~/Content/kendo/2014.1.318/kendo.default.min.css");
        Html.AppendScriptParts("~/Scripts/kendo/2014.1.318/kendo.web.min.js");
      
        Html.AppendScriptParts("~/Scripts/chart/Chart.bundle.js"); // chart library
       
        <!--calender-->
        <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    }
    
    @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "product-form" }))
    {
        <script>
            $(document).ready(function () {
                $("#product-edit").kendoTabStrip({
                    animation: {
                        open: {
                            effects: "fadeIn"
                        }
                    },
                    select: tabstrip_on_tab_select
                });
            });
        </script>
    
        <div class="section-header">
            <div class="title">
                <img src="@Url.Content("~/Administration/Content/images/ico-catalog.png")" alt="" />
                Analytics and Reports
            </div>
        </div>
    
    
        <div id="product-edit">
            <ul>
                <li @Html.RenderSelectedTabIndex(0, GetSelectedTabIndex())>
                    Product
                </li>
                <li @Html.RenderSelectedTabIndex(1, GetSelectedTabIndex())>
                    Category
                </li>
                <li @Html.RenderSelectedTabIndex(2, GetSelectedTabIndex())>
                    Customer
                </li>
            </ul>
            <div>
                @TabProduct()
            </div>
            <div>
                @TabCategory()
            </div>
            <div>
                @TabCustomer()
            </div>
        </div>
    
      @helper TabProduct()
        {
            @Html.Partial("_ProductLineChart")
        }
            @helper TabCategory()
        {
            @Html.Partial("_CategoryLineChart")
        }
            @helper TabCustomer()
        {
            @Html.Partial("_CustomerLineChart")
        }
    }
    
    ***************************************************************************************************************************
    [_productChart.cshtml]
    
    
    <style>
        .timeButton {
            background-color: #00c0ef;
            border-color: #00acd6;
            color: white;
        }
    
        .activecolor {
            background-color: #3c8dbc !important;
        }
    
        .selectchart {
            width: 20%;
            float: right;
            height: 30px;
            background-color: #00c0ef;
            color: white;
            margin-top: -2%;
        }
    </style>
    
    <input type="button" id="browsedview" value="Product Browsed by Time" class="timeButton" />
    <input type="button" id="publishedview" value="Product Published by Time" class="timeButton" />
    <input type="button" id="usergroupview" value="Product Uses By Age Group" class="timeButton" />
    <input type="button" id="downloadedbycountryview" value="Product download by Country" class="timeButton" />
    
    
    
    
    <div style="margin: 0 auto; width: 400px;">
        <input type="button" id="yearview" value="Year View" class="timeButton">
        <input type="button" id="monthview" value="Month View" class="timeButton" />
        <input type="button" id="weekview" value="Week View" class="timeButton" />
        <input type="button" id="dateview" value="View by date" class="timeButton" />
        
    
        <div id="datepicker" style="display:none">
            StartDate: <input type="text" id="sdatepicker">
            EndDate: <input type="text" id="edatepicker">
        </div>
        <input id="datepickerbtn" style="display:none" type="button" value="View" class="timeButton" />
    </div>
    
    <select name="selector" class="selectchart">
        <option value=" 1">Line Chart</option>
        <option value="2">Bar Chart</option>
    </select>
    
    <div id="graph-container" style="width:500px;height:500px;margin: auto;">
        <canvas id="browsedDownloadedChart"></canvas>
    </div>
    @*<div id="container" style="min-width: 350px; height: 350px; max-width: 600px; margin: 0 auto"></div>*@
    
    <script type="text/javascript">
        $(document).ready(function () {
    
            $("#datepicker").hide();
            $("#datepickerbtn").hide();
            var actiontypeId = 10;
            var viewtypevalue = 10;
            var startDate = '01-01-1980';
            var endDate = '01-01-1980';
            // On chart type change
            $('select[name=selector]').change(function () {
                addclass(viewtypevalue);
                addclassOnAction(actiontypeId);
                AjaxMethod(viewtypevalue, startDate, endDate, actiontypeId)
            });
            //call function on load
            addclass(viewtypevalue);
            addclassOnAction(actiontypeId);
            AjaxMethod(viewtypevalue, startDate, endDate, actiontypeId)
            $('#yearview, #monthview, #weekview, #datepickerbtn, #browsedview , #publishedview, #usergroupview,#downloadedbycountryview').click(function () {
                var viewtype = $(this).val();
    
                if (viewtype.trim().toUpperCase() == 'YEAR VIEW') {
                    viewtypevalue = 10;
                    addclass(viewtypevalue);
                    $("#datepicker,#datepickerbtn").hide();
                }
                else if (viewtype.trim().toUpperCase() == 'MONTH VIEW') {
                    viewtypevalue = 20;
                    addclass(viewtypevalue);
                    $("#datepicker,#datepickerbtn").hide();
                }
                else if (viewtype.trim().toUpperCase() == 'WEEK VIEW') {
                    viewtypevalue = 30;
                    addclass(viewtypevalue);
                    $("#datepicker,#datepickerbtn").hide();
    
                }
                else {
                    viewtypevalue = 0;
    
                }
    
                if (viewtype.trim().toUpperCase() == 'PRODUCT BROWSED BY TIME') {
                    viewtypevalue = 10;
                    actiontypeId = 10;
                    addclass(viewtypevalue);
                    addclassOnAction(actiontypeId);
                    $("#datepicker,#datepickerbtn").hide();
                    $("#yearview,#monthview,#weekview,#dateview").show();
                }
                else if (viewtype.trim().toUpperCase() == 'PRODUCT PUBLISHED BY TIME') {
                    viewtypevalue = 10;
                    actiontypeId = 30;
                    addclass(viewtypevalue);
                    addclassOnAction(actiontypeId);
                    $("#datepicker,#datepickerbtn").hide();
                    $("#yearview,#monthview,#weekview,#dateview").show();
                }
                else if (viewtype.trim().toUpperCase() == 'VIEW') {
                    if ($("#sdatepicker").val()) {
                        startDate = $("#sdatepicker").val();
                    }
                    if ($("#edatepicker").val()) {
                        endDate = $("#edatepicker").val();
                    }
                    if (startDate == '01-01-1980' || endDate == '01-01-1980') {
    
                        if (startDate == '01-01-1980' && endDate == '01-01-1980') {
                            $("<div>" + "Select start date and end date." + "</div>").dialog({
                                title: 'OneRead',
                                height: 70,
                                width: 350,
                                modal: true,
                                resizable: true
                            });
                            return false;
                        }
    
                        else if (startDate == '01-01-1980') {
                            $("<div>" + "Select start date." + "</div>").dialog({
                                title: 'OneRead',
                                height: 70,
                                width: 350,
                                modal: true,
                                resizable: true
                            });
                            return false;
                        }
                        else if (endDate == '01-01-1980') {
                            $("<div>" + "Select end date." + "</div>").dialog({
                                title: 'OneRead',
                                height: 70,
                                width: 350,
                                modal: true,
                                resizable: true
                            });
                            return false;
                        }
                    }
                    else if ((new Date(startDate).getTime() >= new Date(endDate).getTime())) {
                        $("<div class='dialogbox'>" + "Start date must be less than end date." + "</div>").dialog({
                            title:'OneRead',
                            height: 70,
                            width: 350,
                            modal: true,
                            resizable: true
                        });
                        return false;
                    }
                }
                else if (viewtype.trim().toUpperCase() == 'PRODUCT USES BY AGE GROUP') {
                    viewtypevalue = 40;
                    actiontypeId = 40;
                    addclass(viewtypevalue);
                    addclassOnAction(actiontypeId);
                    $("#datepicker,#datepickerbtn,#yearview,#monthview,#weekview,#dateview").hide();
                }
                else if (viewtype.trim().toUpperCase() == 'PRODUCT DOWNLOAD BY COUNTRY') {
                    viewtypevalue = 50;
                    actiontypeId = 50;
                    addclass(viewtypevalue);
                    addclassOnAction(actiontypeId);
                    $("#datepicker,#datepickerbtn,#yearview,#monthview,#weekview,#dateview").hide();
                }
            
                AjaxMethod(viewtypevalue, startDate, endDate, actiontypeId);
            });
        });
    
        function AjaxMethod(viewtypevalue, startDate, endDate, actiontypeId)
        {
            $.ajax({
                url: '@Html.Raw(Url.Action("DisplayChart", "AnalyticsAndReports"))',
                data: { "viewtypeid": viewtypevalue, "startDate": startDate, "endDate": endDate, "actionType": actiontypeId },
                dataType: "json",
                type: "GET",
                contentType: 'application/json; charset=utf-8',
                async: false,
                processData: true,
                cache: false,
                delay: 15,
                success: function (responseData) {
    
                    var BrowseSeriesValue = new Array();
                    var BrowseSeriesItem = new Array();
                    for (var i in responseData.list) {
                        var serieItm = new Array((responseData.list[i].Item).toString());
                        var serieValue = new Array(responseData.list[i].Value);
    
                        BrowseSeriesItem.push(parseInt(serieItm));
                        BrowseSeriesValue.push(serieValue);
                    }
    
                    var DownloadedSeriesValue = new Array();
                    var DownloadedSeriesItem = new Array();
                    for (var i in responseData.list_d) {
                        var serieValue = new Array(responseData.list_d[i].Value);
                        var serieItem = new Array(responseData.list_d[i].Item.toString());
    
                        DownloadedSeriesItem.push(parseInt(serieItem));
                        DownloadedSeriesValue.push(serieValue);
    
                    }
    
                    DrawLineChart(BrowseSeriesValue, BrowseSeriesItem, DownloadedSeriesValue, DownloadedSeriesItem, viewtypevalue, actiontypeId);
                },
                error: function (xhr) {
                    alert('error');
                }
            });
        }
    
        function DrawLineChart(BrowseSeriesValue, BrowseSeriesItem, DownloadedSeriesValue, DownloadedSeriesItem, viewtypevalue, actiontypeId) {
    
           
            $('#browsedDownloadedChart').remove(); // this is <canvas> element 
            $('#graph-container').append('<canvas id="browsedDownloadedChart"><canvas>'); //remove canvas than add again becose of clear old chart issue.
    
            var ctx = document.getElementById("browsedDownloadedChart");
            var chartTypeId = $('select[name=selector]').val();
            var CType = 'line';
            var label = BrowseSeriesValue;
           
            
            if (BrowseSeriesValue == '')
            {
                label = DownloadedSeriesValue;
            }
    
            if (chartTypeId == 1)
                CType = 'line';
    
            else if (chartTypeId == 2)
                CType = 'bar';
    
            var label1 = 'Browsed';
            var label2 = 'Downloaded';
            if (actiontypeId == 30) {
                label1 = 'Published';
                label2 = '';
            }
            if (actiontypeId == 50) {
                label1 = '';
                var label2 = 'Downloaded';
            }
            var browsedDownloadedChart = new Chart(ctx, {
    
                type: CType,
                data: {
                   
                    labels: label,
                    datasets: [
                        {
                            fillColor: "rgba(60,141,188,0.9)",
                            strokeColor: "rgba(60,141,188,0.8)",
                            label: label1,
                            pointColor: "#3b8bba",
                            pointStrokeColor: "rgba(60,141,188,1)",
                            pointHighlightFill: "#fff",
                            pointHighlightStroke: "rgba(60,141,188,1)",
                            borderColor: 'rgba(60, 141, 188, 0.7)',
                            backgroundColor: 'rgba(44, 152, 214, 0.5)',
                            pointBorderColor: 'rgba(37, 103, 142, 0.9)',
                            pointBackgroundColor: 'rgba(60, 141, 188, 0.4)',
                            pointBorderWidth: 1,
                            data: BrowseSeriesItem,
                        },
                        {
                            label: label2,
                            fillColor: "rgba(60,141,188,0.9)",
                            strokeColor: "rgba(60,141,188,0.8)",
                            pointColor: "#00a65a",
                            pointStrokeColor: "rgba(0,166,90,1)",
                            pointHighlightFill: "#fff",
                            pointHighlightStroke: "rgba(0,166,90,1)",
                            borderColor: 'rgba(0,166,90, 1)',
                            backgroundColor: 'rgba(0,166,90,0.5)',
                            pointBorderColor: 'rgba(0,166,90,0.7)',
                            pointBackgroundColor: 'rgba(0,166,90,0.2)',
                            pointBorderWidth: 1,
                            data: DownloadedSeriesItem,
    
                        }
                    ]
                },
                responsive: true,
    
                options: {
                    scales: {
                        yAxes: [{
                            ticks: {
                                beginAtZero: true
                            }
                        }]
                    },
                    scaleShowLabels: false
    
                }
            });
        }
    
        $(function () {
            $("#sdatepicker").datepicker({
                changeMonth: true,
                changeYear: true
            });
            $("#edatepicker").datepicker({
                changeMonth: true,
                changeYear: true
            });
        });
        $('#dateview').click(function () {
            $("#datepicker,#datepickerbtn").show();
            addclass(0);
        });
        function addclass(viewtypevalue) {
            if (viewtypevalue == 10) {
                $("#yearview").addClass("activecolor");
                $("#monthview").removeClass("activecolor");
                $("#weekview").removeClass("activecolor");
                $("#dateview").removeClass("activecolor");
            }
            else if (viewtypevalue == 20) {
                $("#monthview").addClass("activecolor");
                $("#yearview").removeClass("activecolor");
                $("#weekview").removeClass("activecolor");
                $("#dateview").removeClass("activecolor");
            }
            else if (viewtypevalue == 30) {
                $("#weekview").addClass("activecolor");
                $("#monthview").removeClass("activecolor");
                $("#yearview").removeClass("activecolor");
                $("#dateview").removeClass("activecolor");
            }
            else if (viewtypevalue == 0) {
                $("#dateview").addClass("activecolor");
                $("#monthview").removeClass("activecolor");
                $("#weekview").removeClass("activecolor");
                $("#yearview").removeClass("activecolor");
            }
        }
        function addclassOnAction(actiontypeId) {
            if (actiontypeId == 10) {
                $("#browsedview").addClass("activecolor");
                $("#publishedview").removeClass("activecolor");
                $("#usergroupview").removeClass("activecolor");
                $("#downloadedbycountryview").removeClass("activecolor");
              
            }
            else if (actiontypeId == 30) {
                $("#publishedview").addClass("activecolor");
                $("#browsedview").removeClass("activecolor");
                $("#usergroupview").removeClass("activecolor");
                $("#downloadedbycountryview").removeClass("activecolor");
              
            }
            else if (actiontypeId == 40) {
                $("#usergroupview").addClass("activecolor");
                $("#browsedview").removeClass("activecolor");
                $("#publishedview").removeClass("activecolor");
                $("#downloadedbycountryview").removeClass("activecolor");
               
            }
            else if (actiontypeId == 50) {
                $("#downloadedbycountryview").addClass("activecolor");
                $("#browsedview").removeClass("activecolor");
                $("#publishedview").removeClass("activecolor");
                $("#usergroupview").removeClass("activecolor");
             
            }
          
        }
    </script>
    **********************************************************************************************
    [_categoryChart.cshtml]
    
    
    <style>
        .timeButton {
            background-color: #00c0ef;
            border-color: #00acd6;
            color: white;
        }
    </style>
    <div style="margin: 0 auto; width: 400px;">
        <input type="button" id="cyearview" value="Year View" class="timeButton" />
        <input type="button" id="cmonthview" value="Month View" class="timeButton" />
        <input type="button" id="cweekview" value="Week View" class="timeButton" />
        <input type="button" id="cdateview" value="View by date" class="timeButton" />
        <div id="catdatepicker" style="display:none">StartDate: <input type="text" id="catsdatepicker"> EndDate: <input type="text" id="catedatepicker"></div>
        <input id="catdatepickerbtn" style="display:none" type="button" value="View" class="timeButton" />
    </div>
    <select name="selectorPublished" class="selectchart">
        <option value="1">Line Chart</option>
        <option value="2">Bar Chart</option>
    </select>
    <div id="cat-graph-container" style="width:500px;height:500px;margin: auto;">
        <canvas id="catChart"></canvas>
    </div>
    
    <script type="text/javascript">
        $(document).ready(function () {
            $("#catdatepicker").hide();
            var viewtypevalue = 10;
            var startDate = '01-01-1980';
            var endDate = '01-01-1980';
            // On chart type change
            $('select[name=selectorPublished]').change(function () {
                addcatclass(viewtypevalue);
                CatAjaxMethod(viewtypevalue, startDate, endDate)
            });
    
            // call function on load
            addcatclass(viewtypevalue);
            CatAjaxMethod(viewtypevalue, startDate, endDate);
            $('#cyearview, #cmonthview, #cweekview, #catdatepickerbtn').click(function () {
                var viewtype = $(this).val();
    
                if (viewtype.trim().toUpperCase() == 'YEAR VIEW') {
                    viewtypevalue = 10;
                    addcatclass(viewtypevalue);
                    $("#catdatepicker ,#catdatepickerbtn").hide();
                }
                else if (viewtype.trim().toUpperCase() == 'MONTH VIEW') {
                    viewtypevalue = 20;
                    addcatclass(viewtypevalue);
                    $("#catdatepicker ,#catdatepickerbtn").hide();
                }
                else if (viewtype.trim().toUpperCase() == 'WEEK VIEW') {
                    viewtypevalue = 30;
                    addcatclass(viewtypevalue);
                    $("#catdatepicker ,#catdatepickerbtn").hide();
                }
                else {
                    viewtypevalue = 0;
    
                }
    
                if (viewtype.trim().toUpperCase() == 'VIEW') {
                    if ($("#catsdatepicker").val()) {
                        startDate = $("#catsdatepicker").val();
                    }
                    if ($("#catedatepicker").val()) {
                        endDate = $("#catedatepicker").val();
                    }
                    if (startDate == '01-01-1980' || endDate == '01-01-1980') {
    
                        if (startDate == '01-01-1980' && endDate == '01-01-1980') {
                            $("<div>" + "Select start date and end date." + "</div>").dialog({
                                title: 'OneRead',
                                height: 70,
                                width: 350,
                                modal: true,
                                resizable: true
                            });
                            //alert("Select start date and end date.")
                            return false;
                        }
    
                        else if (startDate == '01-01-1980') {
                            $("<div>" + "Select start date." + "</div>").dialog({
                                title: 'OneRead',
                                height: 70,
                                width: 350,
                                modal: true,
                                resizable: true
                            });
                            return false;
                        }
                        else if (endDate == '01-01-1980') {
                            $("<div>" + "Select end date." + "</div>").dialog({
                                title: 'OneRead',
                                height: 70,
                                width: 350,
                                modal: true,
                                resizable: true
                            });
                            return false;
                        }
                    }
                    else if ((new Date(startDate).getTime() >= new Date(endDate).getTime())) {
                        $("<div>" + "Start date must be less than end date." + "</div>").dialog({
                            title: 'OneRead',
                            height: 70,
                            width: 350,
                            modal: true,
                            resizable: true
                        });
                        return false;
                    }
                }
                //if ($("#catsdatepicker").val()) {
                //    startDate = $("#catsdatepicker").val();
                //}
                //if ($("#catedatepicker").val()) {
                //    endDate = $("#catedatepicker").val();
                //}
                //var startDate = $("#sdatepicker").val();
                CatAjaxMethod(viewtypevalue, startDate, endDate);
            });
        });
    
    
        function CatAjaxMethod(viewtypevalue, startDate, endDate) {
            $.ajax({
                url: '@Html.Raw(Url.Action("DisplayCategoryChart", "AnalyticsAndReports"))',
                data: { "viewtypeid": viewtypevalue, "startDate": startDate, "endDate": endDate },
                dataType: "json",
                type: "GET",
                contentType: 'application/json; charset=utf-8',
                async: false,
                processData: true,
                cache: false,
                delay: 15,
                success: function (data) {
                    var series = new Array();
                    var CatSeriesValue = new Array();
                    var CatSeriesItem = new Array();
                    for (var i in data) {
                        var serieItm = new Array((data[i].Item).toString());
                        var serieValue = new Array(data[i].Value);
    
                        CatSeriesItem.push(parseInt(serieItm));
                        CatSeriesValue.push(serieValue);
                    }
    
    
                    DrawCatLineChart(CatSeriesValue, CatSeriesItem);
                },
                error: function (xhr) {
                    alert('error');
                }
            });
        }
        function DrawCatLineChart(CatSeriesValue, CatSeriesItem) {
    
            $('#catChart').remove(); // this is <canvas> element
            $('#cat-graph-container').append('<canvas id="catChart"><canvas>');
    
            var ctx = document.getElementById("catChart");
            var ChartType = 'line';
            var chartTypeId = $('select[name=selectorPublished]').val();
    
            if (chartTypeId == 1)
                ChartType = 'line';
    
            else if (chartTypeId == 2)
                ChartType = 'bar';
            var catChart = new Chart(ctx, {
    
                type: ChartType,
                data: {
                    labels: CatSeriesValue,
                    datasets: [
                        {
                            label: 'Category Browsed',
                            fillColor: "rgba(60,141,188,0.9)",
                            strokeColor: "rgba(60,141,188,0.8)",
                            pointColor: "#3b8bba",
                            pointStrokeColor: "rgba(60,141,188,1)",
                            pointHighlightFill: "#fff",
                            pointHighlightStroke: "rgba(60,141,188,1)",
                            borderColor: 'rgba(60, 141, 188, 0.7)',
                            backgroundColor: 'rgba(44, 152, 214, 0.5)',
                            pointBorderColor: 'rgba(37, 103, 142, 0.9)',
                            pointBackgroundColor: 'rgba(60, 141, 188, 0.4)',
                            pointBorderWidth: 1,
                            data: CatSeriesItem,
    
    
                        },
                    ]
                },
                options: {
                    scales: {
                        yAxes: [{
                            ticks: {
                                beginAtZero: true
                            }
                        }]
                    }
                }
            });
        }
        $(function () {
            $("#catsdatepicker").datepicker({
                changeMonth: true,
                changeYear: true
            });
            $("#catedatepicker").datepicker({
                changeMonth: true,
                changeYear: true
            });
        });
        $('#cdateview').click(function () {
            $("#catdatepicker ,#catdatepickerbtn").show();
            addcatclass(0);
        });
    
        function addcatclass(viewtypevalue) {
            if (viewtypevalue == 10) {
                $("#cyearview").addClass("activecolor");
                $("#cmonthview").removeClass("activecolor");
                $("#cweekview").removeClass("activecolor");
                $("#cdateview").removeClass("activecolor");
            }
            else if (viewtypevalue == 20) {
                $("#cmonthview").addClass("activecolor");
                $("#cyearview").removeClass("activecolor");
                $("#cweekview").removeClass("activecolor");
                $("#cdateview").removeClass("activecolor");
            }
            else if (viewtypevalue == 30) {
                $("#cweekview").addClass("activecolor");
                $("#cmonthview").removeClass("activecolor");
                $("#cyearview").removeClass("activecolor");
                $("#cdateview").removeClass("activecolor");
            }
            else if (viewtypevalue == 0) {
                $("#cdateview").addClass("activecolor");
                $("#cmonthview").removeClass("activecolor");
                $("#cweekview").removeClass("activecolor");
                $("#cyearview").removeClass("activecolor");
            }
        }
    </script>
    
    ***********************************************************************************************
    [_customerChart.cshtml]
    
    
    <style>
        .timeButton {
            background-color: #00c0ef;
            border-color: #00acd6;
            color: white;
        }
    
        .activecolor {
            background-color: #3c8dbc !important;
        }
    
        .selectchart {
            width: 20%;
            float: right;
            height: 30px;
            background-color: #00c0ef;
            color: white;
            margin-top: -2%;
        }
    </style>
    
    <input type="button" id="userdemographicview" value="User Demographics" class="timeButton" />
    <input type="button" id="usertimelineview" value="User Timeline" class="timeButton" />
    
    
    
    <div style="margin: 0 auto; width: 400px;">
        <input type="button" id="custyearview" value="Year View" class="timeButton">
        <input type="button" id="custmonthview" value="Month View" class="timeButton" />
        <input type="button" id="custweekview" value="Week View" class="timeButton" />
        <input type="button" id="custdateview" value="View by date" class="timeButton" />
    
    
        <div id="custdatepicker" style="display:none">
            StartDate: <input type="text" id="custsdatepicker">
            EndDate: <input type="text" id="custedatepicker">
        </div>
        <input id="custdatepickerbtn" style="display:none" type="button" value="View" class="timeButton" />
    </div>
    
    <select name="selectorCustoemr" class="selectchart">
        <option value="1">Line Chart</option>
        <option value="2">Bar Chart</option>
    </select>
    
    <div id="cust-graph-container" style="width:500px;height:500px;margin: auto;">
        <canvas id="Customerchart" ></canvas>
    </div>
    @*<div id="container" style="min-width: 350px; height: 350px; max-width: 600px; margin: 0 auto"></div>*@
    
    <script type="text/javascript">
        $(document).ready(function () {
    
            $("#custdatepicker").hide();
            $("#custdatepickerbtn").hide();
            var actiontypeId = 60;
            var viewtypevalue = 00;
            var startDate = '01-01-1980';
            var endDate = '01-01-1980';
        
            // On chart type change
            $('select[name=selectorCustoemr]').change(function () {
                addCustclass(viewtypevalue);
                AjaxCustMethod(viewtypevalue, startDate, endDate, actiontypeId);
            });
    
            //call function on load
            //addCustclass(viewtypevalue);
            addclassOnCustAction(actiontypeId);
            $("#custdatepicker,#custdatepickerbtn,#custyearview,#custmonthview,#custweekview,#custdateview").hide();
            AjaxCustMethod(viewtypevalue, startDate, endDate, actiontypeId)
            $('#custyearview, #custmonthview, #custweekview, #custdatepickerbtn,#userdemographicview,#usertimelineview').click(function () {
                var viewtype = $(this).val();
                if (viewtype.trim().toUpperCase() == 'YEAR VIEW') {
                    viewtypevalue = 10;
                    addCustclass(viewtypevalue);
                    $("#custdatepicker,#custdatepickerbtn").hide();
                }
                else if (viewtype.trim().toUpperCase() == 'MONTH VIEW') {
                    viewtypevalue = 20;
                    addCustclass(viewtypevalue);
                    $("#custdatepicker,#custdatepickerbtn").hide();
                }
                else if (viewtype.trim().toUpperCase() == 'WEEK VIEW') {
                    viewtypevalue = 30;
                    addCustclass(viewtypevalue);
                    $("#custdatepicker,#custdatepickerbtn").hide();
    
                }
                else {
                    viewtypevalue = 0;
    
                }
    
                if (viewtype.trim().toUpperCase() == 'VIEW') {
                    if ($("#custsdatepicker").val()) {
                        startDate = $("#custsdatepicker").val();
                    }
                    if ($("#custedatepicker").val()) {
                        endDate = $("#custedatepicker").val();
                    }
                    if (startDate == '01-01-1980' || endDate == '01-01-1980') {
    
                        if (startDate == '01-01-1980' && endDate == '01-01-1980') {
                            $("<div>" + "Select start date and end date." + "</div>").dialog({
                                title: 'OneRead',
                                height: 70,
                                width: 350,
                                modal: true,
                                resizable: true
                            });
                            return false;
                        }
    
                        else if (startDate == '01-01-1980') {
                            $("<div>" + "Select start date." + "</div>").dialog({
                                title: 'OneRead',
                                height: 70,
                                width: 350,
                                modal: true,
                                resizable: true
                            });
                            return false;
                        }
                        else if (endDate == '01-01-1980') {
                            $("<div>" + "Select end date." + "</div>").dialog({
                                title: 'OneRead',
                                height: 70,
                                width: 350,
                                modal: true,
                                resizable: true
                            });
                            return false;
                        }
                    }
                    else if ((new Date(startDate).getTime() >= new Date(endDate).getTime())) {
                        $("<div class='dialogbox'>" + "Start date must be less than end date." + "</div>").dialog({
                            title: 'OneRead',
                            height: 70,
                            width: 350,
                            modal: true,
                            resizable: true
                        });
                        return false;
                    }
                }
                else if (viewtype.trim().toUpperCase() == 'USER DEMOGRAPHICS') {
                    viewtypevalue = 60;
                    actiontypeId = 60;
                    addclassOnCustAction(actiontypeId);
                    $("#custdatepicker,#custdatepickerbtn,#custyearview,#custmonthview,#custweekview,#custdateview").hide();
                }
                if (viewtype.trim().toUpperCase() == 'USER TIMELINE') {
                    viewtypevalue = 10;
                    actiontypeId = 70;
                    addCustclass(viewtypevalue);
                    addclassOnCustAction(actiontypeId);
                    $("#custdatepicker,#custdatepickerbtn").hide();
                    $("#custyearview,#custmonthview,#custweekview,#custdateview").show();
                }
      
                AjaxCustMethod(viewtypevalue, startDate, endDate, actiontypeId);
            });
        });
    
        function AjaxCustMethod(viewtypevalue, startDate, endDate, actiontypeId) {
            
            $.ajax({
                url: '@Html.Raw(Url.Action("DisplayCustomerChart", "AnalyticsAndReports"))',
                data: { "viewtypeid": viewtypevalue, "startDate": startDate, "endDate": endDate, "actionType": actiontypeId },
                dataType: "json",
                type: "GET",
                contentType: 'application/json; charset=utf-8',
                async: false,
                processData: true,
                cache: false,
                delay: 15,
                success: function (responseData) {
                   
                    var CustSeriesValue = new Array();
                    var CustSeriesItem = new Array();
                    for (var i in responseData.list) {
                        var serieItm = new Array((responseData.list[i].Item).toString());
                        var serieValue = new Array(responseData.list[i].Value);
    
                        CustSeriesItem.push(parseInt(serieItm));
                        CustSeriesValue.push(serieValue);
                    }
    
                    var Cust_dSeriesValue = new Array();
                    var Cust_dSeriesItem = new Array();
                    for (var i in responseData.list_d) {
                        var serieValue = new Array(responseData.list_d[i].Value);
                        var serieItem = new Array(responseData.list_d[i].Item.toString());
    
                        Cust_dSeriesItem.push(parseInt(serieItem));
                        Cust_dSeriesValue.push(serieValue);
    
                    }
    
                    DrawCustLineChart(CustSeriesValue, CustSeriesItem, Cust_dSeriesValue, Cust_dSeriesItem, actiontypeId);
                },
                error: function (xhr) {
                    alert('error');
                }
            });
        }
    
        function DrawCustLineChart(CustSeriesValue, CustSeriesItem, Cust_dSeriesValue, Cust_dSeriesItem, actiontypeId) {
      
            $('#Customerchart').remove(); // this is <canvas> element
            $('#cust-graph-container').append('<canvas id="Customerchart"><canvas>');
    
            var ctx = document.getElementById("Customerchart");
            var CustChartType = 'line';
            var label = CustSeriesValue;
    
            if (CustSeriesValue == '') {
                label = Cust_dSeriesValue;
            }
            var CustchartTypeId = $('select[name=selectorCustoemr]').val();
            if (CustchartTypeId == 1)
                CustChartType = 'line';
    
            else if (CustchartTypeId == 2)
                CustChartType = 'bar';
    
            var label1 = 'Active Cutomers';
            var label2 = 'New Customers';
    
            if (actiontypeId == 60) {
                label1 = 'Customers Demographic';
                label2 = '';
            }
            var Customerchart = new Chart(ctx, {
    
                type: CustChartType,
                data: {
    
                    labels: label,
                    datasets: [
                        {
                            fillColor: "rgba(60,141,188,0.9)",
                            strokeColor: "rgba(60,141,188,0.8)",
                            label: label1,
                            pointColor: "#3b8bba",
                            pointStrokeColor: "rgba(60,141,188,1)",
                            pointHighlightFill: "#fff",
                            pointHighlightStroke: "rgba(60,141,188,1)",
                            borderColor: 'rgba(60, 141, 188, 0.7)',
                            backgroundColor: 'rgba(44, 152, 214, 0.5)',
                            pointBorderColor: 'rgba(37, 103, 142, 0.9)',
                            pointBackgroundColor: 'rgba(60, 141, 188, 0.4)',
                            pointBorderWidth: 1,
                            data: CustSeriesItem,
                        },
                        {
                            label: label2,
                            fillColor: "rgba(60,141,188,0.9)",
                            strokeColor: "rgba(60,141,188,0.8)",
                            pointColor: "#00a65a",
                            pointStrokeColor: "rgba(0,166,90,1)",
                            pointHighlightFill: "#fff",
                            pointHighlightStroke: "rgba(0,166,90,1)",
                            borderColor: 'rgba(0,166,90, 1)',
                            backgroundColor: 'rgba(0,166,90,0.5)',
                            pointBorderColor: 'rgba(0,166,90,0.7)',
                            pointBackgroundColor: 'rgba(0,166,90,0.2)',
                            pointBorderWidth: 1,
                            data: Cust_dSeriesItem,
    
                        }
                    ]
                },
                responsive: true,
    
                options: {
                    scales: {
                        yAxes: [{
                            ticks: {
                                beginAtZero: true
                            }
                        }]
                    }
    
                }
            });
        }
    
        $(function () {
            $("#custsdatepicker").datepicker({
                changeMonth: true,
                changeYear: true
            });
            $("#custedatepicker").datepicker({
                changeMonth: true,
                changeYear: true
            });
        });
        $('#custdateview').click(function () {
            $("#custdatepicker,#custdatepickerbtn").show();
            addCustclass(0);
        });
        function addCustclass(viewtypevalue) {
            if (viewtypevalue == 10) {
                $("#custyearview").addClass("activecolor");
                $("#custmonthview").removeClass("activecolor");
                $("#custweekview").removeClass("activecolor");
                $("#custdateview").removeClass("activecolor");
            }       
            else if (viewtypevalue == 20) {
                $("#custmonthview").addClass("activecolor");
                $("#custyearview").removeClass("activecolor");
                $("#custweekview").removeClass("activecolor");
                $("#custdateview").removeClass("activecolor");
            }
            else if (viewtypevalue == 30) {
                $("#custweekview").addClass("activecolor");
                $("#custmonthview").removeClass("activecolor");
                $("#custyearview").removeClass("activecolor");
                $("#custdateview").removeClass("activecolor");
            }
            else if (viewtypevalue == 0) {
                $("#custdateview").addClass("activecolor");
                $("#custmonthview").removeClass("activecolor");
                $("#custweekview").removeClass("activecolor");
                $("#custyearview").removeClass("activecolor");
            }
        }
        function addclassOnCustAction(actiontypeId) {
            
             if (actiontypeId == 60) {
                $("#userdemographicview").addClass("activecolor");
                $("#usertimelineview").removeClass("activecolor");
    
            }
            else if (actiontypeId == 70) {
                $("#usertimelineview").addClass("activecolor");
                $("#userdemographicview").removeClass("activecolor");
    
            }
        }
    </script>
    
    

    external by joshi-kumar modified Feb 17, 2018  7  4  1  0

    Encrypt code in js and decrypt the code in c# (.cs)

    Encrypt code in js and decrypt the code in c# (.cs): Encrypt in js and decrypt in c#
    c# code
    public string DecryptStringAES(string encryptedValue)
            {
                var keybytes = Encoding.UTF8.GetBytes("7061737323313233");
                var iv = Encoding.UTF8.GetBytes("7061737323313233");
    
                //DECRYPT FROM CRIPTOJS
                var encrypted = Convert.FromBase64String(encryptedValue);
                var decriptedFromJavascript = DecryptStringFromBytes(encrypted, keybytes, iv);
    
                return decriptedFromJavascript;
            }
    
            private static string DecryptStringFromBytes(byte[] cipherText, byte[] key, byte[] iv)
            {
                // Check arguments.
                if (cipherText == null || cipherText.Length <= 0)
                {
                    throw new ArgumentNullException("cipherText");
                }
                if (key == null || key.Length <= 0)
                {
                    throw new ArgumentNullException("key");
                }
                if (iv == null || iv.Length <= 0)
                {
                    throw new ArgumentNullException("key");
                }
    
                // Declare the string used to hold
                // the decrypted text.
                string plaintext = null;
    
                // Create an RijndaelManaged object
                // with the specified key and IV.
                using (var rijAlg = new RijndaelManaged())
                {
                    //Settings
                    rijAlg.Mode = CipherMode.CBC;
                    rijAlg.Padding = PaddingMode.PKCS7;
                    rijAlg.FeedbackSize = 128;
    
                    rijAlg.Key = key;
                    rijAlg.IV = iv;
                  
                    // Create a decrytor to perform the stream transform.
                    var decryptor = rijAlg.CreateDecryptor(rijAlg.Key, rijAlg.IV);
    
                    // Create the streams used for decryption.
                    using (var msDecrypt = new MemoryStream(cipherText))
                    {
                        using (var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
                        {
                            using (var srDecrypt = new StreamReader(csDecrypt))
                            {
                                // Read the decrypted bytes from the decrypting stream
                                // and place them in a string.
                                plaintext = srDecrypt.ReadToEnd();
                            }
                        }
                    }
                }
    
                return plaintext;
            }
            *****************************************************************************************
            js code 
            --------
            function Encryption(number) {
        console.log(number);
        var key = CryptoJS.enc.Utf8.parse('7061737323313233');
            var iv = CryptoJS.enc.Utf8.parse('7061737323313233');
            var encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(number), key,
                {
                    keySize: 128 / 8,
                    iv: iv,
                    mode: CryptoJS.mode.CBC,
                    padding: CryptoJS.pad.Pkcs7
                });
            return encrypted.toString();
      }
    
    
    • Public Snippets
    • Channels Snippets