Click here to Skip to main content
15,885,914 members
Articles / Web Development / ASP.NET

Custom Membership Providers - Task Manager

Rate me:
Please Sign up or sign in to vote.
4.17/5 (5 votes)
9 Apr 2011CPOL5 min read 55.9K   2K   47  
This article extends what was built in the previous article. This is a task manager application that uses the custom provider designed in the last part.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Linq;
using System.Configuration;

namespace CustomMembership.Models
{
    public class User
    {
        private Table<UserObj> usersTable;
        private DataContext context;

        public User()
        {
            string connectionString = ConfigurationManager.ConnectionStrings["AppDb"].ConnectionString;
            context = new DataContext(connectionString);
            usersTable = context.GetTable<UserObj>();
        }

        public UserObj GetUserObjByUserName(string userName, string passWord)
        {
            UserObj user = usersTable.SingleOrDefault(u => u.UserName == userName && u.Password == passWord);
            return user;
        }

        public int GetUserIDByUsername(string userName)
        {
            UserObj userObj = usersTable.SingleOrDefault(u => u.UserName == userName);
            if (userObj != null)
                return userObj.UserID;
            return -1;
        }

        public UserObj GetUserObjByUserName(string userName)
        {
            UserObj user = usersTable.SingleOrDefault(u => u.UserName == userName);
            return user;
        }

        public IEnumerable<UserObj> GetAllUsers()
        {
            return usersTable.AsEnumerable();
        }

        public int RegisterUser(UserObj userObj)
        {
            UserObj user = new UserObj();
            user.UserName = userObj.UserName;
            user.Password = userObj.Password;
            user.UserEmailAddress = userObj.UserEmailAddress;

            usersTable.InsertOnSubmit(user);
            context.SubmitChanges();

            return user.UserID;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
Just another passionate software developer!

Some of the contributions to the open source world - a blog engine written in MVC 4 - sBlog.Net. Check it out here. For the codeproject article regarding sBlog.Net click here!

(Figuring out this section!)

Comments and Discussions