0 Replies - 786 Views - Last Post: 31 July 2016 - 08:04 AM

#1 karengsh  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 129
  • Joined: 18-May 09

How do I use my webform to call a method ?

Posted 31 July 2016 - 08:04 AM

Hello,

I am starting out on webform with a DAO layer and WebService layer.

Here's my database schema,

Table : User

userID
roleID
userName
mobileNumber
userEmail

My web service layer :

 public class WebService1 : System.Web.Services.WebService
    {

        DAO.UserEF userDAO = new DAO.UserEF();
        

        // List of User object
        [WebMethod]
        public List<WebDL.User> GetUsers()
        {
            List<WebDL.User> Userlist = new List<WebDL.User>();
            Userlist = userDAO.GetUsers().ToList<WebDL.User>();
            return Userlist;
        }






My DAO layer

namespace WebSL.DAO
{
    public class UserEF
    {
         private PhoneUserEntities db = new PhoneUserEntities();

        public IQueryable<User> GetUsers()
        {
            return db.Users; 
        }
        private bool UserExists(int id)
        {
            return db.Users.Count(e => e.userID == id) > 0;
        }

        [b]private bool UserExists(User userName)
        {
            return db.Users.Count(e => e.userName.Equals(userName) > 0;
        }[/b]
        public User GetUser(int id)
        {
            User user = db.Users.Find(id);
            if (user == null)
            {

            }

            return user;
        }



I am stuck at what to do with checking if a user already has a username cos I dun think I can use UserID in my case.
If it exist, then I will redirect the user to another form otherwise the user can continue the register using form.

Can someone advice me what should be in the DAO layer or Service layer so that I can call them in my webform ?

I am trying with this line of code :
 private bool UserExists(User userName)
        {
            return db.Users.Count(e => e.userName.Equals(userName) > 0;
        }



but apparently, my poor coding logic is not helping me...and I am STUCK ......

And here's my registration form :

 protected void Submit_Button_Click(object sender, EventArgs e)
        {
           
                       
                    PhoneUserEntities db = new PhoneUserEntities();
            
                    
               //     ServiceReference1.WebService1SoapClient sr = new ServiceReference1.WebService1SoapClient();
                        
                WHAT SHOULD I put here ????    
                    
                    User customer = new User();
                    customer.userName = txtUserName.Text;                   
                    customer.userName = txtUserName.Text;
                    customer.lastName = txtLastName.Text;
                    customer.userPassword = txtUserPassword.Text;
                    customer.userPassword = txtConfirmedPassword.Text;
                    customer.moblieNumber = txtMobileNo.Text;
                    customer.userAddress = txtAddress.Text;
                    customer.userEmail = txtEmail.Text;
                    customer.roleID = 1;
                    customer.paymentMethod = DropDownList1.SelectedValue;
                    
            cntx.Users.Add(customer);
                    //    cntx.SaveChanges();
                    //    lblMessageSuccess.Text = "successful registration";
                    //    Response.Redirect("/ShoppingPage.aspx");
                    //}



                    else if (checkuser != 0)
                    {
                        lblMessageUser.Text = "You have registered before. Pls proceed to login";
                        Response.Redirect("/Login.aspx");
                    }

                }





Hope someone can help me....Thanks..

Is This A Good Question/Topic? 0
  • +

Page 1 of 1