public async Task <IActionResult> Create([Bind("Id,Distance,Time,FitnessRating,TId,UId")] UserTestMapping userTestMapping)
        {
            if (ModelState.IsValid)
            {
                if (userTestMapping.Distance <= 1000)
                {
                    userTestMapping.FitnessRating = "Below Average";
                }
                else if (userTestMapping.Distance > 1000 && userTestMapping.Distance <= 2000)
                {
                    userTestMapping.FitnessRating = "Average";
                }
                else if (userTestMapping.Distance > 2000 && userTestMapping.Distance <= 3500)
                {
                    userTestMapping.FitnessRating = "Good";
                }
                else if (userTestMapping.Distance > 3500)
                {
                    userTestMapping.FitnessRating = "Very good";
                }
                _context.Add(userTestMapping);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "Tests", new { Id = userTestMapping.TId }));
            }
            ViewData["TId"]  = new SelectList(_context.Test, "Id", "Id", userTestMapping.TId);
            ViewData["UId"]  = new SelectList(_context.User.Where(k => k.Type != "Coach"), "Id", "Name", userTestMapping.UId);
            TempData["dist"] = "na";
            TempData["time"] = "na";
            return(View(userTestMapping));
        }
        public async Task <IActionResult> Create([Bind("Id,Type,Date")] Test test)
        {
            if (ModelState.IsValid)
            {
                _context.Add(test);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(test));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Type")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

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