private async Task <bool> AddEntity(RaceViewModel model, ICollection <RaceOrganisation> raceOrganisations, IQueryable <Organisation> regions) { bool isSaveSuccess = true; List <RaceOrganisation> RaceOrganisationList = new List <RaceOrganisation>(); foreach (var record in model.OrganisationIds) { var currentRolePermission = regions.Any(a => a.Id == record); if (currentRolePermission) { RaceOrganisation raceOrganisation = new RaceOrganisation(); RaceOrganisationList.Add(raceOrganisation.ToEntity(record, model.Id, model.SessionUserId)); } } if (RaceOrganisationList.Count > 0) { await _context.RaceOrganisation.AddRangeAsync(RaceOrganisationList); await _context.SaveChangesAsync(); isSaveSuccess = true; } return(isSaveSuccess); }
private async Task <bool> AddRaceOrganisationWherePreviousExists(RaceViewModel model, ICollection <RaceOrganisation> RaceOrganisations, IQueryable <Organisation> regions) { bool isSaveSuccess = true; List <RaceOrganisation> assignedRaceOrganisations = new List <RaceOrganisation>(); foreach (var recordId in model.OrganisationIds) { var currentRolePermission = regions.Where(a => a.Id == recordId).FirstOrDefault(); if (currentRolePermission != null) { if (!RaceOrganisations.Any(a => a.OrganisationId == recordId)) { // var currentUserRoleID = currentMenuRoles.First(a => a.Organisation.RoleID == currentRolePermission.RoleID).RegionID; var RaceOrganisationRepo = new RaceOrganisation(); assignedRaceOrganisations.Add(RaceOrganisationRepo.ToEntity(recordId, model.Id, model.SessionUserId)); } } } if (assignedRaceOrganisations.Count > 0) { await _context.RaceOrganisation.AddRangeAsync(assignedRaceOrganisations); await _context.SaveChangesAsync(); isSaveSuccess = true; } return(isSaveSuccess); }