public ActionResult Delete(int id) { var statement = _context.StatementIEs.SingleOrDefault(m => m.Id == id); if (statement == null) { return(HttpNotFound()); } var ies = _context.IncomeExpenditure_StatementIE.SingleOrDefault(m => m.StatementId == id); var proposal = _context.Proposals.SingleOrDefault(m => m.IncomeExpenditureId == ies.IncomeExpenditureId); if (proposal == null || proposal.Submitted) { return(HttpNotFound()); } if (!proposal.IsEditable(User.Identity.GetUserId())) { return(HttpNotFound()); } _context.IncomeExpenditure_StatementIE.Remove(ies); _context.StatementIEs.Remove(statement); _context.SaveChanges(); return(RedirectToAction("Index", "IncomeExpenditure", new { id = proposal.Id })); }
public ActionResult New(int id) { var proposal = _context.Proposals.SingleOrDefault(m => m.Id == id); if (proposal == null) { return(HttpNotFound()); } if (proposal.ProgrammeRationaleId != null) { return(HttpNotFound()); } if (!proposal.IsEditable(User.Identity.GetUserId())) { return(HttpNotFound()); } proposal.IsInEdit = true; proposal.UserEditing = User.Identity.GetUserId(); _context.SaveChanges(); var viewModel = new RationaleFormViewModel { Proposal = proposal, }; return(View("Form", viewModel)); }
public ActionResult Index(int id) { var proposal = _context.Proposals.SingleOrDefault(m => m.Id == id); if (proposal == null || proposal.Submitted) { return(HttpNotFound()); } if (!proposal.IsEditable(User.Identity.GetUserId())) { return(HttpNotFound()); } var er = _context.ExternalReviews.SingleOrDefault(m => m.Id == proposal.ExternalReviewId); var reviewers = er.GetReviewers(); proposal.IsInEdit = true; proposal.UserEditing = User.Identity.GetUserId(); _context.SaveChanges(); var viewModel = new ExternalReviewIndexViewModel { Proposal = proposal, Reviewers = reviewers }; return(View(viewModel)); }
public ActionResult Index(int id) { var proposal = _context.Proposals.SingleOrDefault(m => m.Id == id); if (proposal == null || proposal.Submitted) { return(HttpNotFound()); } if (!proposal.IsEditable(User.Identity.GetUserId())) { return(HttpNotFound()); } var ie = _context.IncomeExpenditures.SingleOrDefault(m => m.Id == proposal.IncomeExpenditureId); var statements = ie.GetStatements(); proposal.IsInEdit = true; proposal.UserEditing = User.Identity.GetUserId(); _context.SaveChanges(); var viewModel = new IncomeExpenditureIndexViewModel { Proposal = proposal, Statements = statements }; return(View(viewModel)); }
public ActionResult Jump(int id) { var proposal = _context.Proposals.SingleOrDefault(m => m.Id == id); if (proposal == null || !proposal.Submitted || !proposal.HasFacultyApproval()) { return(HttpNotFound()); } if (proposal.InPrincipalId == null) { InPrincipal a = new InPrincipal(); proposal.InPrincipal = a; _context.InPrincipals.Add(a); var pvc = new PvcApproval(); pvc.Upload = "_"; _context.PvcApprovals.Add(pvc); var ipp = new InPrincipal_Pvc(); ipp.PvcApproval = pvc; ipp.PvcApprovalId = pvc.Id; ipp.InPrincipal = a; ipp.InPrincipalId = a.Id; _context.InPrincipal_Pvc.Add(ipp); _context.SaveChanges(); return(RedirectToAction("InPrinciple", "Proposal", new { id = proposal.Id })); } else { return(RedirectToAction("InPrinciple", "Proposal", new { id = proposal.Id })); } }
public ActionResult Edit(int cid) { var comment = _context.Comments.SingleOrDefault(m => m.Id == cid); if (comment == null || comment.UserId != User.Identity.GetUserName()) { return(HttpNotFound()); } foreach (string name in Request.Form.AllKeys) { try { int commentId = Convert.ToInt32(name); if (cid != commentId) { return(HttpNotFound()); } if (Request[name] == "") { return(Redirect(Request.UrlReferrer.ToString())); } comment.Description = Request[name]; comment.Date = DateTime.Now; _context.SaveChanges(); } catch (Exception e) { } } return(Redirect(Request.UrlReferrer.ToString())); }
public ActionResult Save(EndorsementCollabFormViewModel vm) { var proposal = vm.Proposal; proposal = _context.Proposals.SingleOrDefault(m => m.Id == proposal.Id); if (proposal == null || !proposal.Submitted) { return(HttpNotFound()); } var endorsement = vm.Endorsement; if (endorsement.Selection == true) { //if a is chosen, set helddate to a default date endorsement.HeldDate = "01/01/0001"; } if (!ModelState.IsValid) { return(View("Form", endorsement)); } var endorsementInDb = _context.EndorsementCollabs.SingleOrDefault(m => m.Id == endorsement.Id); endorsementInDb.HeldDate = endorsement.HeldDate; endorsementInDb.SignedBy = "DeanXYZ"; endorsementInDb.SignedDate = DateTime.Now; endorsementInDb.Selection = endorsement.Selection; _context.SaveChanges(); return(RedirectToAction("Approval", "Proposal", new { id = proposal.Id })); }
public ActionResult Save(StatementServFormViewModel vm) { var proposal = vm.Proposal; proposal = _context.Proposals.SingleOrDefault(m => m.Id == proposal.Id); if (proposal == null || !proposal.Submitted) { return(HttpNotFound()); } var statement = vm.Statement; if (statement.Selection == true) { //if a is chosen, set reservations to a default string statement.Reservations = "_"; } if (!ModelState.IsValid) { return(View("Form", statement)); } var statementInDb = _context.StatementServs.SingleOrDefault(m => m.Id == statement.Id); statementInDb.Reservations = statement.Reservations; statementInDb.SignedBy = "DeanXYZ"; statementInDb.SignedDate = DateTime.Now; statementInDb.Selection = statement.Selection; _context.SaveChanges(); return(RedirectToAction("Approval", "Proposal", new { id = proposal.Id })); }
public ActionResult Save(UnitFormViewModel vm) { var unit = vm.Unit; if (unit.Id != 0) { return(HttpNotFound()); } unit.Code += " *"; if (!ModelState.IsValid) { var viewModel = GetViewModel(vm.YearRedirect); //viewModel.Unit.Code = unit.Code; //viewModel.Unit.Title = unit.Title; return(View("Form", viewModel)); } if (vm.SelectedDept != null) { string s = vm.SelectedDept; var department = _context.Ref_Department.SingleOrDefault(m => m.Id.ToString() == s); unit.Ref_Department = department; unit.DepartmentId = department.Id; } _context.Ref_Unit.Add(unit); _context.SaveChanges(); //check that user can go to yearredirect return(RedirectToAction("Edit", "Year", new { id = vm.YearRedirect })); }
public ActionResult New(int id) { var proposal = _context.Proposals.SingleOrDefault(m => m.Id == id); if (proposal == null) { return(HttpNotFound()); } if (!proposal.IsEditable(User.Identity.GetUserId())) { return(HttpNotFound()); } ProgrammeRationale pr = null; if (proposal.ProgrammeRationaleId != null) { pr = _context.ProgrammeRationales.SingleOrDefault(m => m.Id == proposal.ProgrammeRationaleId); } if (pr == null) { //if section B has not been visited yet return(RedirectToAction("Jump", "ProgrammeRationale", new { id = proposal.Id })); } if (pr.DemandId == null) { //if section demand has not been visited yet return(RedirectToAction("Jump", "Demand", new { id = proposal.Id })); } if (pr.PsId != null) { return(HttpNotFound()); } proposal.IsInEdit = true; proposal.UserEditing = User.Identity.GetUserId(); _context.SaveChanges(); var viewModel = new ProgrammeStudyFormViewModel { Proposal = proposal, ProgrammeStudy = new ProgrammeOfStudy() }; return(View("Form", viewModel)); }
// GET: TentativePs public ActionResult Index(int id) { var proposal = _context.Proposals.SingleOrDefault(m => m.Id == id); if (proposal == null || proposal.Submitted) { return(HttpNotFound()); } if (!proposal.IsEditable(User.Identity.GetUserId())) { return(HttpNotFound()); } var pr = _context.ProgrammeRationales.SingleOrDefault(m => m.Id == proposal.ProgrammeRationaleId); if (pr == null) { //if section B has not been visited yet return(RedirectToAction("Jump", "ProgrammeRationale", new { id = proposal.Id })); } if (pr.DemandId == null) { //if section demand has not been visited yet return(RedirectToAction("Jump", "Demand", new { id = proposal.Id })); } if (pr.PsId == null) { //if section ps has not been visited yet return(RedirectToAction("Jump", "ProgrammeStudy", new { id = proposal.Id })); } var tp = _context.TentativePs.SingleOrDefault(m => m.Id == pr.TentativePsId); var years = _context.Years.Where(m => m.TentativePsId == tp.Id).OrderBy(m => m.YearNo).ToList(); proposal.IsInEdit = true; proposal.UserEditing = User.Identity.GetUserId(); _context.SaveChanges(); var viewModel = new TentativePsIndexViewModel { Proposal = proposal, Years = years }; return(View(viewModel)); }
public ActionResult Delete(int id) { var reviewer = _context.Reviewers.SingleOrDefault(m => m.Id == id); if (reviewer == null) { return(HttpNotFound()); } var err = _context.ExternalReview_Reviewer.SingleOrDefault(m => m.ReviewerId == id); var proposal = _context.Proposals.SingleOrDefault(m => m.ExternalReviewId == err.ExternalReviewId); if (proposal == null || proposal.Submitted) { return(HttpNotFound()); } if (!proposal.IsEditable(User.Identity.GetUserId())) { return(HttpNotFound()); } _context.ExternalReview_Reviewer.Remove(err); _context.Reviewers.Remove(reviewer); //remove from whitelist and user list if reviewer is not linked to other proposals //reviewers with the email var reviewerList = _context.Reviewers.Where(m => m.Email == reviewer.Email).ToList(); if (reviewerList.Count() > 1) { //do nothing } else { var wlToRemove = _context.Whitelists.SingleOrDefault(m => m.Email == reviewer.Email); _context.Whitelists.Remove(wlToRemove); } _context.SaveChanges(); return(RedirectToAction("Index", "ExternalReview", new { id = proposal.Id })); }
public ActionResult Save(CouncilDecisionFormViewModel vm) { var proposal = vm.Proposal; proposal = _context.Proposals.SingleOrDefault(m => m.Id == proposal.Id); if (proposal == null || !proposal.Submitted || !proposal.HasFacultyApproval()) { return(HttpNotFound()); } var council = vm.CouncilDecision; if (!ModelState.IsValid) { //return form var viewModel = new CouncilDecisionFormViewModel { Proposal = proposal, CouncilDecision = council }; return(View("Form", viewModel)); } if (council.Selection == true) { //if a is chosen var senate = proposal.GetSenateDecision(); if (senate.SignedBy != null) { if (senate.Selection == true) { //council also approved proposal.InPrincipalApproved = true; } else { proposal.InPrincipalApproved = false; } } } else { //if b is chosen proposal.InPrincipalApproved = false; } var councilInDb = _context.CouncilDecisions.SingleOrDefault(m => m.Id == council.Id); councilInDb.SignedBy = "DeanXYZ"; councilInDb.SignedDate = DateTime.Now; councilInDb.Selection = council.Selection; _context.SaveChanges(); return(RedirectToAction("InPrinciple", "Proposal", new { id = proposal.Id })); }
public ActionResult LogOff() { GaptDbContext _context = new GaptDbContext(); var userId = User.Identity.GetUserId(); var unlocked = _context.Proposals.Where(m => m.IsInEdit == true && m.UserEditing == userId).ToList(); foreach (Proposal p in unlocked) { p.Unlock(); } _context.SaveChanges(); AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); return(RedirectToAction("Index", "Home")); }
public ActionResult Delete(int id) { var reviewer = _context.Reviewers.SingleOrDefault(m => m.Id == id); if (reviewer == null) { return(HttpNotFound()); } var err = _context.ExternalReview_Reviewer.SingleOrDefault(m => m.ReviewerId == id); var proposal = _context.Proposals.SingleOrDefault(m => m.ExternalReviewId == err.ExternalReviewId); if (proposal == null || proposal.Submitted) { return(HttpNotFound()); } _context.ExternalReview_Reviewer.Remove(err); _context.Reviewers.Remove(reviewer); _context.SaveChanges(); return(RedirectToAction("Index", "ExternalReview", new { id = proposal.Id })); }
public ActionResult Jump(int id) { var proposal = _context.Proposals.SingleOrDefault(m => m.Id == id); if (proposal == null || !proposal.Submitted) { return(HttpNotFound()); } if (proposal.ApprovalId == null) { Approval a = new Approval(); proposal.Approval = a; Thread t = new Thread(); _context.Threads.Add(t); a.Thread = t; _context.Approvals.Add(a); _context.SaveChanges(); return(RedirectToAction("Approval", "Proposal", new { id = proposal.Id })); } else { return(RedirectToAction("Approval", "Proposal", new { id = proposal.Id })); } }
public ActionResult UnlockAll() { var userId = User.Identity.GetUserId(); var unlocked = _context.Proposals.Where(m => m.IsInEdit == true && m.UserEditing == userId).ToList(); foreach (Proposal p in unlocked) { p.Unlock(); } _context.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public ActionResult Save(RecommendationFicsFormViewModel vm) { var proposal = vm.Proposal; proposal = _context.Proposals.SingleOrDefault(m => m.Id == proposal.Id); if (proposal == null || !proposal.Submitted) { return(HttpNotFound()); } var recommendation = vm.Recommendation; var faculty = _context.Ref_Faculty.SingleOrDefault(m => m.Id == recommendation.FacultyId); if (faculty.Dean != User.Identity.GetUserId()) { return(HttpNotFound()); } if (recommendation.Selection == true) { //if a is chosen, set helddateB to a default date recommendation.HeldDateB = "01/01/0001"; } else { //if b is chosen, set helddateA to a default date recommendation.HeldDateA = "01/01/0001"; } if (!ModelState.IsValid) { return(View("Form", recommendation)); } var recommendationInDb = _context.RecommendationFics.SingleOrDefault(m => m.Id == recommendation.Id); recommendationInDb.HeldDateA = recommendation.HeldDateA; recommendationInDb.HeldDateB = recommendation.HeldDateB; recommendationInDb.SignedBy = User.Identity.GetUserId(); recommendationInDb.SignedDate = DateTime.Now; recommendationInDb.Selection = recommendation.Selection; _context.SaveChanges(); return(RedirectToAction("Approval", "Proposal", new { id = proposal.Id })); }
public ActionResult Jump(int id) { var proposal = _context.Proposals.SingleOrDefault(m => m.Id == id); if (proposal == null || proposal.Submitted) { return(HttpNotFound()); } if (proposal.ExternalReviewId == null) { ExternalReview er = new ExternalReview(); proposal.ExternalReview = er; _context.ExternalReviews.Add(er); _context.SaveChanges(); return(RedirectToAction("Index", "ExternalReview", new { id = proposal.Id })); } else { return(RedirectToAction("Index", "ExternalReview", new { id = proposal.Id })); } }
public ActionResult Jump(int id) { var proposal = _context.Proposals.SingleOrDefault(m => m.Id == id); if (proposal == null || proposal.Submitted) { return(HttpNotFound()); } if (proposal.IncomeExpenditureId == null) { IncomeExpenditure ie = new IncomeExpenditure(); proposal.IncomeExpenditure = ie; _context.IncomeExpenditures.Add(ie); _context.SaveChanges(); return(RedirectToAction("Index", "IncomeExpenditure", new { id = proposal.Id })); } else { return(RedirectToAction("Index", "IncomeExpenditure", new { id = proposal.Id })); } }
public ActionResult Jump(int id) { var proposal = _context.Proposals.SingleOrDefault(m => m.Id == id); var pr = _context.ProgrammeRationales.SingleOrDefault(c => c.Id == proposal.ProgrammeRationaleId); if (proposal == null || proposal.Submitted) { return(HttpNotFound()); } if (pr == null) { //if section B has not been visited yet return(RedirectToAction("Jump", "ProgrammeRationale", new { id = proposal.Id })); } if (pr.DemandId == null) { //if section demand has not been visited yet return(RedirectToAction("Jump", "Demand", new { id = proposal.Id })); } if (pr.PsId == null) { //if section ps has not been visited yet return(RedirectToAction("Jump", "ProgrammeStudy", new { id = proposal.Id })); } if (pr.TentativePsId == null) { TentativeP tp = new TentativeP(); pr.TentativeP = tp; _context.TentativePs.Add(tp); _context.SaveChanges(); return(RedirectToAction("Index", "TentativePs", new { id = proposal.Id })); } else { return(RedirectToAction("Index", "TentativePs", new { id = proposal.Id })); } }
public ActionResult Submit(int id) { var proposal = _context.Proposals.SingleOrDefault(m => m.Id == id); string errorMessage = null; if (proposal == null) { return(HttpNotFound()); } if (proposal.GeneralId == null) { errorMessage = "Section A not filled in yet."; } else if (proposal.ProgrammeRationaleId == null) { errorMessage = "Section B not filled in yet."; } else if (proposal.ExternalReviewId == null) { errorMessage = "Section C not filled in yet."; } else if (proposal.IncomeExpenditureId == null) { errorMessage = "Section D not filled in yet."; } else { var general = proposal.General; var pr = proposal.ProgrammeRationale; var er = proposal.ExternalReview; var ie = proposal.IncomeExpenditure; if (general.GetErrorMessage() != null) { errorMessage = general.GetErrorMessage(); } else if (pr.GetErrorMessage() != null) { errorMessage = pr.GetErrorMessage(); } else if (er.GetErrorMessage() != null) { errorMessage = er.GetErrorMessage(); } else if (ie.GetErrorMessage() != null) { errorMessage = ie.GetErrorMessage(); } } if (errorMessage != null) { // an error is present var ie = _context.IncomeExpenditures.SingleOrDefault(m => m.Id == proposal.IncomeExpenditureId); var statements = ie.GetStatements(); var viewModel = new IncomeExpenditureIndexViewModel { Proposal = proposal, Statements = statements, ErrorMessage = errorMessage }; return(View("../IncomeExpenditure/Index", viewModel)); } else { proposal.Submitted = true; _context.SaveChanges(); return(RedirectToAction("Index", "Proposal")); } }
public ActionResult Save(PvcApprovalFormViewModel vm, HttpPostedFileBase postedFile) { var proposal = vm.Proposal; proposal = _context.Proposals.SingleOrDefault(m => m.Id == proposal.Id); if (proposal == null || !proposal.Submitted || !proposal.HasFacultyApproval()) { return(HttpNotFound()); } var pvc = vm.PvcApproval; if (pvc.Selection == true) { //if a is chosen pvc.Upload = "_"; if (pvc.CouncilRef == true) { if (proposal.GetCouncilDecision() == null) { //refer to council var council = new CouncilDecision(); _context.CouncilDecisions.Add(council); var ipc = new InPrincipal_Council(); ipc.CouncilDecision = council; ipc.CouncilDecisionId = council.Id; ipc.InPrincipal = proposal.InPrincipal; ipc.InPrincipalId = proposal.InPrincipal.Id; _context.InPrincipal_Council.Add(ipc); } } else { pvc.CouncilRef = false; } if (proposal.GetSenateDecision() == null) { //refer to senate var senate = new SenateDecision(); _context.SenateDecisions.Add(senate); var ips = new InPrincipal_Senate(); ips.SenateDecision = senate; ips.SenateDecisionId = senate.Id; ips.InPrincipal = proposal.InPrincipal; ips.InPrincipalId = proposal.InPrincipal.Id; _context.InPrincipal_Senate.Add(ips); } } else { //if b is chosen if (postedFile != null) { string path = Server.MapPath("~/Uploads/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } postedFile.SaveAs(path + Path.GetFileName(postedFile.FileName.Replace(' ', '_'))); pvc.Upload = postedFile.FileName.Replace(' ', '_'); pvc.CouncilRef = null; proposal.InPrincipalApproved = false; } else { //return form var viewModel = new PvcApprovalFormViewModel { Proposal = proposal, PvcApproval = pvc }; return(View("Form", viewModel)); } } var pvcInDb = _context.PvcApprovals.SingleOrDefault(m => m.Id == pvc.Id); pvcInDb.Upload = pvc.Upload; pvcInDb.CouncilRef = pvc.CouncilRef; pvcInDb.SignedBy = User.Identity.GetUserId(); pvcInDb.SignedDate = DateTime.Now; pvcInDb.Selection = pvc.Selection; _context.SaveChanges(); return(RedirectToAction("InPrinciple", "Proposal", new { id = proposal.Id })); }
public ActionResult Save(YearFormViewModel vm) { var proposal = vm.Proposal; proposal = _context.Proposals.SingleOrDefault(m => m.Id == proposal.Id); if (proposal == null || proposal.Submitted) { return(HttpNotFound()); } if (!proposal.IsEditable(User.Identity.GetUserId())) { return(HttpNotFound()); } var year = vm.Year; if (!ModelState.IsValid) { return(View("Form", year)); } if (year.Id == 0) { _context.Years.Add(year); var pr = _context.ProgrammeRationales.SingleOrDefault(m => m.Id == proposal.ProgrammeRationaleId); year.TentativeP = pr.TentativeP; year.TentativePsId = pr.TentativePsId; } else { var yearInDb = _context.Years.SingleOrDefault(m => m.Id == year.Id); yearInDb.TotalEcts = year.TotalEcts; if (year.YearNo != null) { var maxYearNo = _context.Database.SqlQuery <int>("Select Max(YearNo) From dbo.Year Where TentativePsId = " + yearInDb.TentativePsId).First() + 5; if (year.YearNo <= maxYearNo) { // check that no year exists with the same number var takenYearNos = _context.Database.SqlQuery <int>("Select YearNo From dbo.Year Where TentativePsId = " + yearInDb.TentativePsId).ToList(); if (!takenYearNos.Contains((int)year.YearNo)) { yearInDb.YearNo = year.YearNo; } else { return(HttpNotFound()); } } else { return(HttpNotFound()); } } // remove exsting Year_Units where TentativePsId == tentative.Id var toRemove = _context.Year_Unit.Where(m => m.YearId == year.Id).ToList(); foreach (Year_Unit yu in toRemove.ToList()) { var unit = _context.Ref_Unit.SingleOrDefault(m => m.Id == yu.UnitId); var dept = unit.Ref_Department; var stm = dept.GetServStatement(proposal.Id); if (stm != null) { if (stm.Selection == true) { toRemove.Remove(yu); } } } _context.Year_Unit.RemoveRange(toRemove); //string queryYu = "DELETE FROM dbo.Year_Unit WHERE YearId = " + year.Id; //_context.Database.ExecuteSqlCommand(queryYu); } foreach (string name in Request.Form.AllKeys) { try { int unitId = Convert.ToInt32(name); Year_Unit yu = new Year_Unit(); yu.YearId = year.Id; yu.Year = _context.Years.SingleOrDefault(m => m.Id == year.Id); yu.UnitId = unitId; yu.Coe = Convert.ToInt32(Request["coe_" + name]); if (Request["lecturer_" + name] != "null") { yu.Lecturer = Request["lecturer_" + name]; } else { yu.Lecturer = null; } if (Request["credits_" + name] != "") { yu.Ects = Convert.ToInt32(Request["credits_" + name]); } //if (Request["lecturer_" + name] != "") //{ // yu.Lecturer = Request["lecturer_" + name]; //} yu.Period = Convert.ToInt32(Request["period_" + name]); if (proposal.GetGeneral().LevelId == 1) { // if UG, check if compensating was selected if (Request["comp_" + name] == "on") { yu.Compensating = 1; yu.CompensatingReason = null; } else { yu.Compensating = 0; if (Request["reason_" + name] != "") { yu.CompensatingReason = Request["reason_" + name]; } } } else { yu.Compensating = 0; yu.CompensatingReason = "Compensated passes are not applicable for PG courses."; } _context.Year_Unit.Add(yu); _context.SaveChanges(); } catch (Exception e) { } } _context.SaveChanges(); var jump = Request["jump"]; switch (jump) { case "0": { // Save pressed return(RedirectToAction("Index", "TentativePs", new { id = proposal.Id })); } case "1": { // New unit pressed return(RedirectToAction("New", "Unit", new { yearRedirect = year.Id })); } default: { return(RedirectToAction("Index", "TentativePs", new { id = proposal.Id })); } } }
public ActionResult Save(SenateDecisionFormViewModel vm) { var proposal = vm.Proposal; proposal = _context.Proposals.SingleOrDefault(m => m.Id == proposal.Id); if (proposal == null || !proposal.Submitted || !proposal.HasFacultyApproval()) { return(HttpNotFound()); } var senate = vm.SenateDecision; if (!ModelState.IsValid) { //return form var viewModel = new SenateDecisionFormViewModel { Proposal = proposal, SenateDecision = senate }; return(View("Form", viewModel)); } if (senate.Selection == true) { //if a is chosen var pvc = proposal.GetPvcApproval(); if (pvc.CouncilRef == false) { //not referred to council proposal.InPrincipalApproved = true; } else { var council = proposal.GetCouncilDecision(); if (council.SignedBy != null) { if (council.Selection == true) { //council also approved proposal.InPrincipalApproved = true; } else { proposal.InPrincipalApproved = false; } } } } else { //if b is chosen proposal.InPrincipalApproved = false; } var senateInDb = _context.SenateDecisions.SingleOrDefault(m => m.Id == senate.Id); senateInDb.SignedBy = User.Identity.GetUserId(); senateInDb.SignedDate = DateTime.Now; senateInDb.Selection = senate.Selection; _context.SaveChanges(); return(RedirectToAction("InPrinciple", "Proposal", new { id = proposal.Id })); }
public ActionResult Save(DemandFormViewModel vm) { var demand = vm.Demand; var proposal = _context.Proposals.SingleOrDefault(m => m.Id == vm.Proposal.Id); if (proposal == null) { return(HttpNotFound()); } if (proposal.Submitted) { return(Content("Proposal already submitted")); } if (!ModelState.IsValid) { return(View("Form", demand)); } if (demand.Id == 0) { _context.Demands.Add(demand); var pr = _context.ProgrammeRationales.SingleOrDefault(m => m.Id == proposal.Id); pr.DemandId = demand.Id; pr.Demand = demand; } else { var demandInDb = _context.Demands.SingleOrDefault(m => m.Id == demand.Id); demandInDb.Description = demand.Description; demandInDb.Period = demand.Period; } _context.SaveChanges(); var jump = Request["jump"]; switch (jump) { case "0": { // Save pressed -> return form return(RedirectToAction("Edit", "Demand", new { id = proposal.Id })); } case "-1": { // Previous pressed -> return form return(RedirectToAction("Edit", "Rationale", new { id = proposal.Id })); } case "1": { // Next pressed -> return next page return(RedirectToAction("Jump", "ProgrammeStudy", new { id = proposal.Id })); } case "A": { // A pressed -> go to Section A return(RedirectToAction("Edit", "General", new { id = proposal.Id })); } case "B": { // B pressed -> go to Section B return(RedirectToAction("Jump", "ProgrammeRationale", new { id = proposal.Id })); } case "C": { // C pressed -> go to Section C return(RedirectToAction("Jump", "ExternalReview", new { id = proposal.Id })); } case "D": { // D pressed -> go to Section D return(RedirectToAction("Jump", "IncomeExpenditure", new { id = proposal.Id })); } default: { return(RedirectToAction("Index", "Proposal")); } } }
public ActionResult Save(TentativePsFormViewModel vm) { var tentative = vm.TentativePs; var proposal = _context.Proposals.SingleOrDefault(m => m.Id == vm.Proposal.Id); if (!ModelState.IsValid) { return(View("Form", tentative)); } if (tentative.Id == 0) { _context.TentativePs.Add(tentative); var pr = _context.ProgrammeRationales.SingleOrDefault(m => m.Id == proposal.Id); pr.TentativePsId = tentative.Id; pr.TentativeP = tentative; var addedYears = new List <int>(); foreach (string name in Request.Form.AllKeys) { try { int n = Convert.ToInt32(name); int yearNo = Convert.ToInt32(Request["year_" + name]); if (!addedYears.Contains(yearNo)) { addedYears.Add(yearNo); Year year = new Year(); year.TentativePsId = tentative.Id; year.TentativeP = tentative; year.YearNo = yearNo; year.TotalEcts = 0; _context.Years.Add(year); _context.SaveChanges(); } Year yearInDb = _context.Years.SingleOrDefault(m => m.TentativePsId == tentative.Id && m.YearNo == yearNo); Year_Unit yu = new Year_Unit(); yu.YearId = yearInDb.Id; yu.Year = _context.Years.SingleOrDefault(m => m.Id == yearInDb.Id); yu.UnitId = n; yu.Coe = Convert.ToInt32(Request["coe_" + name]); yu.Ects = Convert.ToInt32(Request["credits_" + name]); yu.Period = Convert.ToInt32(Request["period_" + name]); yu.Lecturer = Request["lecturer_" + name]; _context.Year_Unit.Add(yu); _context.SaveChanges(); //return Content(name + " " + Request["lecturer_" + name] + " " + Request["credits_" + name]); } catch (Exception e) { } } } else { //save all yearno, ects pairs to dictionary SortedDictionary <int, int> pairs = new SortedDictionary <int, int>(); string query = "Select YearNo From dbo.Year Where TentativePsId = " + tentative.Id; var yearNos = _context.Database.SqlQuery <int>(query).ToList(); foreach (int yearNo in yearNos) { string q = "Select TotalEcts From dbo.Year Where YearNo = " + yearNo + " and TentativePsId = " + tentative.Id; int ects = _context.Database.SqlQuery <int>(q).Single(); pairs.Add(yearNo, ects); } // remove exsting Year_Units and Years where TentativePsId == tentative.Id string queryYu = "DELETE FROM dbo.Year_Unit WHERE YearId in (Select Id From dbo.Year Where TentativePsId = " + tentative.Id + "); "; string queryY = "DELETE FROM dbo.Year Where TentativePsId = " + tentative.Id; _context.Database.ExecuteSqlCommand(queryYu); _context.Database.ExecuteSqlCommand(queryY); var addedYears = new List <int>(); foreach (string name in Request.Form.AllKeys) { try { int n = Convert.ToInt32(name); int yearNo = Convert.ToInt32(Request["year_" + name]); if (!addedYears.Contains(yearNo)) { addedYears.Add(yearNo); Year year = new Year(); year.TentativePsId = tentative.Id; year.YearNo = yearNo; if (pairs.ContainsKey(yearNo)) { year.TotalEcts = pairs[yearNo]; } else { year.TotalEcts = 0; } _context.Years.Add(year); _context.SaveChanges(); } Year yearInDb = _context.Years.SingleOrDefault(m => m.TentativePsId == tentative.Id && m.YearNo == yearNo); Year_Unit yu = new Year_Unit(); yu.YearId = yearInDb.Id; yu.Year = _context.Years.SingleOrDefault(m => m.Id == yearInDb.Id); yu.UnitId = n; yu.Coe = Convert.ToInt32(Request["coe_" + name]); yu.Ects = Convert.ToInt32(Request["credits_" + name]); yu.Period = Convert.ToInt32(Request["period_" + name]); yu.Lecturer = Request["lecturer_" + name]; _context.Year_Unit.Add(yu); _context.SaveChanges(); } catch (Exception e) { } } } _context.SaveChanges(); var jump = Request["jump"]; switch (jump) { case "0": { // Save pressed -> return form return(RedirectToAction("Edit", "TentativePs", new { id = proposal.Id })); } case "-1": { // Previous pressed -> return form return(RedirectToAction("Edit", "ProgrammeStudy", new { id = proposal.Id })); } case "1": { // Next pressed -> return next page return(RedirectToAction("YearTotals", "TentativePs", new { id = proposal.Id })); } case "A": { // A pressed -> go to Section A return(RedirectToAction("Edit", "General", new { id = proposal.Id })); } case "B": { // B pressed -> go to Section B return(RedirectToAction("Edit", "Rationale", new { id = proposal.Id })); } case "C": { // C pressed -> go to Section C return(RedirectToAction("Jump", "ExternalReview", new { id = proposal.Id })); } default: { return(RedirectToAction("Index", "Proposal")); } } }
public ActionResult Save(ProgrammeStudyFormViewModel vm) { var programmeStudy = vm.ProgrammeStudy; var proposal = _context.Proposals.SingleOrDefault(m => m.Id == vm.Proposal.Id); if (proposal == null) { return(HttpNotFound()); } if (proposal.Submitted) { return(Content("Proposal already submitted")); } if (!ModelState.IsValid) { return(View("Form", programmeStudy)); } if (programmeStudy.Id == 0) { _context.ProgrammeOfStudies.Add(programmeStudy); var pr = _context.ProgrammeRationales.SingleOrDefault(m => m.Id == proposal.Id); pr.PsId = programmeStudy.Id; pr.ProgrammeOfStudy = programmeStudy; } else { var psInDb = _context.ProgrammeOfStudies.SingleOrDefault(m => m.Id == programmeStudy.Id); psInDb.KnowledgeUnderstanding = programmeStudy.KnowledgeUnderstanding; psInDb.IntellectualDevelopment = programmeStudy.IntellectualDevelopment; psInDb.KeyTransferableSkills = programmeStudy.KeyTransferableSkills; psInDb.OtherSkills = programmeStudy.OtherSkills; } _context.SaveChanges(); var jump = Request["jump"]; switch (jump) { case "0": { // Save pressed -> return form return(RedirectToAction("Edit", "ProgrammeStudy", new { id = proposal.Id })); } case "-1": { // Previous pressed -> return form return(RedirectToAction("Edit", "Demand", new { id = proposal.Id })); } case "1": { // Next pressed -> return next page //return RedirectToAction("Jump", "TentativePs", new { id = proposal.Id }); return(RedirectToAction("Jump", "TentativePs", new { id = proposal.Id })); } case "A": { // A pressed -> go to Section A return(RedirectToAction("Edit", "General", new { id = proposal.Id })); } case "B": { // B pressed -> go to Section B return(RedirectToAction("Jump", "ProgrammeRationale", new { id = proposal.Id })); } case "C": { // C pressed -> go to Section C return(RedirectToAction("Jump", "ExternalReview", new { id = proposal.Id })); } case "D": { // D pressed -> go to Section D return(RedirectToAction("Jump", "IncomeExpenditure", new { id = proposal.Id })); } default: { return(RedirectToAction("Index", "Proposal")); } } }
public ActionResult Save(GeneralFormViewModel vm) { var general = vm.General; List <Department_General> removed = new List <Department_General>(); List <Department_General> added = new List <Department_General>(); if (!ModelState.IsValid) { //foreach (ModelState modelState in ViewData.ModelState.Values) //{ // foreach (ModelError error in modelState.Errors) // { // return Content(error.ErrorMessage); // } //} return(View("Form", general)); } if (general.Id == 0) { Thread t = new Thread(); _context.Threads.Add(t); general.Thread = t; _context.Generals.Add(general); var proposal = new Proposal(); proposal.GeneralId = general.Id; proposal.CreatedOn = DateTime.Now; proposal.CreatedBy = User.Identity.GetUserId(); proposal.IsInEdit = true; proposal.UserEditing = User.Identity.GetUserId(); _context.Proposals.Add(proposal); } else { var proposal = _context.Proposals.SingleOrDefault(m => m.GeneralId == general.Id); if (proposal == null) { return(HttpNotFound()); } if (!proposal.IsEditable(User.Identity.GetUserId())) { return(HttpNotFound()); } if (proposal.Submitted) { return(Content("Proposal already submitted")); } var changedLevel = false; var generalInDb = _context.Generals.SingleOrDefault(m => m.Id == general.Id); if (generalInDb.LevelId != general.LevelId) { changedLevel = true; } generalInDb.Title = general.Title; generalInDb.LevelId = general.LevelId; generalInDb.Ref_Level = _context.Ref_Level.SingleOrDefault(m => m.Id == general.LevelId); generalInDb.AreasStudy = general.AreasStudy; generalInDb.FacultyId = general.FacultyId; generalInDb.Ref_Faculty = general.Ref_Faculty; generalInDb.DeliveryId = general.DeliveryId; generalInDb.Ref_Delivery = _context.Ref_Delivery.SingleOrDefault(m => m.Id == general.DeliveryId); generalInDb.DurationSemesters = general.DurationSemesters; generalInDb.FirstDateIntake = general.FirstDateIntake; generalInDb.ExpectedStudents = general.ExpectedStudents; if (general.MaxStudents == null) { generalInDb.CappingReason = null; } else { generalInDb.CappingReason = general.CappingReason; } generalInDb.MaxStudents = general.MaxStudents; //remove departments, to be added again later var toRemove = _context.Department_General.Where(m => m.GeneralId == general.Id).ToList(); //remove proposers and shared, to be added again later var proposersToRemove = _context.Proposer_General.Where(m => m.GeneralId == general.Id).ToList(); var sharedToRemove = _context.Shared_General.Where(m => m.GeneralId == general.Id).ToList(); var typesToRemove = _context.Type_General.Where(m => m.GeneralId == general.Id).ToList(); foreach (Department_General dg in toRemove.ToList()) { if (dg.Type == 3) { //servicing var dept = dg.Ref_Department; //does not remove if approval accepted var stm = dept.GetServStatement(proposal.Id); if (stm != null) { if (stm.Selection == true) { toRemove.Remove(dg); } } } } removed = toRemove; _context.Department_General.RemoveRange(toRemove); _context.Proposer_General.RemoveRange(proposersToRemove); _context.Shared_General.RemoveRange(sharedToRemove); _context.Type_General.RemoveRange(typesToRemove); _context.SaveChanges(); //if level changed -> change existing year_units if (changedLevel) { if (general.LevelId == 2) { if (proposal.ProgrammeRationale != null) { if (proposal.ProgrammeRationale.TentativeP != null) { var tentative = proposal.ProgrammeRationale.TentativeP; var years = tentative.GetYears(); foreach (Year y in years) { var yus = y.GetYearUnits(); foreach (Year_Unit yu in yus) { var yuInDb = _context.Year_Unit.Single(m => m.Id == yu.Id); yuInDb.Compensating = 0; yuInDb.CompensatingReason = "Compensated passes are not applicable for PG courses."; } } } } } else { //switch reasons to null if they were PG default if (proposal.ProgrammeRationale != null) { if (proposal.ProgrammeRationale.TentativeP != null) { var tentative = proposal.ProgrammeRationale.TentativeP; var years = tentative.GetYears(); foreach (Year y in years) { var yus = y.GetYearUnits(); foreach (Year_Unit yu in yus) { var yuInDb = _context.Year_Unit.Single(m => m.Id == yu.Id); if (yuInDb.Compensating == 0 && yuInDb.CompensatingReason == "Compensated passes are not applicable for PG courses.") { yuInDb.CompensatingReason = null; } } } } } } } } _context.SaveChanges(); if (vm.SelectedInitDepts != null) { foreach (string s in vm.SelectedInitDepts) { var department = _context.Ref_Department.SingleOrDefault(m => m.Id.ToString() == s); Department_General dg = new Department_General(department.Id, general.Id, 1); var existing = _context.Department_General.Where(m => m.DepartmentId == department.Id && m.GeneralId == general.Id).ToList(); if (existing.Count == 0) { _context.Department_General.Add(dg); added.Add(dg); } } } _context.SaveChanges(); if (vm.SelectedCollabDepts != null) { foreach (string s in vm.SelectedCollabDepts) { var department = _context.Ref_Department.SingleOrDefault(m => m.Id.ToString() == s); Department_General dg = new Department_General(department.Id, general.Id, 2); var existing = _context.Department_General.Where(m => m.DepartmentId == department.Id && m.GeneralId == general.Id).ToList(); if (existing.Count == 0) { _context.Department_General.Add(dg); added.Add(dg); } } } _context.SaveChanges(); if (vm.SelectedServDepts != null) { foreach (string s in vm.SelectedServDepts) { var department = _context.Ref_Department.SingleOrDefault(m => m.Id.ToString() == s); Department_General dg = new Department_General(department.Id, general.Id, 3); var existing = _context.Department_General.Where(m => m.DepartmentId == department.Id && m.GeneralId == general.Id).ToList(); if (existing.Count == 0) { _context.Department_General.Add(dg); added.Add(dg); } } } if (vm.SelectedTypes != null) { foreach (string s in vm.SelectedTypes) { var type = _context.Ref_Type.SingleOrDefault(m => m.Id.ToString() == s); Type_General tg = new Type_General(type.Id, general.Id); _context.Type_General.Add(tg); } } List <int> removedDepIds = new List <int>(); foreach (Department_General dg in removed) { var f = false; foreach (Department_General adg in added) { if ((dg.DepartmentId == adg.DepartmentId) && (dg.GeneralId == adg.GeneralId)) { f = true; } } if (f == true) { continue; } else { removedDepIds.Add(dg.DepartmentId); //return Content("removed " + dg.DepartmentId); } } if (vm.SelectedProposers != null) { ApplicationDbContext adb = new ApplicationDbContext(); foreach (string s in vm.SelectedProposers) { var user = adb.Database.SqlQuery <ApplicationUser>("Select * from dbo.AspNetUsers Where Id = '" + s + "'").First(); Proposer_General pg = new Proposer_General(user.Id, general.Id); _context.Proposer_General.Add(pg); } } if (vm.SelectedShared != null) { ApplicationDbContext adb = new ApplicationDbContext(); foreach (string s in vm.SelectedShared) { var user = adb.Database.SqlQuery <ApplicationUser>("Select * from dbo.AspNetUsers Where Id = '" + s + "'").First(); Shared_General sg = new Shared_General(user.Id, general.Id); _context.Shared_General.Add(sg); } } _context.SaveChanges(); var jump = Request["jump"]; var prop = general.GetProposal(); var pr = _context.ProgrammeRationales.SingleOrDefault(m => m.Id == prop.ProgrammeRationaleId); if (pr != null) { if (pr.TentativePsId != null) { var tentativePs = pr.TentativeP; var years = tentativePs.GetYears(); foreach (Year year in years) { var year_units = year.GetYearUnits(); foreach (Year_Unit yu in year_units) { if (removedDepIds.Contains(yu.GetUnit().DepartmentId)) { var yuInDb = _context.Year_Unit.SingleOrDefault(m => m.Id == yu.Id); _context.Year_Unit.Remove(yuInDb); } } } } } _context.Database.ExecuteSqlCommand("Update dbo.GeneralHistory Set EditedBy = '" + User.Identity.GetUserId() + "' Where GeneralId = " + general.Id + " and EditedBy is null"); _context.SaveChanges(); switch (jump) { case "0": { // Save pressed -> return form return(RedirectToAction("Edit", "General", new { id = general.Id })); } case "1": { // Next pressed -> return next page return(RedirectToAction("Jump", "ProgrammeRationale", new { id = prop.Id })); } case "2": { // Save and exit return(RedirectToAction("CloseEdit", "Proposal", new { id = prop.Id })); } case "A": { // A pressed -> go to Section A return(RedirectToAction("Edit", "General", new { id = general.Id })); } case "B": { // B pressed -> go to Section B return(RedirectToAction("Jump", "ProgrammeRationale", new { id = prop.Id })); } case "C": { // C pressed -> go to Section C return(RedirectToAction("Jump", "ExternalReview", new { id = prop.Id })); } case "D": { // D pressed -> go to Section D return(RedirectToAction("Jump", "IncomeExpenditure", new { id = prop.Id })); } default: { return(RedirectToAction("Index", "Proposal")); } } }
public ActionResult Save(YearFormViewModel vm) { var proposal = vm.Proposal; proposal = _context.Proposals.SingleOrDefault(m => m.Id == proposal.Id); if (proposal == null || proposal.Submitted) { return(HttpNotFound()); } var year = vm.Year; if (!ModelState.IsValid) { return(View("Form", year)); } if (year.Id == 0) { _context.Years.Add(year); var pr = _context.ProgrammeRationales.SingleOrDefault(m => m.Id == proposal.Id); year.TentativeP = pr.TentativeP; year.TentativePsId = pr.TentativePsId; } else { var yearInDb = _context.Years.SingleOrDefault(m => m.Id == year.Id); yearInDb.TotalEcts = year.TotalEcts; // remove exsting Year_Units where TentativePsId == tentative.Id string queryYu = "DELETE FROM dbo.Year_Unit WHERE YearId = " + year.Id; _context.Database.ExecuteSqlCommand(queryYu); } foreach (string name in Request.Form.AllKeys) { try { int unitId = Convert.ToInt32(name); Year_Unit yu = new Year_Unit(); yu.YearId = year.Id; yu.Year = _context.Years.SingleOrDefault(m => m.Id == year.Id); yu.UnitId = unitId; yu.Coe = Convert.ToInt32(Request["coe_" + name]); if (Request["credits_" + name] != "") { yu.Ects = Convert.ToInt32(Request["credits_" + name]); } if (Request["lecturer_" + name] != "") { yu.Lecturer = Request["lecturer_" + name]; } yu.Period = Convert.ToInt32(Request["period_" + name]); if (proposal.GetGeneral().LevelId == 1) { // if UG, check if compensating was selected if (Request["comp_" + name] == "on") { yu.Compensating = 1; } else { yu.Compensating = 0; if (Request["reason_" + name] != "") { yu.CompensatingReason = Request["reason_" + name]; } } } else { yu.Compensating = 0; } _context.Year_Unit.Add(yu); _context.SaveChanges(); } catch (Exception e) { } } _context.SaveChanges(); var jump = Request["jump"]; switch (jump) { case "0": { // Save pressed return(RedirectToAction("Index", "TentativePs", new { id = proposal.Id })); } case "1": { // New unit pressed return(RedirectToAction("New", "Unit", new { yearRedirect = year.Id })); } default: { return(RedirectToAction("Index", "TentativePs", new { id = proposal.Id })); } } }