public ActionResult ForgotPassword(string EmailID) { //Verify the emailid //Generate Reset Password Link //Send Email string message = ""; bool status = false; using (PostEntity pe = new PostEntity()) { var account = pe.Subscriber_Table.Where(x => x.email == EmailID).FirstOrDefault(); if (account != null) { //Send email for reset password string resetCode = Guid.NewGuid().ToString(); SendVerificationLinkEmail(account.email, resetCode, "ResetPassword"); account.ResetPasswordCode = resetCode; pe.Configuration.ValidateOnSaveEnabled = false; pe.SaveChanges(); message = "Reset Password Link has been sent to your Email ID"; } else { message = "Account Not Found"; } } ViewBag.Message = message; return(View()); }
public ActionResult ResetPassword(ResetPasswordModel model) { var message = ""; if (ModelState.IsValid) { using (PostEntity pe = new PostEntity()) { var user = pe.Subscriber_Table.Where(x => x.ResetPasswordCode == model.ResetCode).FirstOrDefault(); if (user != null) { user.password = Crypto.Hash(model.NewPassword); user.ResetPasswordCode = ""; pe.Configuration.ValidateOnSaveEnabled = false; pe.SaveChanges(); message = "New password updated successfully"; } } } else { message = "Something invalid"; } ViewBag.Message = message; return(View(model)); }
public ActionResult Create(Post_Table post, Article article, Comment comment) { try { using (PostEntity pe = new PostEntity()) { DomainTech.DomainTechService dt = new DomainTech.DomainTechService(); List <Domain_Table> DomainList = dt.GetDomainList(); ViewBag.DomainList = new SelectList(DomainList, "did", "domain"); pe.Configuration.ProxyCreationEnabled = false; List <Technology_Table> TechnologyList = dt.GetTechforDomain(post.domain); ViewBag.TechnologyList = new SelectList(TechnologyList, "tid", "technology"); //Get the Domain ID int did = Convert.ToInt32(article.Post.domain); //Get the Technology ID int tid = Convert.ToInt32(article.Post.technology); DomainTechEntity dte = new DomainTechEntity(); //Convert the Domain ID to Domain Name var d = dte.Domain_Table.Where(x => x.did == did).FirstOrDefault(); post.domain = d.domain; //Convert the Technology ID to Technology Name var t = dte.Technology_Table.Where(x => x.tid == tid).FirstOrDefault(); post.technology = t.technology; //Check for same title int count = pe.Post_Table.Where(x => x.title == article.Post.title && x.category == true).Count(); if (count > 0) { ViewBag.ErrorMessage = "Please modify the TITLE, Article found with same TITLE"; return(View(article)); } else { post.title = article.Post.title; post.tags = article.Post.tags; post.content_ = article.Post.content_; post.date = DateTime.Now; post.category = true; post.userid = Session["userid"].ToString(); ViewData["Article"] = post; pe.Post_Table.Add(post); pe.SaveChanges(); return(View("ResultView")); } } } catch { return(View()); } }
public ActionResult DeletePost(int id, FormCollection form) { try { using (PostEntity pe = new PostEntity()) { Post_Table post = pe.Post_Table.Where(x => x.postid == id).FirstOrDefault(); pe.Post_Table.Remove(post); pe.SaveChanges(); } return(RedirectToAction("ManageUser")); } catch { return(View()); } }
public ActionResult EditPost(int id, Post_Table post) { StreamWriter stream = null; DomainTech.DomainTechService dt = new DomainTech.DomainTechService(); List <DomainTech.Domain_Table> DomainList = dt.GetDomainList(); ViewBag.DomainList = new SelectList(DomainList, "did", "domain"); try { using (PostEntity pe = new PostEntity()) { //Get all the values of article/blog var postvalues = pe.Post_Table.Where(x => x.postid == id).FirstOrDefault(); //set all the values post.postid = postvalues.postid; post.date = postvalues.date; post.category = postvalues.category; post.userid = postvalues.userid; int did = Convert.ToInt32(post.domain); int tid = Convert.ToInt32(post.technology); DomainTechEntity dte = new DomainTechEntity(); var d = dte.Domain_Table.Where(x => x.did == did).FirstOrDefault(); post.domain = d.domain; var t = dte.Technology_Table.Where(x => x.tid == tid).FirstOrDefault(); post.technology = t.technology; post.userid = Session["userid"].ToString(); ViewData["Article"] = post; pe.Post_Table.AddOrUpdate(post); pe.SaveChanges(); } return(View("../Post/ResultView")); } catch (Exception e) { stream = new StreamWriter(@"D:/EditException.txt"); stream.WriteLine(e); stream.Close(); return(View()); } }
public ActionResult VerifyAccount(string id) { bool Status = false; using (PostEntity pe = new PostEntity()) { pe.Configuration.ValidateOnSaveEnabled = false; //This line is added to avoid //confirm password does not match issue var v = pe.Subscriber_Table.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault(); if (v != null) { v.IsEmailVerified = true; pe.SaveChanges(); Status = true; } else { ViewBag.Message = "Invalid Request"; } } ViewBag.Status = Status; return(View()); }
public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode")] Subscriber_Table subscriber) { bool Status = false; string message = ""; StreamWriter stream = null; //Model Validation if (ModelState.IsValid) { #region Email is already existing var isExist = IsEmailExist(subscriber.email); if (isExist) { ModelState.AddModelError("EmailExist", "Email already exist"); return(View(subscriber)); } #endregion #region Activation Code Generation subscriber.ActivationCode = Guid.NewGuid(); #endregion #region Password Hashing subscriber.password = Crypto.Hash(subscriber.password); subscriber.confirmpassword = Crypto.Hash(subscriber.confirmpassword); #endregion subscriber.IsEmailVerified = false; #region Save data to database using (PostEntity pe = new PostEntity()) { pe.Subscriber_Table.Add(subscriber); try { pe.SaveChanges(); } catch (DbEntityValidationException dbEx) { stream = new StreamWriter(@"D:\Exception.txt"); foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { stream.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } stream.Close(); } finally { //stream.Close(); } //Send Email to user SendVerificationLinkEmail(subscriber.email, subscriber.ActivationCode.ToString()); message = "Registration successfully done. Account activation link has been sent to your emailid " + subscriber.email; Status = true; } #endregion } else { message = "Invalid request"; } ViewBag.Message = message; ViewBag.Status = Status; return(View(subscriber)); }
public ActionResult Create(Post_Table post, Blog blog, Comment comment) { StreamWriter stream = null; try { using (PostEntity pe = new PostEntity()) { DomainTech.DomainTechService dt = new DomainTech.DomainTechService(); List <Domain_Table> DomainList = dt.GetDomainList(); ViewBag.DomainList = new SelectList(DomainList, "did", "domain"); pe.Configuration.ProxyCreationEnabled = false; List <Technology_Table> TechnologyList = dt.GetTechforDomain(post.domain); ViewBag.TechnologyList = new SelectList(TechnologyList, "tid", "technology"); //Get the Domain ID int did = Convert.ToInt32(blog.Post.domain); //Get the Technology ID int tid = Convert.ToInt32(blog.Post.technology); DomainTechEntity dte = new DomainTechEntity(); //Convert the Domain ID to Domain Name var d = dte.Domain_Table.Where(x => x.did == did).FirstOrDefault(); post.domain = d.domain; //Convert the Technology ID to Technology Name var t = dte.Technology_Table.Where(x => x.tid == tid).FirstOrDefault(); post.technology = t.technology; //Check for same title int count = pe.Post_Table.Where(x => x.title == blog.Post.title && x.category == false).Count(); if (count > 0) { ViewBag.ErrorMessage = "Please modify the TITLE, Blog found with same TITLE"; return(View(blog)); } else { // Add the date, category and post.title = blog.Post.title; post.tags = blog.Post.tags; post.content_ = blog.Post.content_; post.date = DateTime.Now; post.category = false; post.userid = Session["userid"].ToString(); ViewData["Blog"] = post; pe.Post_Table.Add(post); pe.SaveChanges(); return(View("../Post/ResultView")); } } } catch (DbEntityValidationException dbEx) { stream = new StreamWriter(@"D:\BlogException.txt"); foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { stream.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } stream.Close(); return(View()); } }
public ActionResult TakeTest(Test_Table test, string searchtest, string submittechnology, string technology, string submitdomain, QuestionBank qu, string domain, string checkscore, string _1, string _2, string _3, string _4, string _5, string _6, string _7, string _8, string _9, string _10) { /*provides dropdown to select domain*/ if (searchtest != null) { PostEntity tec = new PostEntity(); var domainlist = (from p in tec.Domain_Table select new { domain = p.domain //select domain from domain table }).ToList(); List <QuestionBank> li = new List <QuestionBank>(); foreach (var p in domainlist) { QuestionBank q = new QuestionBank(); q.domainlist = p.domain; li.Add(q); } return(View(li)); //return the list of domain to the view } /*Lists the technologies after selecting the respective domain*/ else if (submitdomain != null) { PostEntity tec = new PostEntity(); //fetch technology id var techlist = (from p in tec.Technology_Table join q in tec.Domain_Table on p.did equals q.did where q.domain == domain select new { Technology = p.technology, }).ToList(); Session["Domain"] = domain; var domainlist = (from p in tec.Domain_Table select new { domain = p.domain //gets the domain list }).ToList(); List <QuestionBank> li = new List <QuestionBank>(); foreach (var p in techlist) { QuestionBank q = new QuestionBank(); q.techlist = p.Technology; li.Add(q); } foreach (var p in domainlist) { QuestionBank q = new QuestionBank(); q.domainlist = p.domain; li.Add(q); } return(View(li)); //returns the list of domain and technology } /*submitting the technology and domain and starting the test*/ else if (submittechnology != null) { PostEntity te = new PostEntity(); //fetch technologyID var techidquery = (from p in te.Technology_Table where p.technology == technology select new { Technology = p.tid }); foreach (var p in techidquery) { qu.idtech = p.Technology; } Session["TechnologyID"] = qu.idtech; //fetch the questions and options based on TechnologyID var query = (from p in te.Question_Bank_Table where p.TechnologyId == qu.idtech select new { Question = p.Question, QuestionID = p.QuestionID, Options = p.Options, CorrectAnswer = p.CorrectAnswer }); List <QuestionBank> li = new List <QuestionBank>(); int no = 1; foreach (var p in query) { QuestionBank qi = new QuestionBank(); qi.QuestionID = p.QuestionID; qi.Question = p.Question; qi.qno = no; qi.CorrectAnswer = p.CorrectAnswer; string[] tempsplit = p.Options.Split(','); qi.Options = tempsplit; li.Add(qi); no++; } Session["listOfObjects"] = li; return(View("TestPage", li)); } /*Checking the score after end of test*/ else if (checkscore != null) { qu.idtech = Int32.Parse(Session["TechnologyID"].ToString()); PostEntity te = new PostEntity(); //Fetch Domain ID var iddomain = (from p in te.Technology_Table where p.tid == qu.idtech select new { DomainID = p.did }); foreach (var p in iddomain) { qu.count = p.DomainID; } //Based on the technology ID retrieve the correct answers var query = (from p in te.Question_Bank_Table where p.TechnologyId == qu.idtech select new { Question = p.Question, QuestionID = p.QuestionID, Options = p.Options, Answer = p.CorrectAnswer }); List <string> correctanswer = new List <string>(); //Append the selected options and enter into test_table string selectedoptions = ""; foreach (var p in query) { qu.qid = qu.qid + p.QuestionID + ","; correctanswer.Add(p.Answer); } selectedoptions = _1 + "," + _2 + "," + _3 + "," + _4 + "," + _5 + "," + _6 + "," + _7 + "," + _8 + "," + _9 + "," + _10; Session["selectedoptions"] = selectedoptions; /*evaluate the score by checking each of radio button with the correct answer*/ if (_1 == correctanswer[0]) { qu.score += 1; } if (_2 == correctanswer[1]) { qu.score += 1; } if (_3 == correctanswer[2]) { qu.score += 1; } if (_4 == correctanswer[3]) { qu.score += 1; } if (_5 == correctanswer[4]) { qu.score += 1; } if (_6 == correctanswer[5]) { qu.score += 1; } if (_7 == correctanswer[6]) { qu.score += 1; } if (_8 == correctanswer[7]) { qu.score += 1; } if (_9 == correctanswer[8]) { qu.score += 1; } if (_10 == correctanswer[9]) { qu.score += 1; } string userid = Session["userid"].ToString(); test.UserId = userid; test.TechnologyID = (qu.idtech); test.DomainID = (qu.count); test.SelectedOptions = selectedoptions; test.Score = qu.score; te.Test_Table.Add(test); te.SaveChanges(); //saving the results of the test in the database return(View("TestResult", qu)); } else { return(View("TakeTest")); } }