Beispiel #1
0
        public async Task <IActionResult> Create(CreateTeamViewModel model)
        {
            if (ModelState.IsValid)
            {
                var devs = model.Developers.Select(c => _context.Users.FirstOrDefault(u => u.Id == c)).ToList();
                var team = new Team()
                {
                    Developers = devs,
                    TeamLeadID = model.TeamLeadId,
                    TeamName   = model.TeamName
                };
                _context.Add(team);
                await _context.SaveChangesAsync();

                var teamsDevelopers = devs.Select(c => new TeamDevelopers
                {
                    DeveloperId = c.Id,
                    TeamId      = team.ID
                });

                _context.AddRange(teamsDevelopers);
                await _context.SaveChangesAsync();


                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
        public async Task <IActionResult> Create(CreateProjectViewModel model)
        {
            if (ModelState.IsValid)
            {
                var teams = model.Teams.Select(c => _context.Teams.FirstOrDefault(u => u.ID == c)).ToList();

                var project = new Project
                {
                    Teams       = teams,
                    ProjectName = model.ProjectName,
                    Description = model.Description
                };

                _context.Add(project);
                await _context.SaveChangesAsync();

                var projectTeams = teams.Select(c => new ProjectTeams
                {
                    ProjectID = project.ID,
                    TeamID    = c.ID
                });

                _context.AddRange(projectTeams);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }