public async Task <IActionResult> EditProject(int id) { var project = await _context.Project .Include(p => p.CurrentPositions) .FirstOrDefaultAsync(q => q.Id == id); var editingProject = new NewProjectAndPositions() { Id = project.Id, Title = project.Title, Description = project.Description, StartDate = project.StartDate, Budget = project.Budget, Active = project.Active, DirectorId = project.DirectorId, Positions = new List <string>() }; foreach (ProjectPosition position in project.CurrentPositions) { if (position.TalentId == null) { editingProject.Positions.Add(position.Postion); } } ViewBag.currentPositions = project.CurrentPositions.ToList(); return(View(editingProject)); }
public async Task <IActionResult> EditProject(int id, [Bind("Id, Active, Title, Budget, Description, StartDate, DirectorId, Positions")] NewProjectAndPositions model) { if (id != model.Id) { return(NotFound()); } if (ModelState.IsValid) { try { Project project = new Project() { Id = model.Id, Title = model.Title, Description = model.Description, Budget = model.Budget, Active = model.Active, StartDate = model.StartDate, DirectorId = model.DirectorId }; _context.Project.Update(project); await _context.SaveChangesAsync(); if (model.Positions != null) { var positionsAdded = await UpdatePositions(model.Positions, model.Id); } return(RedirectToAction(nameof(AllProjects), new ProjectListRoute() { index = 1, viewingyours = false })); } catch (DbUpdateConcurrencyException) { if (!ProjectExists(model.Id)) { return(NotFound()); } else { throw; } } } return(View(model)); }
public async Task <IActionResult> CreateProject([Bind("Title,Budget,Description,Positions")] NewProjectAndPositions model) { ModelState.Remove("Director"); ModelState.Remove("Active"); ModelState.Remove("Id"); ModelState.Remove("StartDate"); ModelState.Remove("EndDate"); if (ModelState.IsValid) { var user = await GetCurrentUserAsync(); var director = await _context.Director .FirstOrDefaultAsync(d => d.ApplicationUserId == user.Id); Project project = new Project() { Id = 0, Title = model.Title, Description = model.Description, Budget = model.Budget, Active = true, StartDate = System.DateTime.Now, DirectorId = director.Id }; _context.Project.Add(project); await _context.SaveChangesAsync(); if (model.Positions != null) { var positionsAdded = await AddPositions(model.Positions, project.StartDate, director.Id); } return(RedirectToAction(nameof(AllProjects), new ProjectListRoute() { index = 1, viewingyours = false })); } return(View()); }