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> PutUserTestMapping([FromRoute] int id, [FromBody] UserTestMapping userTestMapping)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userTestMapping.Id)
            {
                return(BadRequest());
            }

            _context.Entry(userTestMapping).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserTestMappingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PostUserTestMapping([FromBody] UserTestMapping userTestMapping)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.UserTestMapping.Add(userTestMapping);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetUserTestMapping", new { id = userTestMapping.Id }, userTestMapping));
        }
예제 #4
0
        public async Task <IActionResult> AthletesList([FromForm] AthletesViewModel athletesViewModel)
        {
            var             users           = _dbContext.User.Where(s => s.Name == athletesViewModel.AName);
            UserTestMapping userTestMapping = new UserTestMapping();
            TestDetails     testDetails     = new TestDetails();
            TestTypeMapping typeMapping     = new TestTypeMapping();

            typeMapping.TestId = testDetails.ID;
            _dbContext.UserTestMapping.Add(userTestMapping);
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction("TestAthleteDetails", new { id = testId }));
        }
 public async Task <IActionResult> Edit(int id, [Bind("Id,Distance,Time,FitnessRating,TId,UId")] UserTestMapping userTestMapping)
 {
     if (id != userTestMapping.Id)
     {
         return(NotFound());
     }
     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";
     }
     if (ModelState.IsValid)
     {
         try
         {
             _context.Update(userTestMapping);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!UserTestMappingExists(userTestMapping.Id))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         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);
     return(View(userTestMapping));
 }
예제 #6
0
        // PUT: Main/TestAthleteDetails/PutEdit/5
        // [HttpPut]
        public IActionResult PutEdit([FromForm] UserTestMapping userTestMapping)
        {
            var obj = _dbContext.UserTestMapping.Where(s => s.UserId == userTestMapping.UserId && s.TestId == userTestMapping.TestId).First();

            if (userTestMapping.CTDistance != null)
            {
                obj.CTDistance = userTestMapping.CTDistance;
            }
            else if (userTestMapping.STTime != null)
            {
                obj.STTime = userTestMapping.STTime;
            }

            _dbContext.UserTestMapping.Update(obj);
            _dbContext.SaveChanges();
            return(RedirectToAction("TestAthleteDetails", new { id = testId }));
        }
예제 #7
0
        public async Task <IActionResult> NewAthlete([FromForm] AthletesViewModel athletesViewModel)
        {
            UserTestMapping userTest = new UserTestMapping();
            //var NewA = _dbContext.User.Where(s => s.ID == athletesViewModel.UserId).Select(s => s.Name);
            var NewA = _dbContext.User.Where(s => s.Name == athletesViewModel.AName).Select(s => s.ID).First();

            userTest.UserId = NewA;

            if (athletesViewModel.CTDistance != null)
            {
                userTest.FitnessRating = CalculateFitness(athletesViewModel.CTDistance);
            }

            userTest.TestId     = testId;
            userTest.CTDistance = athletesViewModel.CTDistance;
            //userTest.FitnessRating = CalculateFitness(athletesViewModel.CTDistance);
            userTest.STTime = athletesViewModel.STTime;

            _dbContext.UserTestMapping.Add(userTest);

            await _dbContext.SaveChangesAsync();

            return(RedirectToAction("TestAthleteDetails", new { id = testId }));
        }