// GET: api/FromName public IHttpActionResult Get() { string returnValue = string.Empty; ReturnStatus returnStatus = new ReturnStatus(); FromUserData fromUserData = new FromUserData(); returnStatus = fromUserData.GetCurrentUserName(); if (returnStatus.StatusText == "OK") { return Ok(returnStatus); } else { return BadRequest(returnStatus.ErrorMessage); } }
// POST: api/FromName public IHttpActionResult Post([FromBody]From fromName) { ReturnStatus returnStatus = new ReturnStatus(); FromUserData fromUserData = new FromUserData(); returnStatus = fromUserData.UpdateFromName(fromName.FromName); if (returnStatus.Status) { return Ok(); } else { return BadRequest(returnStatus.ErrorMessage); } }
public ReturnStatus CheckRegistrationStatus(string email) { int count = 0; List<User> userList = new List<User>(); ReturnStatus returnStatus = new ReturnStatus(); try { using (IDbConnection db = new MySqlConnection(ConfigurationValues.GroveHillConnection)) { const string query = "select * from users where username = @username"; userList = db.Query<User>(query, new { @username = email }).ToList(); if(userList.Count > 0) //if (userList.Count > 0) { returnStatus.Status = true; returnStatus.AdditionalInformation = GetFirstPassword(email); return returnStatus; } else { returnStatus.Status = false; returnStatus.AdditionalInformation = string.Empty; return returnStatus; } } } catch (Exception er) { returnStatus.Status = false; returnStatus.AdditionalInformation = string.Empty; return returnStatus; } }
public ReturnStatus GetCurrentUserName() { string fromName = string.Empty; ReturnStatus returnStatus = new ReturnStatus(); try { using (IDbConnection db = new SqlConnection(ConfigurationValues.WaldenFaxConnection)) { //const string query = "SELECT [ID],[UserName],[FromName]" const string query = "SELECT [FromName]" + "FROM [FromName]" + " where [UserName] = @UserName"; fromName = db.Query<string>(query, new { @UserName = Utility.GetUserName() }).SingleOrDefault(); returnStatus.AdditionalInformation = fromName; returnStatus.Status = true; returnStatus.ErrorMessage = "None"; returnStatus.StatusText = "OK"; return returnStatus; } } catch (Exception er) { returnStatus.AdditionalInformation = "None"; returnStatus.Status = false; returnStatus.ErrorMessage = er.ToString(); returnStatus.StatusText = "None"; return returnStatus; } }
public ReturnStatus UpdateFromName(string newFromName) { int count = 0; ReturnStatus returnStatus = new ReturnStatus(); try { using (IDbConnection db = new SqlConnection(ConfigurationValues.WaldenFaxConnection)) { const string query = "SELECT count(ID)" + "FROM [FromName]" + " where [UserName] = @UserName"; count = db.Query<int>(query, new { @UserName = Utility.GetUserName() }).SingleOrDefault(); } if (count > 0) { using (IDbConnection db = new SqlConnection(ConfigurationValues.WaldenFaxConnection)) { const string query = "update FromName" + " set FromName = @FromName" + " where username = @username"; int rowsAffectd = db.Execute(query, new { @FromName = newFromName, @username = Utility.GetUserName() }); int r = 5; returnStatus.Status = true; returnStatus.ErrorMessage = "None"; returnStatus.StatusText = "OK"; return returnStatus; } } else { using (IDbConnection db = new SqlConnection(ConfigurationValues.WaldenFaxConnection)) { const string query = "insert into FromName" + "(UserName,FromName)" + "values(@UserName,@FromName)"; int rowsAffectd = db.Execute(query, new { @FromName = newFromName, @username = Utility.GetUserName() }); int r = 5; returnStatus.Status = true; returnStatus.ErrorMessage = "None"; returnStatus.StatusText = "OK"; return returnStatus; } } } catch (Exception er) { returnStatus.Status = false; returnStatus.ErrorMessage = er.ToString(); returnStatus.StatusText = "Error"; return returnStatus; } }