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 <ActionResult> Create(ViewModels.CreateObjectViewModel viewModel) { await this.ShowUser(userManager); try { await context.Objects.AddAsync(new Models.Object { Id = viewModel.Id, Name = viewModel.Name }); var result = await context.SaveChangesAsync(); if (result == 1) { viewModel.IsShowSuccess = true; } else { ModelState.AddModelError("", "Ошибка при создании объекта."); } } catch { } return(View(viewModel)); }
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 (await _context.AccountClassifiers.FirstOrDefaultAsync(x => x.ClassifierId == ClassifierId && x.AccountId == HttpContext.Session.GetInt32("id")) == null) { return(RedirectToPage("Error")); } Models.Classifier classifier = await _context.Classifiers.FirstOrDefaultAsync(x => x.Id == ClassifierId); Models.Account account = await _context.Accounts.FirstOrDefaultAsync(x => x.Email == Email && !x.IsAdmin); if (account == null) { ModelState.AddModelError("Email", "No account with this email address exists."); } else if (await _context.Classifiers.FirstOrDefaultAsync(x => x.Name == classifier.Name && (x.AccountClassifiers.FirstOrDefault(y => y.AccountId == account.Id) != null)) != null) { ModelState.AddModelError("ClassifierId", "User already has a classifier with this name."); } if (!ModelState.IsValid) { Classifiers = await _context.Classifiers.Where(x => x.AccountClassifiers.Any(y => y.ClassifierId == x.Id && y.AccountId == HttpContext.Session.GetInt32("id"))).ToListAsync(); return(Page()); } _context.AccountClassifiers.Add(new Models.AccountClassifier() { Account = account, Classifier = classifier }); await _context.SaveChangesAsync(); return(RedirectToPage("Classifiers")); }
public async Task <IActionResult> OnPostAsync() { 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."); } if (DatasetId1 == DatasetId2) { ModelState.AddModelError("DatasetId2", "You must select two different datasets."); } if (!ModelState.IsValid) { Datasets = await _context.Datasets.Where(x => x.AccountDatasets.Any(y => y.DatasetId == x.Id && y.AccountId == HttpContext.Session.GetInt32("id"))).Include(x => x.Articles).ToListAsync(); return(Page()); } if (await _context.AccountDatasets.FirstOrDefaultAsync(x => x.DatasetId == DatasetId1 && x.AccountId == HttpContext.Session.GetInt32("id")) == null || await _context.AccountDatasets.FirstOrDefaultAsync(x => x.DatasetId == DatasetId2 && x.AccountId == HttpContext.Session.GetInt32("id")) == null) { return(RedirectToPage("Error")); } List <Models.Article> queriedArticles = await _context.Articles.Where(x => x.DatasetId == DatasetId1 || x.DatasetId == DatasetId2).ToListAsync(); List <Models.Article> combinedArticles = new List <Models.Article>(); foreach (Models.Article article in queriedArticles) { combinedArticles.Add(new Models.Article() { Abstract = article.Abstract, Classification = article.Classification, Pmid = article.Pmid, Title = article.Title, Date = article.Date }); } Models.Dataset dataset = new Models.Dataset() { Name = Name, Articles = combinedArticles, Date = DateTime.Now }; Models.Account account = await _context.Accounts.FirstOrDefaultAsync(x => x.Id == HttpContext.Session.GetInt32("id")); _context.Datasets.Add(dataset); _context.AccountDatasets.Add(new Models.AccountDataset() { Account = account, Dataset = dataset }); await _context.SaveChangesAsync(); return(RedirectToPage("Datasets")); }
public async Task <IActionResult> Edit([FromForm] ViewModels.Users.EditViewModel model) { try { model.Errors.Items.Clear(); if (model == null) { model.Errors.Items.Add("Пустой параметр"); return(PartialView(model)); } if (string.IsNullOrEmpty(model.Username)) { model.Errors.Items.Add("Не указано имя пользователя."); return(PartialView(model)); } var entity = await context.Users.FindAsync(model.Id); entity.Id = model.Id; entity.Email = model.EMail; entity.UserName = model.Username; entity.PhoneNumber = model.Phone; context.Update(entity); await context.SaveChangesAsync(); //var result = await userManager.UpdateAsync(new Models.User //{ // Id = model.Id, // Email = model.EMail, // UserName = model.Username, // PhoneNumber = model.Phone //}); //if (!result.Succeeded) //{ // foreach (var er in result.Errors) // { // if (er.Code == "DuplicateUserName") // model.Errors.Items.Add($"Пользователь \'{model.Username}\' уже существует"); // } // return PartialView(model); //} } catch (Exception ex) { model.Errors.Items.Add(ex.Message); return(PartialView(model)); } return(RedirectToAction("List")); }
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> OnPostDeleteAsync(int?id) { if (id == null) { return(RedirectToPage("Datasets")); } Models.Dataset dataset = await _context.Datasets.FindAsync(id); if (dataset != null && await _context.AccountDatasets.FirstOrDefaultAsync(x => x.DatasetId == dataset.Id && x.AccountId == HttpContext.Session.GetInt32("id")) != null) { _context.Datasets.Remove(dataset); await _context.SaveChangesAsync(); } return(RedirectToPage("Datasets")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(RedirectToPage("Accounts")); } Models.Account account = await _context.Accounts.FirstOrDefaultAsync(x => x.Id == id); if (account != null && account.Id != HttpContext.Session.GetInt32("id")) { _context.Accounts.Remove(account); await _context.SaveChangesAsync(); } return(RedirectToPage("Accounts")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(RedirectToPage("Classifiers")); } Models.Classifier classifier = await _context.Classifiers.FindAsync(id); if (classifier != null && await _context.AccountClassifiers.FirstOrDefaultAsync(x => x.ClassifierId == classifier.Id && x.AccountId == HttpContext.Session.GetInt32("id")) != null) { var path = Path.Combine(_environment.WebRootPath, "classifiers", $"{classifier.Model}.zip"); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } _context.Classifiers.Remove(classifier); await _context.SaveChangesAsync(); } return(RedirectToPage("Classifiers")); }
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 (!Data.Utilities.Questions.ContainsKey(Account.Question)) { return(RedirectToPage("Error")); } if (await _context.Accounts.FirstOrDefaultAsync(x => x.Email == Account.Email) != null) { ModelState.AddModelError("Account.Email", "An account with this email already exists."); } if (!ModelState.IsValid) { Configuration = await _context.Configurations.FirstOrDefaultAsync(x => x.Id == 1); return(Page()); } byte[] salt = new byte[128 / 8]; using (RandomNumberGenerator random = RandomNumberGenerator.Create()) { random.GetBytes(salt); } byte[] password = KeyDerivation.Pbkdf2( password: Account.Password, salt: salt, prf: KeyDerivationPrf.HMACSHA1, iterationCount: 10000, numBytesRequested: 256 / 8 ); byte[] answer = KeyDerivation.Pbkdf2( password: Account.Answer, salt: salt, prf: KeyDerivationPrf.HMACSHA1, iterationCount: 10000, numBytesRequested: 256 / 8 ); if (HttpContext.Session.Get("isAdmin") == null || !BitConverter.ToBoolean(HttpContext.Session.Get("isAdmin"))) { Account.IsAdmin = false; } Models.Account account = new Models.Account() { Email = Account.Email, Password = Convert.ToBase64String(password), Question = Account.Question, Answer = Convert.ToBase64String(answer), Salt = Convert.ToBase64String(salt), IsAdmin = Account.IsAdmin, Date = DateTime.Now }; _context.Accounts.Add(account); await _context.SaveChangesAsync(); if (HttpContext.Session.Get("isAdmin") != null && BitConverter.ToBoolean(HttpContext.Session.Get("isAdmin"))) { return(RedirectToPage("Accounts")); } HttpContext.Session.SetInt32("id", account.Id); HttpContext.Session.Set("isAdmin", BitConverter.GetBytes(account.IsAdmin)); return(RedirectToPage("Index")); }
public async Task <IActionResult> OnPostAsync() { if (await _context.AccountDatasets.FirstOrDefaultAsync(x => x.DatasetId == DatasetId && x.AccountId == HttpContext.Session.GetInt32("id")) == null) { return(RedirectToPage("Error")); } Models.Dataset dataset = await _context.Datasets.FirstOrDefaultAsync(x => x.Id == DatasetId); List <Models.Article> articles = await _context.Articles.Where(x => x.DatasetId == dataset.Id).ToListAsync(); if (articles.Count(x => x.Classification) < 5 || articles.Count(x => !x.Classification) < 5) { ModelState.AddModelError("DatasetId", "Dataset must have at least 5 articles of each classification."); } if (!ModelState.IsValid) { Datasets = await _context.Datasets.Where(x => x.AccountDatasets.Any(y => y.DatasetId == x.Id && y.AccountId == HttpContext.Session.GetInt32("id"))).ToListAsync(); return(Page()); } List <ArticleData> data = articles.Select(x => new ArticleData() { Text = x.Title + " " + x.Abstract, Classification = x.Classification }).ToList(); MLContext mlContext = new MLContext(); IDataView dataView = mlContext.Data.LoadFromEnumerable(data); TrainTestData splitDataView = mlContext.Data.TrainTestSplit(dataView, 0.2); var estimator = mlContext.Transforms.Text.FeaturizeText(outputColumnName: "Features", inputColumnName: nameof(ArticleData.Text)) .Append(mlContext.BinaryClassification.Trainers.SdcaLogisticRegression(labelColumnName: "Label", featureColumnName: "Features")); ITransformer model = estimator.Fit(splitDataView.TrainSet); IDataView predictions = model.Transform(splitDataView.TestSet); CalibratedBinaryClassificationMetrics metrics = mlContext.BinaryClassification.Evaluate(predictions, "Label"); var guid = Guid.NewGuid().ToString(); var path = Path.Combine(_environment.WebRootPath, "classifiers", $"{guid}.zip"); mlContext.Model.Save(model, dataView.Schema, path); Models.Classifier classifier = new Models.Classifier() { Name = Name, Accuracy = metrics.Accuracy, Precision = metrics.PositivePrecision, Recall = metrics.PositiveRecall, Date = DateTime.Now, Model = guid }; Models.Account account = await _context.Accounts.FirstOrDefaultAsync(x => x.Id == HttpContext.Session.GetInt32("id")); _context.Classifiers.Add(classifier); _context.AccountClassifiers.Add(new Models.AccountClassifier() { Account = account, Classifier = classifier }); await _context.SaveChangesAsync(); return(RedirectToPage("Classifiers")); }
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")); }
public async Task <IActionResult> OnPostAsync() { if (await _context.Datasets.FirstOrDefaultAsync(x => x.Name == Dataset.Name && (x.AccountDatasets.FirstOrDefault(y => y.AccountId == HttpContext.Session.GetInt32("id")) != null)) != null) { ModelState.AddModelError("Dataset.Name", "You already have a dataset with this name."); return(Page()); } List <Models.Article> articles = new List <Models.Article>(); if (InputMethod == "string") { if (string.IsNullOrEmpty(InputString)) { ModelState.AddModelError("InputString", "The articles from text field is required."); } else if (!Regex.IsMatch(InputString, @"(\d+,[01])(;\d+,[01])*")) { ModelState.AddModelError("InputString", "Article list is not in the correct format."); } else { List <string> inputList = InputString.Split(';').ToList(); foreach (string article in inputList) { articles.Add(new Models.Article() { Pmid = article.Split(',')[0], Classification = article.Split(',')[1] == "1" }); } articles = await Data.Utilities.GetArticles(articles); if (articles.Count < 1) { ModelState.AddModelError("InputString", "No valid articles were contained within your input."); } } } else if (InputMethod == "file") { if (InputFile == null) { ModelState.AddModelError("InputFile", "The articles from file field is required."); } else if (InputFile.FileName.Substring(InputFile.FileName.Length - 4) != ".csv") { ModelState.AddModelError("InputFile", "The chosen articles file is of the wrong type."); } else { try { using (StreamReader streamReader = new StreamReader(InputFile.OpenReadStream())) { while (!streamReader.EndOfStream) { string article = streamReader.ReadLine(); if (!Regex.IsMatch(article, @"(\d+,[01])")) { ModelState.AddModelError("InputFile", "The chosen articles file has an invalid structure."); return(Page()); } articles.Add(new Models.Article() { Pmid = article.Split(',')[0], Classification = article.Split(',')[1] == "1" }); } } articles = await Data.Utilities.GetArticles(articles); if (articles.Count < 1) { ModelState.AddModelError("InputFile", "No valid articles were contained within your input."); } } catch { ModelState.AddModelError("InputFile", "The chosen articles file has an invalid structure."); } } } else { return(RedirectToPage("Error")); } if (!ModelState.IsValid) { return(Page()); } Dataset.Articles = articles; Dataset.Date = DateTime.Now; Models.Account account = await _context.Accounts.FirstOrDefaultAsync(x => x.Id == HttpContext.Session.GetInt32("id")); _context.Datasets.Add(Dataset); _context.AccountDatasets.Add(new Models.AccountDataset() { Account = account, Dataset = Dataset }); await _context.SaveChangesAsync(); return(RedirectToPage("Datasets")); }
public async Task <IActionResult> OnPostAsync() { if (await _context.Datasets.FirstOrDefaultAsync(x => x.Name == Dataset.Name && (x.AccountDatasets.FirstOrDefault(y => y.AccountId == HttpContext.Session.GetInt32("id")) != null)) != null) { ModelState.AddModelError("Dataset.Name", "You already have a dataset with this name."); Classifiers = await _context.Classifiers.Where(x => x.AccountClassifiers.Any(y => y.ClassifierId == x.Id && y.AccountId == HttpContext.Session.GetInt32("id"))).ToListAsync(); return(Page()); } List <Models.Article> articles = new List <Models.Article>(); if (InputMethod == "string") { if (string.IsNullOrEmpty(InputString)) { ModelState.AddModelError("InputString", "The articles from text field is required."); } else if (!Regex.IsMatch(InputString, @"(\d+?)(?:,|$)")) { ModelState.AddModelError("InputString", "Article list is not in the correct format."); } else { List <string> inputList = InputString.Split(',').ToList(); foreach (string article in inputList) { articles.Add(new Models.Article() { Pmid = article }); } articles = await Data.Utilities.GetArticles(articles); if (articles.Count < 1) { ModelState.AddModelError("InputString", "No valid articles were contained within your input."); } } } else if (InputMethod == "file") { if (InputFile == null) { ModelState.AddModelError("InputFile", "The articles from file field is required."); } else if (InputFile.FileName.Substring(InputFile.FileName.Length - 4) != ".csv") { ModelState.AddModelError("InputFile", "The chosen articles file is of the wrong type."); } else { try { using (StreamReader streamReader = new StreamReader(InputFile.OpenReadStream())) { while (!streamReader.EndOfStream) { string article = streamReader.ReadLine(); if (!Regex.IsMatch(article, @"(\d+)")) { ModelState.AddModelError("InputFile", "The chosen articles file has an invalid structure."); } articles.Add(new Models.Article() { Pmid = article }); } } articles = await Data.Utilities.GetArticles(articles); if (articles.Count < 1) { ModelState.AddModelError("InputFile", "No valid articles were contained within your input."); } } catch { ModelState.AddModelError("InputFile", "The chosen articles file has an invalid structure."); } } } else { return(RedirectToPage("Error")); } var classifier = await _context.Classifiers.FirstOrDefaultAsync(x => x.Id == ClassifierId); if (classifier == null || await _context.AccountClassifiers.FirstOrDefaultAsync(x => x.ClassifierId == classifier.Id && x.AccountId == HttpContext.Session.GetInt32("id")) == null) { return(RedirectToPage("Error")); } if (!ModelState.IsValid) { Classifiers = await _context.Classifiers.Where(x => x.AccountClassifiers.Any(y => y.ClassifierId == x.Id && y.AccountId == HttpContext.Session.GetInt32("id"))).ToListAsync(); return(Page()); } var path = Path.Combine(_environment.WebRootPath, "classifiers", $"{classifier.Model}.zip"); MLContext mlContext = new MLContext(); DataViewSchema modelSchema; ITransformer trainedModel = mlContext.Model.Load(path, out modelSchema); List <ArticleData> data = articles.Select(x => new ArticleData() { Text = x.Title + " " + x.Abstract }).ToList(); IDataView dataView = mlContext.Data.LoadFromEnumerable(data); IDataView predictions = trainedModel.Transform(dataView); IEnumerable <ArticlePrediction> predictedResults = mlContext.Data.CreateEnumerable <ArticlePrediction>(predictions, reuseRowObject: false); for (var i = 0; i < articles.Count(); i++) { articles[i].Classification = predictedResults.ElementAt(i).Prediction; } Dataset.Articles = articles; Dataset.Date = DateTime.Now; Models.Account account = await _context.Accounts.FirstOrDefaultAsync(x => x.Id == HttpContext.Session.GetInt32("id")); _context.Datasets.Add(Dataset); _context.AccountDatasets.Add(new Models.AccountDataset() { Account = account, Dataset = Dataset }); await _context.SaveChangesAsync(); return(RedirectToPage("Datasets")); }
private void AddTestData(Models.Context ctx) { ctx.Customers.Add(new Models.User() { Id = 1, Name = "Customer 1", UserId = "C00001", Accounts = new List <Models.Account>() { new Models.Account() { Id = 1, AccountNumber = "12345678", AccountType = 1, Balance = 5000, Cards = new List <Models.Card>() { new Models.Card() { Id = 1, CardNumber = "1234567890123456", Pin = "1234" }, new Models.Card() { Id = 2, CardNumber = "2345678901234567", Pin = "2345" }, } } } }); ctx.Customers.Add(new Models.User() { Id = 2, Name = "Customer 2", UserId = "C00001", Accounts = new List <Models.Account>() { new Models.Account() { Id = 2, AccountNumber = "23456789", AccountType = 1, Balance = 5000, Cards = new List <Models.Card>() { new Models.Card() { Id = 3, CardNumber = "3456789012345689", Pin = "3456" }, new Models.Card() { Id = 4, CardNumber = "4567890123456789", Pin = "4567" }, } } } }); ctx.SaveChangesAsync(); }