public IActionResult Confirm(string key) { ViewBag.Title = "confirm your account"; using (var acontext = new SnContext()) { var account = acontext.Accounts.FirstOrDefault(a => a.key == key); if (account == null) { string msg = "Your account was not registered or could not be found. Please submit " + "for registration again."; Flash(msg, "danger"); } else { if (account.verified == false) { account.verified = true; acontext.Accounts.Update(account); acontext.SaveChanges(); } string msg = "The account " + account.email + "@st-andrews.ac.uk " + "(" + account.uname + ") " + "has been succesfuly registered and confirmed. Please save your password, " + "you are authenticated to access all features of stacsnet"; Flash(msg, "success"); } } return(RedirectToAction("Index", "Home")); }
public static void loadModules() { using (var context = new SnContext()) { var _givenmodules = context.GradeReports.Select(g => g.code) .Distinct() .ToList(); foreach (var m in _givenmodules) { _MODULES.Add(m); } } DirectoryInfo parentDir = new DirectoryInfo(MOUNT); foreach (var dir in parentDir.GetDirectories()) { List <DirectoryInfo> modules_in_year = dir.GetDirectories().ToList(); foreach (var module in modules_in_year) { _MODULES.Add(module.Name); } } _MODULES = _MODULES.Distinct().ToList(); }
private QAThread findThread(string pid) { QAPost header = null; List <QAPost> posts = new List <QAPost>(); var context = new SnContext(); if (pid.Equals("0")) { header = Static.FIRST_POST; } else { header = context.QAPosts.Where(p => p.id == pid).FirstOrDefault(); } if (header == null) { return(null); } else { posts.AddRange(context.QAPosts.Where(p => p.pid == pid)); return(new QAThread() { header = header, posts = posts }); } }
public IActionResult Comment(string return_url, QAPost post) { using (var context = new SnContext()) { post.date = DateTime.Now; context.QAPosts.Add(post); context.SaveChanges(); Flash("Comment posted", "success"); } return(Redirect(return_url)); }
private static void loadDb(bool refresh) { using (var context = new SnContext()) { if (refresh) { context.Database.EnsureDeleted(); } context.Database.EnsureCreated(); } }
public QAThread Children() { QAThread thread = new QAThread(); using (var context = new SnContext()) { thread.posts = context.QAPosts.Where(p => p.pid == id).ToList(); thread.header = this; context.SaveChanges(); } return(thread); }
public IActionResult Submit(string return_url, GradeReport report) { if (ModelState.IsValid) { using (var context = new SnContext()) { context.GradeReports.Add(report); context.SaveChanges(); } Flash("submission received", "success"); } else { Flash("submission not received", "danger"); } return(Redirect(return_url)); }
private Dictionary <string, ReportData> loadReports(string module_code, string year) { using (var context = new SnContext()) { var allreports = context.GradeReports.Where(g => g.code == module_code && g.Year == year).ToList(); var reports = new Dictionary <string, ReportData>(); var mincount = 3; foreach (var type in Enum.GetNames(typeof(GradeType))) { var typedreports = allreports.Where(g => g.Type.ToString() == type).ToList(); var count = typedreports.Count(); if (count < mincount) { reports.Add(type, new ReportData { count = count, min = mincount, reports = new List <ArrayList>() }); } else { var list = new List <ArrayList>(); foreach (var row in typedreports) { var innertype = type; if (type == "Practical") { innertype = "W" + row.Week; } list.Add(new ArrayList { innertype, row.Grade }); } reports.Add(type, new ReportData { count = count, min = mincount, reports = list }); } } return(reports); } }
public IActionResult Submit(Account account) { string key = Guid.NewGuid().ToString(); using (var acontext = new SnContext()) { var model = new Account(); var old_account = acontext.Accounts.FirstOrDefault(a => a.email == account.email); if (old_account != null) { if (old_account.verified) { string msg = "The email address " + account.email + " has been registered and confirmed. The username and password you supplied when creating the account" + " are valid to authenticate you on this site."; Flash(msg, "success"); } else { string msg = "The email address " + account.email + "@st-andrews.ac.uk has already submitted for registration. " + "Please check your emails from [email protected] and open the confirmation link supplied."; Flash(msg, "warning"); } } else { Send(account.email, account.uname, key); var hasher = new PasswordHasher <Account>(); account.key = key; account.pwhash = hasher.HashPassword(account, account.pwhash); account.verified = false; acontext.Accounts.Add(account); acontext.SaveChanges(); string msg = "The email address " + account.email + "@st-andrews.ac.uk" + " was succesfully submitted for registration. " + "Please check your emails from [email protected] and open the confirmation link supplied."; Flash(msg, "info"); } return(RedirectToAction("Index", "Home")); } }
public static void loadYears( ) { using (var context = new SnContext()) { var _givenYears = context.GradeReports.Select(g => g.Year) .Distinct() .ToList(); foreach (var y in _givenYears) { _YEARS.Add(y); } } DirectoryInfo parentDir = new DirectoryInfo(MOUNT); foreach (var dir in parentDir.GetDirectories()) { _YEARS.Add(dir.Name); } _YEARS = _YEARS.Distinct().ToList(); }
public bool IsAuthorized(string username, string password) { if (Static.ENV.IsDevelopment() && username.Equals("lemo") && password.Equals("nade")) { return(true); } else { using (var acontext = new SnContext()) { var hasher = new PasswordHasher <Account>(); var account = acontext.Accounts.FirstOrDefault(a => (a.uname == username && (hasher.VerifyHashedPassword(a, a.pwhash, password) == PasswordVerificationResult.Success) && a.verified)); if (account != null && account.verified == true) { return(true); } else { return(false); } } } }
public EFUnitOfWork(string connectionString) { db = new SnContext(connectionString); }