private async Task <bool> AddEntity(TimeTrialResultViewModel model, ICollection <TimeTrialResult> containerEntityList, IQueryable <Member> referralEntityList) { bool isSaveSuccess = true; List <TimeTrialResult> TimeTrialResultList = new List <TimeTrialResult>(); foreach (var record in model.MemberIds) { var currentReferralEntity = referralEntityList.Any(a => a.Id == record); if (currentReferralEntity) { int ageGroupId = await CalculateAge(referralEntityList.FirstOrDefault(), model.TimeTrialDistanceId); TimeTrialResult TimeTrialResult = new TimeTrialResult(); TimeTrialResultList.Add(TimeTrialResult.ToEntity(record, model.TimeTrialDistanceId, model.TimeTaken, model.Position, ageGroupId, model.SessionUserId)); } } if (TimeTrialResultList.Count > 0) { await _context.TimeTrialResult.AddRangeAsync(TimeTrialResultList); await _context.SaveChangesAsync(); isSaveSuccess = true; } return(isSaveSuccess); }
private async Task <bool> AddTimeTrialResultWherePreviousExists(TimeTrialResultViewModel model, ICollection <TimeTrialResult> TimeTrialResults, IQueryable <Member> members) { bool isSaveSuccess = true; List <TimeTrialResult> assignedTimeTrialResults = new List <TimeTrialResult>(); foreach (var recordId in model.MemberIds) { var currentMember = members.Where(a => a.Id == recordId).FirstOrDefault(); if (currentMember != null) { if (!TimeTrialResults.Any(a => a.MemberId == recordId)) { int ageGroupId = await CalculateAge(currentMember, model.TimeTrialDistanceId); var TimeTrialResultRepo = new TimeTrialResult(); assignedTimeTrialResults.Add(TimeTrialResultRepo.ToEntity(recordId, model.TimeTrialDistanceId, model.TimeTaken, model.Position, ageGroupId, model.SessionUserId)); } } } if (assignedTimeTrialResults.Count > 0) { await _context.TimeTrialResult.AddRangeAsync(assignedTimeTrialResults); await _context.SaveChangesAsync(); isSaveSuccess = true; } return(isSaveSuccess); }