// To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.

        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            if (HttpContext.Session.Get("Id") != null)
            {
                byte[] str = HttpContext.Session.Get("Id");
                string ID  = Encoding.UTF8.GetString(str, 0, str.Length);
                ViewData["Userid"] = ID;
                //Console.Out.Write(ViewData["Userid"]);
            }
            if (HttpContext.Session.Get("Role") != null)
            {
                byte[] str  = HttpContext.Session.Get("Role");
                string Role = Encoding.UTF8.GetString(str, 0, str.Length);
                ViewData["UserRole"] = Role;
            }

            //Console.Out.Write(ViewData["Userid"]);
            Product = _context.getProduct(id.GetValueOrDefault());

            if (Product == null)
            {
                return(NotFound());
            }
            return(Page());
        }
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (HttpContext.Session.Get("Id") != null)
            {
                byte[] str = HttpContext.Session.Get("Id");
                string ID  = Encoding.UTF8.GetString(str, 0, str.Length);
                ViewData["Userid"] = ID;
            }
            if (HttpContext.Session.Get("Role") != null)
            {
                byte[] str  = HttpContext.Session.Get("Role");
                string Role = Encoding.UTF8.GetString(str, 0, str.Length);
                ViewData["UserRole"] = Role;
            }
            Product        = _context.getProduct(id.GetValueOrDefault());
            Order          = new Orders();
            Order.O_Status = "Processing";
            Order.O_Date   = DateTime.Now;
            Order.O_UID    = int.Parse(ViewData["UserId"].ToString());
            Order.O_PIDS   = Product.P_ID;

            if (Product == null)
            {
                return(NotFound());
            }

            return(Page());
        }
Exemplo n.º 3
0
 public async Task <IActionResult> OnGetAsync(int id)
 {
     if (HttpContext.Session.Get("Id") != null)
     {
         byte[] str = HttpContext.Session.Get("Id");
         string ID  = Encoding.UTF8.GetString(str, 0, str.Length);
         ViewData["Userid"] = ID;
     }
     if (HttpContext.Session.Get("Role") != null)
     {
         byte[] str  = HttpContext.Session.Get("Role");
         string Role = Encoding.UTF8.GetString(str, 0, str.Length);
         ViewData["UserRole"] = Role;
     }
     Product = _context.getProduct(id);
     Id      = id;
     if (Product == null)
     {
         return(NotFound());
     }
     return(Page());
 }
Exemplo n.º 4
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (HttpContext.Session.Get("Id") != null)
            {
                byte[] str = HttpContext.Session.Get("Id");
                string ID  = Encoding.UTF8.GetString(str, 0, str.Length);
                ViewData["Userid"] = ID;
            }
            if (HttpContext.Session.Get("Role") != null)
            {
                byte[] str  = HttpContext.Session.Get("Role");
                string Role = Encoding.UTF8.GetString(str, 0, str.Length);
                ViewData["UserRole"] = Role;
            }
            Product           = _context.getProduct(id.GetValueOrDefault());
            Products          = _context.getProductList();
            productSelectList = new SelectList(Products, "ID", "P_Name");
            SelectedId        = 1;

            validReviews = _context.GetReviewsOnProduct(id.GetValueOrDefault());

            return(Page());
        }
Exemplo n.º 5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            Order = _context.getOrder(id.GetValueOrDefault());

            P = _context.getProduct(Order.O_PIDS.GetValueOrDefault());

            if (Order != null)
            {
                SqlConnection sqlConnection = new SqlConnection(_context.connection);

                SqlCommand cmd = new SqlCommand("dbo.delete_Order", sqlConnection);
                cmd.Parameters.Add("@id", SqlDbType.Int).Value       = id.GetValueOrDefault();;
                cmd.Parameters.Add("@p_id", SqlDbType.Int).Value     = P.P_ID;
                cmd.Parameters.Add("@p_amount", SqlDbType.Int).Value = P.P_Amount + 1;
                cmd.CommandType = CommandType.StoredProcedure;


                sqlConnection.Open();
                cmd.ExecuteNonQuery();
                sqlConnection.Close();
            }
            if (HttpContext.Session.Get("Role") != null)
            {
                byte[] str  = HttpContext.Session.Get("Role");
                string Role = Encoding.UTF8.GetString(str, 0, str.Length);
                ViewData["UserRole"] = Role;
                role = ViewData["UserRole"].ToString();
            }
            if (role == "Admin" || role == "Master")
            {
                return(RedirectToPage("./OrderTable"));
            }
            else
            {
                return(RedirectToPage("./OrderCustomerTable"));
            }
        }