public string Login([FromBody] Login details) { string returnValue = ""; string connString = ConfigurationManager.ConnectionStrings["SQLConString"].ToString(); IDBFamily family = new DBFamily(); var dbFamilyResult = family.GetQueryBuilder(DbFamilyConstants.MSSQL); var checkIfUsersExistsQuery = string.Format("select count(1) from NewUsers where UserName='******'", details.UserName); int count = dbFamilyResult.ExecuteScalar(checkIfUsersExistsQuery, connString); if (count > 0) { var query = string.Format("select count(1) from NewUsers where UserName='******' and Password='******'", details.UserName, details.Password); int result = dbFamilyResult.ExecuteScalar(query, connString); if (result > 0) { returnValue = "Success"; } else { returnValue = "Invalid password"; } } else { returnValue = "User doesnt exists"; } return(returnValue); }
public void Register([FromBody] Register details) { string connString = ConfigurationManager.ConnectionStrings["SQLConString"].ToString(); IDBFamily family = new DBFamily(); var dbFamilyResult = family.GetQueryBuilder(DbFamilyConstants.MSSQL); List <KeyValuePair <string, KeyValuePair <SqlDbType, object> > > inOutParams = new List <KeyValuePair <string, KeyValuePair <SqlDbType, object> > >(); inOutParams.Add(new KeyValuePair <string, KeyValuePair <SqlDbType, object> >("UserName", new KeyValuePair <SqlDbType, object>(SqlDbType.NVarChar, details.FirstName + "." + details.LastName))); inOutParams.Add(new KeyValuePair <string, KeyValuePair <SqlDbType, object> >("Password", new KeyValuePair <SqlDbType, object>(SqlDbType.NVarChar, details.Password))); inOutParams.Add(new KeyValuePair <string, KeyValuePair <SqlDbType, object> >("EmailId", new KeyValuePair <SqlDbType, object>(SqlDbType.NVarChar, details.EmailId))); inOutParams.Add(new KeyValuePair <string, KeyValuePair <SqlDbType, object> >("FirstName", new KeyValuePair <SqlDbType, object>(SqlDbType.NVarChar, details.FirstName))); inOutParams.Add(new KeyValuePair <string, KeyValuePair <SqlDbType, object> >("LastName", new KeyValuePair <SqlDbType, object>(SqlDbType.NVarChar, details.LastName))); inOutParams.Add(new KeyValuePair <string, KeyValuePair <SqlDbType, object> >("IsActive", new KeyValuePair <SqlDbType, object>(SqlDbType.Bit, 1))); dbFamilyResult.ExecuteQuery("insert into NewUsers values(@UserName,@Password,@EmailId,@FirstName,@LastName,@IsActive)", connString, inOutParams); }
public List <UserDetails> GetUserDetails() { string conn = ConfigurationManager.ConnectionStrings["SQLConString"].ConnectionString; List <UserDetails> result = new List <UserDetails>(); IDBFamily dbFamily = new DBFamily(); var dbFamilyResult = dbFamily.GetQueryBuilder(DbFamilyConstants.MSSQL); var dataSet = dbFamilyResult.ExecuteCommand("select * from UserDetails", conn); if (dataSet != null && dataSet.Tables != null) { var dt = dataSet.Tables[0]; if (dt.Rows.Count > 0) { result = dt.DataTableToList <UserDetails>(); } } return(result); }