|
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.
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!)