Example #1
0
        public resultset Register([FromBody] Users user)
        {
            resultset result = new resultset();

            result.data = user;
            try
            {
                connection();

                SqlCommand cmd = new SqlCommand("insertUser", con)
                {
                    CommandType = CommandType.StoredProcedure
                };

                cmd.Parameters.AddWithValue("@phone", user.phone);
                cmd.Parameters.AddWithValue("@name", user.name);
                cmd.Parameters.AddWithValue("@email", user.email);
                cmd.Parameters.AddWithValue("@pass", user.pass);

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

                result.isSuccess = true;
                result.data      = "";
                result.message   = "Inserted Successfully.";
            }
            catch (Exception ex)
            {
                result.isSuccess        = false;
                result.exceptionMessage = ex.Message;
            }
            return(result);
        }
Example #2
0
        public resultset loginUser([FromBody] Users user)
        {
            resultset    result    = new resultset();
            List <Users> usersList = new List <Users>();

            try
            {
                connection();
                SqlCommand cmd = new SqlCommand()
                {
                    CommandType = CommandType.StoredProcedure,
                    CommandText = "loginUser"
                };

                cmd.Connection = con;
                //cmd.CommandText = "loginUser";
                //cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@email", user.email);
                //cmd.Parameters.AddWithValue("@pass", user.pass);

                DataTable dt = new DataTable();
                con.Open();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                con.Close();

                da.Fill(dt);

                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        Users u = new Users()
                        {
                            id    = Convert.ToInt32(dr["id"]),
                            name  = Convert.ToString(dr["name"]),
                            phone = Convert.ToString(dr["phone"]),
                            email = Convert.ToString(dr["email"]),
                            pass  = Convert.ToString(dr["pass"])
                        };
                        usersList.Add(u);
                    }

                    result.isSuccess = true;
                    result.data      = usersList;
                    result.message   = "User Found";
                }
                else
                {
                    result.isSuccess = false;
                    result.data      = "";
                    result.message   = "User Not Found";
                }
            }
            catch (Exception ex)
            {
                result.isSuccess        = false;
                result.exceptionMessage = ex.Message;
            }
            return(result);
        }
Example #3
0
        public resultset Get()
        {
            resultset result = new resultset();

            List <Users> usersList = new List <Users>();

            try
            {
                connection();

                SqlCommand cmd = new SqlCommand("getAllUsers", con);
                cmd.CommandType = CommandType.StoredProcedure;
                con.Open();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                con.Close();
                DataTable dt = new DataTable();
                da.Fill(dt);

                foreach (DataRow dr in dt.Rows)
                {
                    Users user = new Users()
                    {
                        id    = Convert.ToInt32(dr["id"]),
                        name  = Convert.ToString(dr["name"]),
                        phone = Convert.ToString(dr["phone"]),
                        email = Convert.ToString(dr["email"]),
                        //pass = Convert.ToString(dr["pass"])
                    };
                    usersList.Add(user);
                }

                result.isSuccess = true;
                result.data      = usersList;
            }
            catch (Exception ex)
            {
                result.isSuccess        = false;
                result.exceptionMessage = ex.Message;
            }
            return(result);
        }