public string Checkdata_req(Cms_User cmsuser) { string useremail, phoneno; useremail = cmsuser.User_Email; phoneno = cmsuser.User_Phoneno; SqlCommand cmd = con.CreateCommand(); cmd.CommandText = "Select * from Cms_User Where User_Email=@useremail and User_Phoneno=@phoneno"; cmd.Parameters.AddWithValue("@useremail", useremail); cmd.Parameters.AddWithValue("@phoneno", phoneno); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); con.Open(); da.Fill(ds); con.Close(); if (ds.Tables[0].Rows.Count != 0) { return("email and phoneno already exists"); } return("User succcess"); }
public bool Addnewuser(Cms_User cms_user) { string username, useremail, phoneno, dob, gender, password, status, regdate; try { con.Open(); SqlTransaction trans = con.BeginTransaction(); try { username = cms_user.User_Name; useremail = cms_user.User_Email; phoneno = cms_user.User_Phoneno; dob = cms_user.User_Dob.ToString(); gender = cms_user.User_Gender; password = cms_user.User_Password; status = cms_user.User_Type; regdate = cms_user.User_Registerdatetime.ToString(); SqlCommand dbcmd = con.CreateCommand(); dbcmd.Transaction = trans; dbcmd.CommandText = "insert into Cms_User(User_Name,User_Email,User_Phoneno,User_Dob,User_Gender,User_Password,User_Type,User_Registerdatetime) Values(@username,@useremail,@phoneno,@dob,@gender,@password,@status,@registerdatetime)"; dbcmd.Parameters.AddWithValue("@username", username); dbcmd.Parameters.AddWithValue("@useremail", useremail); dbcmd.Parameters.AddWithValue("@phoneno", phoneno); dbcmd.Parameters.AddWithValue("@dob", dob); dbcmd.Parameters.AddWithValue("@gender", gender); dbcmd.Parameters.AddWithValue("@password", password); dbcmd.Parameters.AddWithValue("@status", status); dbcmd.Parameters.AddWithValue("@registerdatetime", regdate); dbcmd.ExecuteNonQuery(); trans.Commit(); con.Close(); return(true); } catch (Exception ex) { trans.Rollback(); con.Close(); return(false); } } catch { return(false); } }
public ActionResult Register(Cms_User cms_user) { if (ModelState.IsValid) { cms_user.User_Type = "User"; cms_user.User_Registerdatetime = Convert.ToDateTime(DateTime.Now.ToLongTimeString()); string a = qh.Checkdata_req(cms_user); if (a == "email and phoneno already exists") { ViewBag.message = "User Email and phoneno is already exists"; } else { MailMessage mail = new MailMessage(); mail.To.Add(cms_user.User_Email); mail.From = new MailAddress("*****@*****.**"); mail.Subject = "<b>HAccount creation<b>"; string Body = "<b>Hello <b>" + cms_user.User_Name + "<b><br/><br/>"; Body += "Your account is successfully created for the CMS system"; Body += "<br/>Your UserName and Password here:-<br/><br/>"; Body += "<br/>UserName= <b>" + cms_user.User_Email + "<br/><br/>"; Body += "<br/>Password = <b>" + cms_user.User_Password + "<br/><br/>"; Body += "<br/>Thanks"; mail.Body = Body; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "7976862730@umang"); // Enter seders User name and password smtp.EnableSsl = true; smtp.Send(mail); qh.Addnewuser(cms_user); ModelState.Clear(); } } else { ViewBag.Error = "Something went wrong"; } ViewBag.Success = "Successfully register for Cms system!! "; return(View()); }