Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpCookie cookie = Request.Cookies["user_id"];//getting the user_id

            Database_Connection con = new Database_Connection();

            //checking if the cookie exists and if it doesn't to create it
            if (cookie == null)
            {
                Unnamed_LoggingOut();

                //creating a default user id
                cookie         = new HttpCookie("user_id");
                cookie.Value   = "0";
                cookie.Expires = DateTime.Now.AddDays(1);
                // cookie.Path = Request.ApplicationPath;
                Response.Cookies.Add(cookie);
            }

            //checking if the user is an default user or custom user and update the UI appropraitely
            if (cookie.Value == "0")
            {
                cart.Visible     = false;
                carts.HRef       = "";
                cart_amount.HRef = "";
                add_prod.Visible = false;
            }
            else
            {
                Process_Executor exec = new Process_Executor();
                cart.Visible          = true;
                carts.HRef            = "~/CART_DATA/CART_INFO.aspx";
                cart_amount.HRef      = "~/CART_DATA/CART_INFO.aspx";
                user.InnerText        = "Hello, " + exec.get_user_name(cookie.Value);
                login_state.Visible   = true;
                logout_state.Visible  = false;
                cart_amount.InnerText = exec.cart_items_count(cookie.Value);


                //checking if the user is an admin user to unlock the admin functionality appropriately
                if (exec.get_user_type(cookie.Value) == "ADMIN")
                {
                    add_prod.Visible = true;
                }
                else
                {
                    add_prod.Visible = false;
                }
            }
        }