0

Good Day All i have a a WCF service , that is checking the login details and its working fine as it should, i decided to add another Function that will display data.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace DAL
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IsDAL" in both code and config file together.
    [ServiceContract]
    public interface IDAL
    {
        [OperationContract]
        int ValidateLogin(String Username, String Password);

        [OperationContract]
        List<LoginModel> GetLogins(); 
    }
}

And the Main class looks like this 

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Configuration;
using System.ComponentModel;

namespace DAL
{
    public class DAL:IDAL
    {
        String strCon = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;

        SqlCommand cmdselect;

        SqlConnection con;

        SqlDataAdapter da;

        /// <summary>
        /// Validate Logins and Return a Integer, if the Value is greater 
        /// </summary>
        /// <param name="Username"></param>
        /// <param name="Password"></param>
        /// <returns></returns>
        public int ValidateLogin(String Username, String Password)
        {

            con = new SqlConnection(strCon);

            cmdselect = new SqlCommand();

            cmdselect.CommandText = "usp_CheckLogin";

            cmdselect.CommandType = CommandType.StoredProcedure;

            cmdselect.Connection = con;

            cmdselect.Parameters.Add("@USER_ID", SqlDbType.VarChar, 50).Value = Username;

            cmdselect.Parameters.Add("@Password", SqlDbType.VarChar, 50).Value = Password;

            cmdselect.Parameters.Add("@Count", SqlDbType.Int);

            cmdselect.Parameters["@Count"].Direction = ParameterDirection.Output;

            int iExistance = 0;

            try
            {
                con.Open();

                cmdselect.ExecuteNonQuery();

                iExistance = (int)cmdselect.Parameters["@Count"].Value;

            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }

            return iExistance;
        }

        /// <summary>
        /// return Logins in a List formart
        /// </summary>
        /// <returns></returns>
        
        public List<LoginModel> GetLogins()
        {
            SqlConnection con = new SqlConnection("User id=motovate;Password=motovate;Server=devsql1;Database=MOTOVATE_PRO_DEV");

            SqlCommand cmdselect = new SqlCommand("usp_SelectLogins");

            cmdselect.CommandType = CommandType.StoredProcedure;

            SqlDataAdapter da = new SqlDataAdapter();

            cmdselect.Connection = con;

            da.SelectCommand = cmdselect;


            DataTable dt = new DataTable();

            List<LoginModel> m_Logins = new List<LoginModel>();

            try
            {
                con.Open();

                da.Fill(dt);

                m_Logins  = convertDatatableToList(dt);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }
            return m_Logins;

        }

        /// <summary>
        /// Convert a Datatable into a List to be Presented in Silverlight 
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public List<LoginModel> convertDatatableToList(DataTable dt)
        {    
            List<LoginModel> mFinal = new List<LoginModel>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                LoginModel m = new LoginModel();
                m.iID = Convert.ToInt32(dt.Rows[i][0]); 
                m.iUser_ID = Convert.ToInt32(dt.Rows[i][1]);
                m.sFirstName = dt.Rows[i][2].ToString();
                m.sLastName = dt.Rows[i][3].ToString();
                m.sPassword = dt.Rows[i][2].ToString();

                mFinal.Add(m);
            }

            return mFinal;
        }

    } 
}

Now when i compile this , it does not show me any Error, but when i test this service it gives me an Error that says

c:\Users\vuyo\AppData\Local\Temp\Test Client Projects\10.0\
f5c63a6e-fdb9-4b63-b7ff-11dcffe853ca\Client.cs(19,43) : 
error CS0426: The type name 'DAL' does not exist in the type 'DAL.DAL'

but when i remove this line in the interface it works, but i need this to be there

[OperationContract]
        List<LoginModel> GetLogins();

thanks

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by tinymark
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.