public async Task <IActionResult> OnGetAsync(string id) { if (id == null) { return(NotFound()); } Themes = await _context.Themes.FirstOrDefaultAsync(m => m.Id == Int32.Parse(id)); Supervisor = await _context.Supervisors.FirstOrDefaultAsync(m => m.Id == Themes.SupervisorId); StProgram = await _context.StPrograms.FirstOrDefaultAsync(m => m.Id == Themes.StProgramId); if (Themes == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(string id) { if (id == null) { return(NotFound()); } Themes = await _context.Themes.FindAsync(Int32.Parse(id)); Supervisor = await _context.Supervisors.FirstOrDefaultAsync(m => m.Id == Themes.SupervisorId); StProgram = await _context.StPrograms.FirstOrDefaultAsync(m => m.Id == Themes.StProgramId); if (Themes != null) { _context.Themes.Remove(Themes); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnGetAsync(string id) { if (id == null) { return(NotFound()); } Themes = await _context.Themes.FirstOrDefaultAsync(m => m.Id == Int32.Parse(id)); switch (Themes.ResearchType) { case ResearchType.BasicResearch: resType = "základný výskum"; break; case ResearchType.AppliedResearch: resType = "aplikovaný výskum"; break; case ResearchType.AppliedResearchExpDevelopment: resType = "aplikovaný výskum a experimentálny vývoj"; break; case null: break; default: throw new ArgumentOutOfRangeException(); } Supervisor = await _context.Supervisors.FirstOrDefaultAsync(m => m.Id == Themes.SupervisorId); StProgram = await _context.StPrograms.FirstOrDefaultAsync(m => m.Id == Themes.StProgramId); if (Themes == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostUploadFile(IFormFile fileName) { if (!ModelState.IsValid) { return(Page()); } #region ClearDbCommands _context.Database.ExecuteSqlCommand("DELETE FROM Theme"); await _context.SaveChangesAsync(); _context.Database.ExecuteSqlCommand("DELETE FROM Supervisor"); await _context.SaveChangesAsync(); _context.Database.ExecuteSqlCommand("DELETE FROM StProgram"); await _context.SaveChangesAsync(); #endregion StreamReader reader = new StreamReader(fileName.OpenReadStream()); reader.ReadLine(); while (!reader.EndOfStream) { var line = reader.ReadLine(); if (!string.IsNullOrWhiteSpace(line)) { var values = line.Split(';'); if (_context.Supervisors.Count(s => s.FullName == values[1]) == 0) { var inserting = new Supervisor(); inserting.FullName = values[1]; _context.Supervisors.Add(inserting); await _context.SaveChangesAsync(); } if (_context.StPrograms.Where(s => s.Name == values[2]).Count(s => s.FieldOfStudy == values[3]) == 0) { var inserting = new StProgram(); inserting.Name = values[2]; inserting.FieldOfStudy = values[3]; _context.StPrograms.Add(inserting); await _context.SaveChangesAsync(); } if (_context.Themes.Where(t => t.Name == values[0]) .Where(t => t.StProgramId == _context.StPrograms.FirstOrDefault(s => s.Name == values[2]).Id) .Count(t => t.StProgramId == _context.StPrograms.FirstOrDefault(s => s.FieldOfStudy == values[3]).Id) == 0) { var inserting = new Theme(); inserting.Name = values[0]; var sup = _context.Supervisors.First(s => s.FullName == values[1]); inserting.SupervisorId = sup.Id; inserting.Supervisor = sup; var stu = _context.StPrograms .Where(s => s.Name == values[2]).First(s => s.FieldOfStudy == values[3]); inserting.StProgramId = stu.Id; inserting.StProgram = stu; inserting.IsFullTimeStudy = Boolean.Parse(values[4]); inserting.IsExternalStudy = Boolean.Parse(values[5]); ResearchType?resType = null; switch (values[6].ToLower()) { case "základný výskum": resType = ResearchType.BasicResearch; break; case "aplikovaný výskum": resType = ResearchType.AppliedResearch; break; case "aplikovaný výskum a experimentálny vývoj": resType = ResearchType.AppliedResearchExpDevelopment; break; case null: break; default: throw new ArgumentOutOfRangeException(); } inserting.ResearchType = resType; string desc = values[7]; desc = desc.Replace("<br>", Environment.NewLine); inserting.Description = desc; inserting.Created = DateTime.Parse(values[8]); _context.Themes.Add(inserting); await _context.SaveChangesAsync(); } } } reader.Close(); return(RedirectToPage("./Index")); }