public List<ArticleModel> GetArticles(string strQuery) { ConnManager connManager = new ConnManager(); connManager.OpenConnection(); DataSet DSQuestions = new DataSet(); DSQuestions = connManager.GetData(strQuery); connManager.DisposeConn(); List<ArticleModel> articles = new List<ArticleModel>(); ArticleModel article; foreach (DataRow row in DSQuestions.Tables[0].Rows) { article = new ArticleModel(); article.ArticleID = row["ArticleID"].ToString(); article.ArticleTitle = row["ArticleTitle"].ToString(); article.InsertedDate = row["InsertedDate"].ToString(); article.ThumbsUp = row["ThumbsUp"].ToString(); article.ThumbsDown = row["ThumbsDown"].ToString(); article.Views = row["Views"].ToString(); articles.Add(article); } return articles; }
public ActionResult CreateEditUser(Users user, HttpPostedFileBase fileUserPhoto, string txtPassword) { string activationCode = Guid.NewGuid().ToString(); //AddEdit user if (Request.Form["Cancel"] == null) { if (ModelState.IsValid) { if (fileUserPhoto != null && fileUserPhoto.ContentLength > 1048576) { ViewBag.Ack = "Image file size should be less than 1 mb"; //return; } else { //try //{ ConnManager con = new ConnManager(); DataSet dsUser = con.GetData("Select * from Users where Email = '" + user.Email + "'"); con.DisposeConn(); if (dsUser.Tables[0].Rows.Count > 0) { ViewBag.Ack = "EMail id already exists. If you have forgotten password, please click forgot password link on the Sign In page."; return View("Users", user); } DataTable dtUserActivation = con.GetDataTable("select * from UserActivation where Email = '" + user.Email + "'"); if (dtUserActivation.Rows.Count > 0) { ViewBag.lblAck = "User activation pending"; ViewBag.Activation = "Resend Activation Code?"; return View("../Account/Login"); } double dblUserID = 0; SqlConnection LclConn = new SqlConnection(); SqlTransaction SetTransaction = null; bool IsinTransaction = false; if (LclConn.State != ConnectionState.Open) { user.SetConnection = user.OpenConnection(LclConn); SetTransaction = LclConn.BeginTransaction(IsolationLevel.ReadCommitted); IsinTransaction = true; } else { user.SetConnection = LclConn; } if (fileUserPhoto != null && fileUserPhoto.FileName != "") { try { string fileName = System.IO.Path.GetFileNameWithoutExtension(fileUserPhoto.FileName); string fileExt = System.IO.Path.GetExtension(fileUserPhoto.FileName); string fullFileName = System.IO.Path.GetFileName(fileUserPhoto.FileName); if (!System.IO.File.Exists(Server.MapPath("~\\Images\\") + fullFileName)) { fileUserPhoto.SaveAs(Server.MapPath("~\\Images\\") + fullFileName); } else { fullFileName = fileName + DateTime.Now.ToString("HHmmss") + fileExt; while (System.IO.File.Exists(fullFileName)) { fileName = fileName + DateTime.Now.ToString("HHmmss"); fullFileName = fileName + fileExt; } fileUserPhoto.SaveAs(Server.MapPath("~\\Images\\") + fullFileName); } user.ImageURL = "~/Images/" + fullFileName; } catch (Exception ex) { //ViewBag.Ack = "Please try again"; user.ImageURL = "~/Images/Person.JPG"; } } else { user.ImageURL = "~/Images/Person.JPG"; } user.OptionID = 1; user.CreatedDateTime = DateTime.Now; user.Password = txtPassword; bool result = user.CreateUsers(ref dblUserID, SetTransaction); if (IsinTransaction && result) { SetTransaction.Commit(); } else { SetTransaction.Rollback(); } using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCON"].ToString())) { using (SqlCommand cmd = new SqlCommand("INSERT INTO UserActivation VALUES(@UserId, @ActivationCode)")) { using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@UserId", dblUserID); cmd.Parameters.AddWithValue("@ActivationCode", activationCode); cmd.Connection = conn; conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); } } } user.CloseConnection(LclConn); //ViewBag.Ack = "User Registered Successfully. Please login."; ViewBag.Ack = "User Info Saved Successfully. An activation link has been sent to your email address, please check your inbox and activate your account"; //SendNewUserRegEMail(user.Email); SendActivationEMail(user.Email, activationCode); SendEMail(user.Email, user.FirstName, user.LastName); } Session["User"] = user; //return View("ViewUser", user); return Redirect("../Account/ViewUser"); } else { ViewBag.Ack = ModelState["ReCaptcha"].Errors[0].ErrorMessage; return View("Users", user); } } else { return View("Users", user); } }
//public ActionResult Google() //{ // return View(); //} public ActionResult ForgotPassword(string txtEMailId) { if (!string.IsNullOrEmpty(txtEMailId)) { ConnManager con = new ConnManager(); DataSet dsUser = con.GetData("Select * from Users where Email = '" + txtEMailId + "'"); con.DisposeConn(); if (dsUser.Tables[0].Rows.Count <= 0) { ViewBag.Ack = "No such EMail Id exists"; } DataTable dtUserActivation = con.GetDataTable("select * from UserActivation where Email = '" + txtEMailId + "'"); if (dtUserActivation.Rows.Count > 0) { ViewBag.Ack = "User activation pending"; ViewBag.Activation = "Resend Activation Code?"; return View("../Account/Login"); } if (!string.IsNullOrEmpty(dsUser.Tables[0].Rows[0]["Password"].ToString())) { Mail mail = new Mail(); mail.IsBodyHtml = true; string EMailBody = System.IO.File.ReadAllText(Server.MapPath("EMailBody.txt")); mail.Body = string.Format(EMailBody, "Your CodeAnalyze account password is " + dsUser.Tables[0].Rows[0]["Password"].ToString()); mail.FromAdd = "*****@*****.**"; mail.Subject = "Code Analyze account password"; mail.ToAdd = dsUser.Tables[0].Rows[0]["EMail"].ToString(); mail.SendMail(); ViewBag.Ack = "Password has been emailed to you, please check your email."; } else { ViewBag.Ack = "You have created your profile thorugh one of the social sites. Please use the same channel to login. Google Or Facebook"; } } return View(); }
private ActionResult CheckUserLogin(string txtEMailId, string txtPassword) { ConnManager connManager = new ConnManager(); connManager.OpenConnection(); DataTable DSUserList = new DataTable(); DataTable dtUserActivation = new DataTable(); if (!string.IsNullOrEmpty(txtPassword)) { DSUserList = connManager.GetDataTable("select * from users where email = '" + txtEMailId + "' and Password = '******'"); } else { DSUserList = connManager.GetDataTable("select * from users where email = '" + txtEMailId + "'"); } if (DSUserList.Rows.Count == 0) { ViewBag.lblAck = "Invalid login credentials, please try again"; return View("../Account/Login"); } else { dtUserActivation = connManager.GetDataTable("select * from UserActivation where UserId = " + double.Parse(DSUserList.Rows[0]["UserId"].ToString()) + " and Email = '" + txtEMailId + "'"); if (dtUserActivation.Rows.Count > 0) { ViewBag.lblAck = "User activation pending"; ViewBag.Activation = "Resend Activation Code?"; return View("../Account/Login"); } Users user = new Users(); user.UserId = double.Parse(DSUserList.Rows[0]["UserId"].ToString()); user.FirstName = DSUserList.Rows[0]["FirstName"].ToString(); user.LastName = DSUserList.Rows[0]["LastName"].ToString(); user.Email = DSUserList.Rows[0]["EMail"].ToString(); user.Address = DSUserList.Rows[0]["Address"].ToString(); user.ImageURL = DSUserList.Rows[0]["ImageURL"].ToString(); user.Password = DSUserList.Rows[0]["Password"].ToString(); user.ImageURL = user.ImageURL.Replace("~", ""); user.ImageURL = user.ImageURL.Replace("/CodeAnalyzeMVC2015", ""); DataSet dsQuestions = new DataSet(); DataSet dsAnswers = new DataSet(); DataSet dsArticles = new DataSet(); dsQuestions = connManager.GetData("Select Count(*) from Question where AskedUser = "******""); if (dsQuestions.Tables.Count > 0 && dsQuestions.Tables[0].Rows.Count > 0) user.QuestionsPosted = dsQuestions.Tables[0].Rows[0][0].ToString(); dsAnswers = connManager.GetData("Select Count(*) from Replies where RepliedUser = "******""); if (dsAnswers.Tables.Count > 0 && dsAnswers.Tables[0].Rows.Count > 0) user.AnswersPosted = dsAnswers.Tables[0].Rows[0][0].ToString(); dsArticles = connManager.GetData("Select Count(*) from CodeArticles where UserId = " + user.UserId + ""); if (dsArticles.Tables.Count > 0 && dsArticles.Tables[0].Rows.Count > 0) user.ArticlesPosted = dsArticles.Tables[0].Rows[0][0].ToString(); else user.ArticlesPosted = "0"; user.Details = DSUserList.Rows[0]["Details"].ToString(); Session["User"] = user; Session["user.Email"] = user.Email; ViewBag.UserEmail = user.Email; connManager.DisposeConn(); return View("../Account/ViewUser", user); } }
public ActionResult EditUser(Users user, HttpPostedFileBase fileUserPhoto) { //AddEdit user if (Request.Form["Cancel"] == null) { if (ModelState.IsValid) { if (fileUserPhoto != null && fileUserPhoto.ContentLength > 1048576) { ViewBag.Ack = "Image file size should be less than 1 mb"; //return; } else { //try //{ ConnManager con = new ConnManager(); DataSet dsUser = con.GetData("Select * from Users where Email = '" + user.Email + "'"); con.DisposeConn(); if (dsUser.Tables[0].Rows.Count > 0) { //if (Session["User"] == null) //{ // ViewBag.Ack = "EMail id already exists. If you have forgotten password, please click forgot password link on the Sign In page."; // //return; //} user.UserId = double.Parse(dsUser.Tables[0].Rows[0]["UserId"].ToString()); } double dblUserID = 0; SqlConnection LclConn = new SqlConnection(); SqlTransaction SetTransaction = null; bool IsinTransaction = false; if (LclConn.State != ConnectionState.Open) { user.SetConnection = user.OpenConnection(LclConn); SetTransaction = LclConn.BeginTransaction(IsolationLevel.ReadCommitted); IsinTransaction = true; } else { user.SetConnection = LclConn; } if (fileUserPhoto != null && fileUserPhoto.FileName != "") { try { string fileName = System.IO.Path.GetFileNameWithoutExtension(fileUserPhoto.FileName); string fileExt = System.IO.Path.GetExtension(fileUserPhoto.FileName); string fullFileName = System.IO.Path.GetFileName(fileUserPhoto.FileName); if (!System.IO.File.Exists(Server.MapPath("~\\Images\\") + fullFileName)) { fileUserPhoto.SaveAs(Server.MapPath("~\\Images\\") + fullFileName); } else { fullFileName = fileName + DateTime.Now.ToString("HHmmss") + fileExt; while (System.IO.File.Exists(fullFileName)) { fileName = fileName + DateTime.Now.ToString("HHmmss"); fullFileName = fileName + fileExt; } fileUserPhoto.SaveAs(Server.MapPath("~\\Images\\") + fullFileName); } user.ImageURL = "~/Images/" + fullFileName; } catch (Exception ex) { //ViewBag.Ack = "Please try again"; user.ImageURL = "~/Images/Person.JPG"; } user.OptionID = 5; } else { user.OptionID = 7; Users tempUser = new CodeAnalyzeMVC2015.Users(); tempUser = (Users)Session["User"]; user.ImageURL = tempUser.ImageURL; } user.ModifiedDateTime = DateTime.Now; dblUserID = user.UserId; bool result = user.CreateUsers(ref dblUserID, SetTransaction); if (IsinTransaction && result) { SetTransaction.Commit(); } else { SetTransaction.Rollback(); } user.CloseConnection(LclConn); ViewBag.Ack = "User Updated Successfully."; //} //catch //{ //} } Session["User"] = user; //return View("ViewUser", user); return Redirect("../Account/ViewUser"); } else { user = (Users)Session["User"]; return View("../Account/ViewUser", user); } } else { user = (Users)Session["User"]; return View("../Account/ViewUser", user); } }