예제 #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));
        }
예제 #2
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));
        }
예제 #3
0
        public async Task CanGetPlan()
        {
            DbContextOptions <VacationDbContext> options = new DbContextOptionsBuilder <VacationDbContext>()
                                                           .UseInMemoryDatabase("CanGetActivityInCity")
                                                           .Options;

            using (VacationDbContext context = new VacationDbContext(options))
            {
                PlanService service = new PlanService(context);

                City testCity = new City();
                testCity.ID          = 1;
                testCity.Name        = "Seattle";
                testCity.Description = "Test";
                testCity.ImageURL    = "test.url";
                testCity.Hot         = 0;
                testCity.InUSA       = 1;
                testCity.Price       = 3;
                context.City.Add(testCity);
                await context.SaveChangesAsync();

                Hotel testHotel = new Hotel();
                testHotel.CityID = 1;
                testHotel.Name   = "Seattle Hotel";
                testHotel.Price  = 3;

                context.Hotel.Add(testHotel);
                await context.SaveChangesAsync();

                Activity testActivity = new Activity();
                testActivity.CityID         = 1;
                testActivity.Name           = "Seattle Strolling";
                testActivity.Outdoors       = 1;
                testActivity.FamilyFriendly = 0;

                context.Activity.Add(testActivity);
                await context.SaveChangesAsync();

                Plan result = await service.GetPlan("1,0,3,0,1");

                Assert.Equal("Seattle", result.City.Name);
                Assert.Equal("Seattle Hotel", result.Hotel.Name);
                Assert.Equal("Seattle Strolling", result.Activity.Name);
            }
        }
예제 #4
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));
        }
예제 #5
0
        public async Task SaveVacationPlanInDb()
        {
            DbContextOptions <VacationDbContext> options = new DbContextOptionsBuilder <VacationDbContext>()
                                                           .UseInMemoryDatabase("SavingPlanInDb")
                                                           .Options;

            City testCity = new City();

            testCity.ID          = 1;
            testCity.Name        = "Seattle";
            testCity.Description = "Test";
            testCity.ImageURL    = "test.url";
            testCity.Hot         = 0;
            testCity.InUSA       = 1;
            testCity.Price       = 3;

            Hotel testHotel = new Hotel();

            testHotel.ID     = 1;
            testHotel.CityID = 1;
            testHotel.Name   = "Seattle Hotel";
            testHotel.Price  = 3;

            Activity testActivity = new Activity();

            testActivity.ID             = 1;
            testActivity.Name           = "Seattle Strolling";
            testActivity.Outdoors       = 1;
            testActivity.FamilyFriendly = 0;

            using (VacationDbContext context = new VacationDbContext(options))
            {
                Plan testPlan = new Plan();
                testPlan.City     = testCity;
                testPlan.Hotel    = testHotel;
                testPlan.Activity = testActivity;
                // Convert RecommendationCode to a string type
                testPlan.RecommendationCode = testCity.ID + testHotel.ID + testActivity.ID;

                context.SavedVacation.Add(testPlan);
                await context.SaveChangesAsync();

                Plan result = await context.SavedVacation.FirstOrDefaultAsync(x => x.City == testPlan.City);

                Assert.Equal("Seattle", result.City.Name);
                Assert.Equal("Seattle Hotel", result.Hotel.Name);
                Assert.Equal("Seattle Strolling", result.Activity.Name);
                Assert.Equal(3, result.RecommendationCode);
            }
        }
예제 #6
0
        public async Task CanGetHotelsInCity()
        {
            DbContextOptions <VacationDbContext> options = new DbContextOptionsBuilder <VacationDbContext>()
                                                           .UseInMemoryDatabase("CanGetHotelsInCity")
                                                           .Options;

            using (VacationDbContext context = new VacationDbContext(options))
            {
                PlanService service   = new PlanService(context);
                Hotel       testHotel = new Hotel();
                testHotel.CityID = 1;
                testHotel.Name   = "Seattle Hotel";
                testHotel.Price  = 3;

                context.Hotel.Add(testHotel);
                await context.SaveChangesAsync();

                Hotel result = await service.GetHotelInCity(1);

                Assert.Equal("Seattle Hotel", result.Name);
            }
        }
예제 #7
0
        public async Task CanGetActivityInCity()
        {
            DbContextOptions <VacationDbContext> options = new DbContextOptionsBuilder <VacationDbContext>()
                                                           .UseInMemoryDatabase("CanGetActivityInCity")
                                                           .Options;

            using (VacationDbContext context = new VacationDbContext(options))
            {
                PlanService service      = new PlanService(context);
                Activity    testActivity = new Activity();
                testActivity.CityID         = 3;
                testActivity.Name           = "Seattle Strolling";
                testActivity.Outdoors       = 1;
                testActivity.FamilyFriendly = 0;

                context.Activity.Add(testActivity);
                await context.SaveChangesAsync();

                Activity result = await service.GetActivityInCity(3);

                Assert.Equal("Seattle Strolling", result.Name);
            }
        }