public async Task <IActionResult> OnPostRenameAsync(int?id) { if (id == null) { return(RedirectToPage("Datasets")); } Models.Dataset dataset = await _context.Datasets.FirstOrDefaultAsync(x => x.Id == id); if (await _context.Datasets.FirstOrDefaultAsync(x => x.Name == Name && (x.AccountDatasets.FirstOrDefault(y => y.AccountId == HttpContext.Session.GetInt32("id")) != null)) != null) { ModelState.AddModelError("Name", "You already have a dataset with this name."); Dataset = await _context.Datasets.FirstOrDefaultAsync(x => x.Id == id); Name = Dataset.Name; Articles = await _context.Articles.Where(x => x.DatasetId == Dataset.Id).ToListAsync(); return(Page()); } if (dataset != null && await _context.AccountDatasets.FirstOrDefaultAsync(x => x.DatasetId == dataset.Id && x.AccountId == HttpContext.Session.GetInt32("id")) != null) { _context.Attach(dataset).State = EntityState.Modified; dataset.Name = Name; await _context.SaveChangesAsync(); } return(RedirectToPage("Datasets")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(RedirectToPage("Classifiers")); } Models.Classifier classifier = await _context.Classifiers.FirstOrDefaultAsync(x => x.Id == id); if (await _context.Classifiers.FirstOrDefaultAsync(x => x.Name == Name && (x.AccountClassifiers.FirstOrDefault(y => y.AccountId == HttpContext.Session.GetInt32("id")) != null)) != null) { ModelState.AddModelError("Name", "You already have a classifier with this name."); Classifier = await _context.Classifiers.FirstOrDefaultAsync(x => x.Id == id); Name = Classifier.Name; return(Page()); } if (classifier != null && await _context.AccountClassifiers.FirstOrDefaultAsync(x => x.ClassifierId == classifier.Id && x.AccountId == HttpContext.Session.GetInt32("id")) != null) { _context.Attach(classifier).State = EntityState.Modified; classifier.Name = Name; await _context.SaveChangesAsync(); } return(RedirectToPage("Classifiers")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Configuration).State = EntityState.Modified; await _context.SaveChangesAsync(); return(RedirectToPage("Index")); }
public async Task <IActionResult> OnPostAsync() { Models.Account account = await _context.Accounts.FirstOrDefaultAsync(x => x.Email == Email); Answer = Convert.ToBase64String(KeyDerivation.Pbkdf2( password: Answer, salt: Convert.FromBase64String(account.Salt), prf: KeyDerivationPrf.HMACSHA1, iterationCount: 10000, numBytesRequested: 256 / 8 )); if (account.Answer != Answer) { ModelState.AddModelError("Answer", "The provided security question answer is incorrect."); } if (!ModelState.IsValid) { return(Page()); } _context.Attach(account).State = EntityState.Modified; account.Password = Convert.ToBase64String(KeyDerivation.Pbkdf2( password: Password, salt: Convert.FromBase64String(account.Salt), prf: KeyDerivationPrf.HMACSHA1, iterationCount: 10000, numBytesRequested: 256 / 8 )); await _context.SaveChangesAsync(); return(RedirectToPage("Login")); }
public async Task <IActionResult> OnPostAsync() { if (HttpContext.Session.Get("isAdmin") != null && !BitConverter.ToBoolean(HttpContext.Session.Get("isAdmin"))) { if (HttpContext.Session.GetInt32("id") != null && HttpContext.Session.GetInt32("id") != Account.Id) { return(RedirectToPage("Error")); } } if (await _context.Accounts.FirstOrDefaultAsync(x => x.Email == Email && x.Id != Account.Id) != null) { ModelState.AddModelError("Email", "An account with this email already exists."); } if (!ModelState.IsValid) { return(Page()); } _context.Attach(Account).State = EntityState.Modified; _context.Entry(Account).Property(x => x.Salt).IsModified = false; _context.Entry(Account).Property(x => x.Date).IsModified = false; Account.Email = Email; if (!string.IsNullOrEmpty(Password)) { Account.Password = Convert.ToBase64String(KeyDerivation.Pbkdf2( password: Password, salt: Convert.FromBase64String(Account.Salt), prf: KeyDerivationPrf.HMACSHA1, iterationCount: 10000, numBytesRequested: 256 / 8 )); } else { _context.Entry(Account).Property(x => x.Password).IsModified = false; } if (!string.IsNullOrEmpty(Answer)) { Account.Answer = Convert.ToBase64String(KeyDerivation.Pbkdf2( password: Answer, salt: Convert.FromBase64String(Account.Salt), prf: KeyDerivationPrf.HMACSHA1, iterationCount: 10000, numBytesRequested: 256 / 8 )); } else { _context.Entry(Account).Property(x => x.Answer).IsModified = false; } if (!BitConverter.ToBoolean(HttpContext.Session.Get("isAdmin"))) { Account.IsAdmin = false; } else if (Account.Id == HttpContext.Session.GetInt32("id")) { Account.IsAdmin = true; } await _context.SaveChangesAsync(); if (HttpContext.Session.Get("isAdmin") != null && BitConverter.ToBoolean(HttpContext.Session.Get("isAdmin"))) { return(RedirectToPage("Accounts")); } return(RedirectToPage("Index")); }