コード例 #1
0
        public async Task <IActionResult> Create(List <SportsSelector> sportsSelectors)
        {
            if (ModelState.IsValid)
            {
                var sports = _context.Sport;
                List <SportsSelector> SportsSelectors = new List <SportsSelector>();
                var uId         = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
                var user        = _context.Users.Where(u => u.Id == uId).FirstOrDefault();
                var myInterests = await _context.Interest.Where(i => i.User == user).ToListAsync();


                foreach (var sportSelected in sportsSelectors)
                {
                    if (!myInterests.Any(i => i.Sport == sportSelected.Sport) && sportSelected.IsChecked)
                    {
                        Interest interest = new Interest
                        {
                            User  = user,
                            Sport = _context.Sport.Where(s => s.Name == sportSelected.Sport.Name).FirstOrDefault()
                        };

                        _context.Add(interest);
                    }
                }

                await _context.SaveChangesAsync();
            }


            return(RedirectToAction("Index", "Home"));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Sport sport)
        {
            if (ModelState.IsValid)
            {
                _context.Add(sport);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(sport));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Id,Title,Body")] Message msg)
        {
            if (ModelState.IsValid)
            {
                _context.Add(msg);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(msg));
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("Id,Name,StreetAddress,City")] Gym gym)
        {
            if (ModelState.IsValid)
            {
                _context.Add(gym);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(gym));
        }
コード例 #5
0
        public async Task <IActionResult> Create([Bind("Id,Name,GymSelection")] GymSegment gymSegment)
        {
            if (ModelState.IsValid)
            {
                var gym = _context.Gym.Where(g => g.Id == Convert.ToInt32(gymSegment.GymSelection)).First();
                gymSegment.Gym = gym;

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

                return(RedirectToAction(nameof(Index)));
            }
            return(View(gymSegment));
        }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("Id,Name,StartTime,EndTime,Capacity,HouseholdsSharePlace,SignupMessage,SafetyConceptURL,SportsSelection,GymSelection,PublishingDate")] Training training)
        {
            if (ModelState.IsValid)
            {
                var sport = _context.Sport.Where(s => s.Id == training.SportsSelection).FirstOrDefault();
                training.Sport = sport;
                var gym = _context.Gym.Where(g => g.Id == training.GymSelection).FirstOrDefault();
                training.Gym     = gym;
                training.EndTime = new DateTime(training.StartTime.Year, training.StartTime.Month, training.StartTime.Day, training.EndTime.Hour, training.EndTime.Minute, 0);
                _context.Add(training);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(training));
        }
        public async Task <IActionResult> Create([Bind("tid")] TrainingsRegistration trainingsRegistration)
        {
            if (ModelState.IsValid)
            {
                trainingsRegistration.Training = await _context.Training.Where(t => t.Id == trainingsRegistration.tid).FirstOrDefaultAsync();

                var reservations = await _context.TrainingsRegistration.Include(t => t.Training).Where(t => t.Training == trainingsRegistration.Training).CountAsync();

                if (trainingsRegistration.Training.Capacity - reservations < 1)
                {
                    return(View(trainingsRegistration));
                }



                trainingsRegistration.UserId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
                _context.Add(trainingsRegistration);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Start", "Home"));
            }
            return(View(trainingsRegistration));
        }