public string AddUser(User user) { var checkUser = GetUser(user.Zid); if (checkUser == null) return "User Already Exists"; var insertUser = new SqlCommand(@"INSERT INTO [dbo].[Ks_User] ([ZID], [First_Name], [Last_Name], [Email],[Password]) VALUES (@zid, @firstMan, @lastName, @email,@password)", _connection); insertUser.Parameters.AddWithValue("@zid", user.Zid); insertUser.Parameters.AddWithValue("@firstMan", user.FirstName); insertUser.Parameters.AddWithValue("@lastName", user.LastName); insertUser.Parameters.AddWithValue("@email", user.Email); insertUser.Parameters.AddWithValue("@password", user.Password); _connection.Open(); insertUser.ExecuteNonQuery(); _connection.Close(); try { SendEmail(user); } catch (Exception ex) { Console.WriteLine(ex); } return "Successfully Added User"; }
public User GetUser(string zid) { // var testInsert = new SqlCommand(@"INSERT INTO [dbo].[Ks_User] ([ZID], [First_Name], [Last_Name], [Email]) // VALUES ('Z123456', 'Test', 'Test', '*****@*****.**')", _connection); var selectUser = new SqlCommand(@"SELECT * FROM [dbo].[Ks_User] where ZID = @zid", _connection); selectUser.Parameters.AddWithValue("@zid", zid); _connection.Open(); var userObject = selectUser.ExecuteReader(); var user = new User(); while (userObject.Read()) { user = new User() { Zid = userObject["ZID"].ToString(), Password = userObject["Password"].ToString(), FirstName = userObject["First_Name"].ToString(), LastName = userObject["Last_Name"].ToString(), Email = userObject["Email"].ToString() }; } _connection.Close(); return user; }
private static void SendEmail(User user) { var from = new MailAddress("*****@*****.**", "KnowledgeShare"); var to = new MailAddress(user.Email); var mail = new MailMessage(from, to) { Subject = "Welcome To KnowledgeShare", Body = "You have been successfully registered in Knowledge Share" }; var ms = new SmtpClient("smtpcorp.com") { Credentials = new NetworkCredential("*****@*****.**", "lucky_123"), Port = 2525 }; ms.Send(mail); }