/// <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); }
public async Task <TEntity> Create(TEntity entity) { await _dbContext.Set <TEntity>().AddAsync(entity); await _dbContext.SaveChangesAsync(); return(entity); }