//private static RijndaelCrypt rC = new RijndaelCrypt("ambiabhhm2883772"); public static ModelResult <List <DTO.Account.UserAccounts> > UserLogin(DTO.Account.LoginModel oUserAccount) { using (SqlConnection conn = new SqlConnection(DbConnection.ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = conn; //var command = @"select * from MD_Media where isDeleted = 0 "; var command = @"select a.*, t.Name As UserTypeName from dbo.UserAccounts a join UserType t On a.UserTypeId = t.Id WHERE (a.Email=@Email OR a.Name=@Email OR a.Mobile=@Email) and Pass=@Pass COLLATE SQL_Latin1_General_CP1_CS_AS"; if (!string.IsNullOrEmpty(oUserAccount.Email)) { cmd.Parameters.AddWithValue("@Email", oUserAccount.Email); } if (!string.IsNullOrEmpty(oUserAccount.Password)) { cmd.Parameters.AddWithValue("@Pass", Common.Md5(oUserAccount.Password)); } //if (!string.IsNullOrEmpty(oUserAccount.Password)) //{ // cmd.Parameters.AddWithValue("@Pass", oUserAccount.Password); //} cmd.CommandText = command; conn.Open(); var reader = cmd.ExecuteReader(); var lstUserAccount = new List <DTO.Account.UserAccounts>(); var oResult = new ModelResult <List <DTO.Account.UserAccounts> >(); if (reader.HasRows) { while (reader.Read()) { var opUserAccount = new DTO.Account.UserAccounts(); if (reader["Avatar"] != DBNull.Value) { opUserAccount.Avatar = Convert.ToString(reader["Avatar"]); } if (reader["Email"] != DBNull.Value) { opUserAccount.Email = Convert.ToString(reader["Email"]); } if (reader["Gender"] != DBNull.Value) { opUserAccount.Gender = Convert.ToString(reader["Gender"]); } opUserAccount.Id = Convert.ToInt32(reader["Id"]); if (reader["IsActive"] != DBNull.Value) { opUserAccount.IsActive = Convert.ToBoolean(reader["IsActive"]); } if (reader["IsDeleted"] != DBNull.Value) { opUserAccount.IsDeleted = Convert.ToBoolean(reader["IsDeleted"]); } if (reader["Mobile"] != DBNull.Value) { opUserAccount.Mobile = Convert.ToString(reader["Mobile"]); } if (reader["UserTypeId"] != DBNull.Value) { opUserAccount.UserTypeId = Convert.ToInt32(reader["UserTypeId"]); } if (reader["Name"] != DBNull.Value) { opUserAccount.Name = Convert.ToString(reader["Name"]); } if (reader["Pass"] != DBNull.Value) { opUserAccount.Pass = Convert.ToString(reader["Pass"]); } if (reader["EmailPassword"] != DBNull.Value) { opUserAccount.EmailPassword = Convert.ToString(reader["EmailPassword"]); } opUserAccount.ManagerGroupId = Convert.ToInt32(reader["ManagerGroupId"]); if (reader["TraceUserActivity"] != DBNull.Value) { opUserAccount.TraceUserActivity = Convert.ToBoolean(reader["TraceUserActivity"]); } //if (reader["BenId"] != DBNull.Value) // opUserAccount.BenId = Convert.ToInt32(reader["BenId"]); //if (reader["BenTypeId"] != DBNull.Value) // opUserAccount.BenTypeId = Convert.ToInt32(reader["BenTypeId"]); lstUserAccount.Add(opUserAccount); } } if (lstUserAccount.Count > 0) { oResult.HasResult = true; oResult.Results = lstUserAccount; //oResult.RowCount = count; } return(oResult); } } }
//private static RijndaelCrypt rC = new RijndaelCrypt("ambiabhhm2883772"); public static ModelResult <List <DTO.News.Visitors> > VisitorLogin(DTO.Account.LoginModel oVisitor) { using (SqlConnection conn = new SqlConnection(DbConnection.ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = conn; //var command = @"select * from MD_Media where isDeleted = 0 "; var command = @"select * from dbo.Visitors a WHERE (Email=@Email OR Name=@Email) and Pass=@Pass COLLATE SQL_Latin1_General_CP1_CS_AS AND IsApproved=1"; if (!string.IsNullOrEmpty(oVisitor.Email)) { cmd.Parameters.AddWithValue("@Email", oVisitor.Email); } if (!string.IsNullOrEmpty(oVisitor.Password)) { cmd.Parameters.AddWithValue("@Pass", Common.Md5(oVisitor.Password)); } cmd.CommandText = command; conn.Open(); var reader = cmd.ExecuteReader(); var lstVisitor = new List <DTO.News.Visitors>(); var oResult = new ModelResult <List <DTO.News.Visitors> >(); if (reader.HasRows) { while (reader.Read()) { var opVisitor = new DTO.News.Visitors(); if (reader["Avatar"] != DBNull.Value) { opVisitor.Avatar = Convert.ToString(reader["Avatar"]); } if (reader["Email"] != DBNull.Value) { opVisitor.Email = Convert.ToString(reader["Email"]); } opVisitor.Id = Convert.ToInt32(reader["Id"]); if (reader["Name"] != DBNull.Value) { opVisitor.Name = Convert.ToString(reader["Name"]); } if (reader["Pass"] != DBNull.Value) { opVisitor.Pass = Convert.ToString(reader["Pass"]); } if (reader["IsApproved"] != DBNull.Value) { opVisitor.IsApproved = Convert.ToBoolean(reader["IsApproved"]); } lstVisitor.Add(opVisitor); } } if (lstVisitor.Count > 0) { oResult.HasResult = true; oResult.Results = lstVisitor; //oResult.RowCount = count; } return(oResult); } } }