//view all the student on the system public IActionResult view(string searchString) { TempRepository.RemoveAll(); var StudentData = _dbContext.InfoTable.OrderBy(s => s.Id); var StudentGpa = _dbContext.StudnetGpa.OrderBy(s => s.StuId); var ResultList = from data in StudentData join Gpa in StudentGpa on data.Id equals Gpa.StuId select new { data.Id, data.Name, Gpa.StuGpa }; var FinalData = ResultList.Select(s => new { s.Id, s.Name, s.StuGpa }); if (!string.IsNullOrEmpty(searchString)) { FinalData = FinalData.Where(s => s.Id.Contains(searchString) || s.Name.Contains(searchString)); } foreach (var f in FinalData) { TempRepository.AddStudent(new NewStudentInsert { Id = f.Id, Name = f.Name, StudentGPA = f.StuGpa }); } return(View(TempRepository.Inserted)); }
public async Task <IActionResult> Upload(IFormFile file) { TempRepository.RemoveAll(); var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot", file.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await file.CopyToAsync(stream); } //Load the the data from the uploaded file IEnumerable <NewStudentInsert> ToAdd = DataLoader.Load(@"wwwroot\" + file.FileName); foreach (NewStudentInsert s in ToAdd) { s.Id = s.Id.Trim(); s.Name = s.Name.Trim(); s.Pass = s.Pass.Trim(); s.RepeatPass = s.RepeatPass.Trim(); var targetUser = _dbContext.InfoTable.SingleOrDefault(i => i.Id.Equals(s.Id, StringComparison.CurrentCulture)); var targetGPA = _dbContext.InfoTable.SingleOrDefault(i => i.Id.Equals(s.Id, StringComparison.CurrentCulture)); if (targetUser != null) { TempRepository.AddStudent(new NewStudentInsert { Id = s.Id, Name = s.Name, StudentGPA = s.StudentGPA, ADD = false }); continue; } var hasher = new PasswordHasher <InfoTable>(); targetUser = new InfoTable { Id = s.Id, Name = s.Name, RoleId = 2 }; targetUser.Pass = hasher.HashPassword(targetUser, s.Pass); //targetGPA = new StudnetGpa { StuId = student.Id, StuGpa = student.StudentGPA }; await _dbContext.InfoTable.AddAsync(targetUser); await _dbContext.SaveChangesAsync(); if (s.StudentGPA != double.NaN) { await GpaSet(s); } ViewBag.templist = true; TempRepository.AddStudent(s); } ViewBag.inserted = true; return(View(TempRepository.Inserted)); }