public static MyUser[] fetchUsersforCourseid(int _courseid)
        {
            dbManager db = new dbManager();
            MyUser[] users = null;

            string sqlCommand;
            MySqlParameter[] param = new MySqlParameter[1];

            param[0] = new MySqlParameter("@courseid", _courseid);

            sqlCommand = "select User.* from UserCourse join User on UserCourse.Userid=user.Userid "+
                        " where Courseidy=@courseid";

            DataTable ds = db.fetchRows(sqlCommand, param);
            users = new MyUser[ds.Rows.Count];
            int i = 0;

            foreach (DataRow dr in ds.Rows)
            {
                users[i] = new MyUser((int)dr["userid"],
                                        dr["username"].ToString(),dr["nameUser"].ToString(),
                                        dr["contactno"].ToString(),
                                        (UserType)Enum.Parse(typeof(UserType), dr["usertype"].ToString()),
                                        (UserStatus)Enum.Parse(typeof(UserStatus), dr["UserStatus"].ToString()));
                i++;
            }

            return users;
        }
 private void CreateAndLoginUser()
 {
     if (!IsValid)
     {
         return;
     }
     var manager = new UserManager();
     var user = new ApplicationUser() { UserName = userName.Text };
     IdentityResult result = manager.Create(user);
     if (result.Succeeded)
     {
         var loginInfo = Context.GetOwinContext().Authentication.GetExternalLoginInfo();
         if (loginInfo == null)
         {
             Response.Redirect("~/Account/Login");
             return;
         }
         result = manager.AddLogin(user.Id, loginInfo.Login);
         if (result.Succeeded)
         {
             MyUser myuser = new MyUser(userName.Text, "", nameUser.Text, contactNo.Text, (UserType)Enum.Parse(typeof(UserType), userType.SelectedItem.Value));
             int returncode = myuser.addUser();
             //MyUser user1 = MyUser.getUser(userName.Text, "");
             //if (Session["UserId"] != null && Convert.ToInt32(Session["UserId"].ToString()) != user1.userId)
             //    Session.Add("UserId", user1.userId);
             IdentityHelper.SignIn(manager, user, isPersistent: false);
             IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
             return;
         }
     }
     AddErrors(result);
 }
Example #3
0
        public static MyUser getUser(int userid)
        {
            dbManager db = new dbManager();
            MyUser usr = null;

            string sqlCommand;
            MySqlParameter[] param = new MySqlParameter[1];

            param[0] = new MySqlParameter("@userid", userid);

            sqlCommand = "select * from user where Userid=@userid";

            DataTable ds = db.fetchRows(sqlCommand, param);

            foreach (DataRow dr in ds.Rows)
            {
                usr = new MyUser((int)dr["userid"], dr["Username"].ToString(),
                    dr["nameuser"].ToString(), dr["contactno"].ToString(),
                    (UserType)Enum.Parse(typeof(UserType), dr["usertype"].ToString()),
                    (UserStatus)Enum.Parse(typeof(UserStatus), dr["userstatus"].ToString()));
            }

            return usr;
        }