/// <summary> /// Update the Participants id and distance of a certain test that matches the TestParticipationId supplied /// </summary> /// <param name="participantId"></param> /// <param name="TestParticipantsId"></param> /// <param name="distance"></param> /// <returns></returns> public async Task <TestParticipants> updateTestParticipants(int participantId, int TestParticipantsId, int distance) { var testPant = new TestParticipants(); try { if (participantId != 0 && TestParticipantsId != 0 && distance != 0) { testPant = (from x in _dbContext.TestParticipants where x.id == TestParticipantsId select x).FirstOrDefault(); if (testPant != null) { testPant.Participant.id = participantId; testPant.Result = distance.ToString(); } _dbContext.TestParticipants.Update(testPant); var result = await _dbContext.SaveChangesAsync(); } } catch (Exception ex) { throw ex; } return(testPant); }
/// <summary> /// Adding Users/Participants to Existing test in the database; /// </summary> /// <param name="atheleteId"></param> /// <param name="testGuid"></param> /// <param name="distance"></param> /// <returns></returns> public async Task <bool> addParticipantstoTest(int atheleteId, string testGuid, int distance) { var tPants = new TestParticipants(); var testByGuid = new Test(); var testUser = new User(); var isDone = false; try { if (atheleteId != 0 && !string.IsNullOrEmpty(testGuid) && distance != 0) //check for null values { testByGuid = (from x in _dbContext.Tests where x.guid == testGuid select x).FirstOrDefault(); //fetches tests testUser = (from c in _dbContext.Users where c.id == atheleteId select c).FirstOrDefault(); //fetches participants tPants.Result = distance.ToString(); tPants.Test = testByGuid; tPants.Participant = testUser; } await _dbContext.TestParticipants.AddAsync(tPants); var result = await _dbContext.SaveChangesAsync(); if (result > 0) { isDone = true; } } catch (Exception ex) { throw ex; } return(isDone); }
/// <summary> /// update a particular test entry for a registered user which criteria matches supplied params; /// </summary> /// <param name="participantId"></param> /// <param name="TestParticipantsId"></param> /// <param name="distance"></param> /// <returns></returns> public async Task <TestParticipants> updateTestParticipants(int participantId, int TestParticipantsId, int distance) { var tpants = new TestParticipants(); try { tpants = await _repo.updateTestParticipants(participantId, TestParticipantsId, distance); } catch (Exception ex) { throw ex; } return(tpants); }
/// <summary> /// Get A single record of Test Participants where id=TestParticipantsId /// </summary> /// <param name="TestParticipantsId"></param> /// <returns></returns> public async Task <TestParticipants> getTestParticipant(int TestParticipantsId) { var res = new TestParticipants(); try { res = await _repo.getTestParticipant(TestParticipantsId); } catch (Exception ex) { throw ex; } return(res); }
/// <summary> /// Get Athelete Participant of a certain test /// </summary> /// <param name="participantId"></param> /// <param name="TestParticipantsId"></param> /// <returns></returns> public async Task <TestParticipants> getTestParticipant(int TestParticipantsId) { var participants = new TestParticipants(); try { participants = (from x in _dbContext.TestParticipants where x.id == TestParticipantsId select x).FirstOrDefault(); } catch (Exception ex) { throw ex; } return(participants); }
public async Task <IActionResult> DeleteParticipant(int id) { var tpant = new TestParticipants(); try { tpant = await _service.getTestParticipant(id); var result = await _service.deleteTestParticipants(id); if (tpant.Test == null) { return(RedirectToAction("TestDetails", new { guid = string.Empty })); } return(RedirectToAction("TestDetails", new { guid = tpant.Test.guid })); } catch (Exception ex) { _logger.LogError(ex, "An Error has occured"); StatusCode(500, ex.Message); } return(View()); }