private static void AddProjectStudents(string AProjectCollegeYear, string ACollegePeriodNr, ApplicationDbContext dbcontext, List <Student> listStudents, string strProjectteamCode, Projectperiod projectperiod) { var calcedId = Projectperiod.CalculateId(AProjectCollegeYear, ACollegePeriodNr, strProjectteamCode); var projectperiod_excist = dbcontext.Projectperiods.FirstOrDefault(p => p.Id == calcedId); if (projectperiod_excist == null) { dbcontext.Add(projectperiod); dbcontext.SaveChanges(); } foreach (Student stud in listStudents) { var student_rec = dbcontext.Students.SingleOrDefault(s => s.Studentnumber == stud.Studentnumber); if (student_rec == null) { dbcontext.Add(stud); ApplicationUser.CreateUserLogin(dbcontext, stud.User); // password and claim security GUID } } dbcontext.SaveChanges(); foreach (Student stud in listStudents) { var ProjectStudent = new ProjectStudent() { ProjectperiodId = projectperiod.Id, StudentId = stud.Studentnumber }; dbcontext.Add(ProjectStudent); } dbcontext.SaveChanges(); listStudents.Clear(); }
public async Task <IActionResult> Edit(int id, [Bind("Id,ProjectId,ApplicationUserId,CreatedBy,CreatedOn,UpdatedBy,UpdatedOn")] ProjectStudent projectStudent) { if (id != projectStudent.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(projectStudent); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProjectStudentExists(projectStudent.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ApplicationUserId"] = new SelectList(_context.Users, "Id", "Id", projectStudent.ApplicationUserId); ViewData["CreatedBy"] = new SelectList(_context.Users, "Id", "Id", projectStudent.CreatedBy); ViewData["ProjectId"] = new SelectList(_context.Projects, "Id", "Description", projectStudent.ProjectId); ViewData["UpdatedBy"] = new SelectList(_context.Users, "Id", "Id", projectStudent.UpdatedBy); return(View(projectStudent)); }
public ActionResult DeleteProject(int joinId) { ProjectStudent joinEntry = _db.ProjectStudent.FirstOrDefault(entry => entry.ProjectStudentId == joinId); _db.ProjectStudent.Remove(joinEntry); _db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create([Bind("Id,ProjectId,ApplicationUserId,CreatedBy,CreatedOn,UpdatedBy,UpdatedOn")] ProjectStudent projectStudent) { if (ModelState.IsValid) { _context.Add(projectStudent); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ApplicationUserId"] = new SelectList(_context.Users, "Id", "Id", projectStudent.ApplicationUserId); ViewData["CreatedBy"] = new SelectList(_context.Users, "Id", "Id", projectStudent.CreatedBy); ViewData["ProjectId"] = new SelectList(_context.Projects, "Id", "Description", projectStudent.ProjectId); ViewData["UpdatedBy"] = new SelectList(_context.Users, "Id", "Id", projectStudent.UpdatedBy); return(View(projectStudent)); }