Beispiel #1
0
        public async Task 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;
                //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;
            }
            USERS    = _context.getUserList();
            REVIEW   = _context.getReviewList();
            PRODUCTS = _context.getProductList();
            count    = REVIEW.Count();
            for (int i = 0; i < USERS.Count(); i++)
            {
                //Msg1 = "In";

                //ID;s validation
                if (USERS[i].U_ID == id)
                {
                    currentUserID = USERS[i].U_ID - 1;//-1 because ID start from 1, but list is start from 0
                }
            }
        }
Beispiel #2
0
        // 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> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            SqlConnection sqlConnection = new SqlConnection(_context.connection);
            SqlCommand    cmd           = new SqlCommand("dbo.users_insert_register", sqlConnection);

            cmd.Parameters.Add("@u_id", SqlDbType.Int).Value       = USERS.U_ID;
            cmd.Parameters.Add("@u_pass", SqlDbType.Char).Value    = USERS.U_Pass;
            cmd.Parameters.Add("@u_fName", SqlDbType.Char).Value   = USERS.U_FName;
            cmd.Parameters.Add("@u_lName", SqlDbType.Char).Value   = USERS.U_LName;
            cmd.Parameters.Add("@u_address", SqlDbType.Char).Value = USERS.U_Address;
            cmd.Parameters.Add("@u_country", SqlDbType.Char).Value = USERS.U_Country;
            cmd.Parameters.Add("@u_zipcode", SqlDbType.Int).Value  = USERS.U_Zipcode;
            cmd.Parameters.Add("@u_phone", SqlDbType.Char).Value   = USERS.U_Phone;
            cmd.Parameters.Add("@u_email", SqlDbType.Char).Value   = USERS.U_Email;
            cmd.Parameters.Add("@u_msg", SqlDbType.Char).Value     = "";
            cmd.CommandType = CommandType.StoredProcedure;

            sqlConnection.Open();
            cmd.ExecuteNonQuery();
            sqlConnection.Close();

            List <USER> users = _context.getUserList();

            url = "./RegisterSucceed?id=" + users[users.Count() - 1].U_ID;
            return(Redirect(url));
        }
Beispiel #3
0
        public async Task 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;
            }
            USERS = _context.getUserList();

            //CurrentUser = await _context.LoginUSER.FirstOrDefaultAsync(m => m.U_ID == id);
            for (int i = 0; i < USERS.Count(); i++)
            {
                //Msg1 = "In";

                //ID;s validation
                if (USERS[i].U_ID == id)
                {
                    currentID = USERS[i].U_ID - 1;//-1 because ID start from 1, but list is start from 0
                }
            }
        }
Beispiel #4
0
        /*
         * public async Task OnGetAsync()
         * {
         *  Msg = "in OnGetAsync()";
         *  USERS = await _context.USERS.ToListAsync();
         *
         * }*/

        public async Task <IActionResult> OnPost(int?id)
        {
            //Msg = "in OnPostAsync()";

            //_context.LoginUSER.Add(USER);
            USERS = _context.getUserList();

            /*if (!ModelState.IsValid)
             * {
             *  return Page();
             * }*/

            for (int i = 0; i < USERS.Count(); i++)
            {
                //Msg1 = "In";

                //ID;s validation
                if (USERS[i].U_ID == LOGIN_USER.U_ID)
                {
                    //Msg = item.U_ID.ToString();
                    //Msg1 = USER.U_ID.ToString();

                    //Password's validation
                    //USER.U_Pass.Contains(USERS[i].U_Pass)
                    if (LOGIN_USER.U_Pass == USERS[i].U_Pass.Trim())
                    {
                        //matched - get all needed infos
                        LOGIN_USER.U_ID = USERS[i].U_ID;
                        //id = USER.U_ID;//Set for route
                        LOGIN_USER.U_LName = USERS[i].U_LName;
                        LOGIN_USER.U_Pass  = USERS[i].U_Pass;
                        LOGIN_USER.U_Role  = USERS[i].U_Role;
                        //Start redirect user by ROLE
                        HttpContext.Session.SetString("Id", LOGIN_USER.U_ID.ToString());
                        HttpContext.Session.SetString("Role", LOGIN_USER.U_Role.ToString());

                        if (USERS[i].U_Role.Contains("Customer"))
                        {
                            url = "../USERS/CustomerAccountMm?id=" + LOGIN_USER.U_ID.ToString();
                            return(Redirect(url));//go back to homepage/product view for customer
                        }
                        else
                        {
                            url = "../USERS/Index?id=" + LOGIN_USER.U_ID.ToString();
                            //mean this user is master/admin role
                            //return RedirectToPage(url);//go to users management/view page
                            //"./Details?id=" + LOGIN_USER.U_ID.ToString()
                            return(Redirect(url));

                            //return RedirectToPage("./Index");
                        }
                    }
                    else
                    {
                        //mean ID or password doesnt matched
                        return(Page());
                    }
                }
            }

            //Msg1 = "outside foreach "+ USER.U_ID.ToString();

            return(Page());
        }