using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
public enum Roles : int
{
Administrator = 1,
Standard = 2
}
/// <summary>
/// Summary description for User
/// </summary>
public class User
{
public Roles Role { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public int UserId { get; set; }
public User()
{
//
// TODO: Add constructor logic here
//
}
public void Save()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["bluelobsterConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("up_user_save",con);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add("@password", System.Data.SqlDbType.VarChar).Value = Password;
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch(SqlException sqlEx)
{
}
finally
{
con.Close();
}
}
public void Retrieve()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["bluelobsterConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("up_user_retrieve",con);
SqlDataReader dr = null;
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add("@user_id", System.Data.SqlDbType.VarChar).Value = UserId;
cmd.Parameters.Add("@username", System.Data.SqlDbType.VarChar).Value = Username;
cmd.Parameters.Add("@password", System.Data.SqlDbType.VarChar).Value = Password;
try
{
con.Open();
dr = cmd.ExecuteReader();
dr.Read();
Password = dr["password"].ToString();
Username = dr["username"].ToString();
UserId = int.Parse(dr["user_id"].ToString());
Role = (Roles)dr["role_id"];
}
catch (SqlException sqlEx)
{
}
finally
{
con.Close();
}
}
}
Tuesday, May 17, 2011
MySession
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for MySession
/// </summary>
public class MySession
{
// private constructor
private MySession() { }
// Gets the current session.
public static MySession Current
{
get
{
MySession session =
(MySession)HttpContext.Current.Session["__MySession__"];
if (session == null)
{
session = new MySession();
HttpContext.Current.Session["__MySession__"] = session;
}
return session;
}
}
public static void Clear()
{
MySession session =
(MySession)HttpContext.Current.Session["__MySession__"];
if (session != null)
{
HttpContext.Current.Session.Remove("__MySession__");
}
}
// **** add your session properties here, e.g like this:
public User User { get; set; }
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for MySession
/// </summary>
public class MySession
{
// private constructor
private MySession() { }
// Gets the current session.
public static MySession Current
{
get
{
MySession session =
(MySession)HttpContext.Current.Session["__MySession__"];
if (session == null)
{
session = new MySession();
HttpContext.Current.Session["__MySession__"] = session;
}
return session;
}
}
public static void Clear()
{
MySession session =
(MySession)HttpContext.Current.Session["__MySession__"];
if (session != null)
{
HttpContext.Current.Session.Remove("__MySession__");
}
}
// **** add your session properties here, e.g like this:
public User User { get; set; }
}
Subscribe to:
Posts (Atom)