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();
}
}
}
No comments:
Post a Comment