Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(BaseTimeOffViewModel model)
        {
            if (ModelState.IsValid)
            {
                PaidTimeOff timeOff = new PaidTimeOff()
                {
                    From       = model.From,
                    To         = model.To,
                    CreatedOn  = DateTime.Now,
                    IsHalfDay  = model.IsHalfDay,
                    IsApproved = model.IsApproved,
                    Requestor  = model.Requestor
                };

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

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