public async Task <IActionResult> CreateCommitie([Bind("CommitteeID,DepartmentID,ProfessorID,StartDate,Title")] Committee model) { if (ModelState.IsValid) { if (model.Level == Level.Department) { model.FacultyID = null; } else if (model.Level == Level.Faculty) { model.DepartmentID = null; } else if (model.Level == Level.University) { model.FacultyID = null; model.DepartmentID = null; } //model.StartDate = DateTime.Today.Date; if (model.ProfessorID != null) { DateTime end = new DateTime(); if (DateTime.Today < new DateTime(DateTime.Today.Year, 6, 1)) { end = new DateTime(DateTime.Today.Year, 6, 1); } else { end = new DateTime(DateTime.Today.Year + 1, 6, 1); } CommitieMembership member = new CommitieMembership() { Chair = true, ProfessorID = (int)model.ProfessorID, DateOfEnrollment = DateTime.Now, EstimatedEndDate = end, }; model.CommitieMembers = new List <CommitieMembership>() { member, }; } _context.Add(model); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(model)); }
public async Task <IActionResult> Invite() { int profId = int.Parse(Request.Form["ProfID"]); int commId = int.Parse(Request.Form["CommID"]); CommitieMembership member = new CommitieMembership() { Chair = false, ProfessorID = profId, CommitteeID = commId, FinishedWork = false, DateOfEnrollment = DateTime.Today.Date, EstimatedEndDate = new DateTime(_context.Semesters.AsNoTracking().SingleOrDefault(i => i.Current == true).EndYear, 5, 1), }; _context.CommitieMembership.Add(member); await _context.SaveChangesAsync(); return(Json("Success")); }
public async Task <IActionResult> UpdateCommittee(Committee model) { if (model.Level == Level.Department) { model.FacultyID = null; } else if (model.Level == Level.Faculty) { model.DepartmentID = null; } else if (model.Level == Level.University) { model.FacultyID = null; model.DepartmentID = null; } var committeeToUpdate = await _context.Committees.Include(i => i.CommitieMembers).SingleOrDefaultAsync(s => s.CommitteeID == model.CommitteeID); if (committeeToUpdate.ProfessorID != model.ProfessorID) { bool found = false; foreach (var member in committeeToUpdate.CommitieMembers) { if (member.ProfessorID == model.ProfessorID && member.Chair == false) { member.Chair = true; found = true; } else if (member.ProfessorID != model.ProfessorID && member.Chair == true) { member.Chair = false; } else if (member.ProfessorID == model.ProfessorID && member.Chair == true) { found = true; break; } } if (found == false) { DateTime end = new DateTime(); if (DateTime.Today < new DateTime(DateTime.Today.Year, 6, 1)) { end = new DateTime(DateTime.Today.Year, 6, 1); } else { end = new DateTime(DateTime.Today.Year + 1, 6, 1); } CommitieMembership member = new CommitieMembership() { Chair = true, ProfessorID = (int)model.ProfessorID, CommitteeID = model.CommitteeID, DateOfEnrollment = DateTime.Now, EstimatedEndDate = end, }; _context.CommitieMembership.Add(member); } } if (await TryUpdateModelAsync <Committee>( committeeToUpdate, "", s => s.CommitteeID, s => s.ProfessorID, s => s.FacultyID, s => s.Title, s => s.Level)) { await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } else { return(RedirectToAction("ManageCommitie", new { id = model.CommitteeID })); } }