#region Data Mamber
VisitingThereEntities context = null;
#endregion
#region Cont'r
public RpUser()
{
context = new VisitingThereEntities();
}
#endregion
#region Clean Session Manager
/// <summary>
/// clean session manager after click change password
/// and fore to re-login into the system.
/// </summary>
/// <param name="obj"></param>
public void Logout()
{
SessionManager.userClearSession();
//SessionManager.clearSession();
SessionManager.userid = 0;
SessionManager.userEmail = null;
SessionManager.userName = null;
SessionManager.userType = null;
}
#endregion
#region Set Session Manager
/// <summary>
/// set session Manager details after login.
/// </summary>
private void SetSessionManager(User obj)
{
SessionManager.userid = obj.UserId;
SessionManager.userEmail = obj.EmailId;
SessionManager.userName = obj.FirstName;
SessionManager.userType = obj.Type;
}
#endregion
#region Login
public UserViewModel Login(string emailId, string password)
{
var obj = context.Users.FirstOrDefault(u => u.EmailId == emailId && u.Password == password);
if (obj != null)
{
//UserViewModel data = new UserViewModel()
UserViewModel data = new UserViewModel()
{
EmailId = obj.EmailId,
FirstName = obj.FirstName,
LastName = obj.LastName,
password = obj.Password,
UserId = obj.UserId,
Type = obj.Type
};
SetSessionManager(obj);
return data;
}
else return null;
}
public UserViewModel UserAdd(UserViewModel obj)
{
User con = new User();
//con.UserName = obj.UserName;
con.FirstName = obj.FirstName;
con.LastName = obj.LastName;
//con.Type = obj.Type;
con.EmailId = obj.EmailId;
con.Password = obj.password;
con.NewPassword = obj.NewPassword;
con.ConformPassword = obj.confirmPassword;
con.AgeId = obj.AgeId;
con.Type = obj.Type;
context.Users.AddObject(con);
context.SaveChanges();
obj.FirstName = con.FirstName;
obj.LastName = con.LastName;
obj.EmailId = con.EmailId;
obj.password = con.Password;
return obj;
}
#endregion