private bool MusicianExists(RateContribution rateContribution) { MusicianRepository musicianRepository = new MusicianRepository(); var retorno = musicianRepository.Get(rateContribution.musician_id); return(retorno != null); }
private bool MusicianExists(RateMusicalProject rateMusicalProject) { MusicianRepository musicianRepository = new MusicianRepository(); var retorno = musicianRepository.Get(rateMusicalProject.musician_id); return(retorno != null); }
private bool VerifyIfMusicianExists(int owner_id) { MusicianRepository musicianRepository = new MusicianRepository(); var retorno = musicianRepository.Get(owner_id); return(retorno != null); }
/// <summary> /// Edits a musician; this is not the most efficient way to edit a record; just demonstrating the repository in action. /// </summary> static void EditMusician() { using (var db = new DB_Bands()) { var musicianRepo = new MusicianRepository(db); var bandRepo = new BandRepository(db); var random = new Random(); var bands = bandRepo.GetAll(); var musicians = musicianRepo.GetAll(); var mi = random.Next(0, musicians.Count); var bi = random.Next(0, bands.Count); var musicianId = musicians[mi].MusicianId; var bandId = bands[bi].BandId; var randomMusician = musicianRepo.GetById(musicianId); var randomBand = bandRepo.GetById(bandId); if (randomMusician.Band != null && randomMusician.Band.Name.Equals(randomBand.Name)) { Console.WriteLine("Selected " + randomMusician.Name + " and " + randomBand.Name + ". No Edit was made. Please try again."); Console.WriteLine(""); return; } randomMusician.Band = randomBand; musicianRepo.Save(); Console.WriteLine("Edited: " + randomMusician.Name + " - New band: " + randomMusician.Band.Name); } Console.WriteLine(""); }
private bool TargetIdExists(RateMusician rateMusician) { MusicianRepository musicianRepository = new MusicianRepository(); var retorno = musicianRepository.Get(rateMusician.musician_target_id); return(retorno != null); }
public UnitOfWork() { _context = new EF6DBContext("DefaultConnection"); _applicationUserManager = new ApplicationUserManager(new CustomUserStore(_context)); _applicationRoleManager = new ApplicationRoleManager(new CustomRoleStore(_context)); _clientRepository = new ClientRepository(_context); _musicianRepository = new MusicianRepository(_context); _musicInstrumentRepository = new MusicInstrumentRepository(_context); _orderRepository = new OrderRepository(_context); _commentRepository = new CommentRepository(_context); }
public IEnumerable <Musician> GetByMusicalProjectId(int musical_project_id) { ContributionBusiness contributionBusiness = new ContributionBusiness(); var contributions = contributionBusiness.GetByMusicalProjectId(musical_project_id); IEnumerable <int> musician_ids = contributions.Select(c => c.musician_id); MusicianRepository musicianRepository = new MusicianRepository(); IEnumerable <Musician> retorno = musicianRepository.GetMusicians(musician_ids); return(retorno); }
/// <summary> /// Add records for bands and musicians to database. /// </summary> static void SeedDatabase() { Console.WriteLine("Attempting to seed database..."); try { // check if data exists using (var db = new DB_Bands()) { var repo = new MusicianRepository(db); if (repo.GetAll().Count > 0) { Console.WriteLine("Data Exists! Retrieving data... "); Console.WriteLine(""); return; } } // Seeding database - make sure the App.config connection string is targeting a valid SQL Server instance. Console.WriteLine("Seeding database... "); using (var db = new DB_Bands()) { var musicians = BandDataLayer.GetMusicians(); var musicianRepo = new MusicianRepository(db); foreach (var musician in musicians) { musicianRepo.Add(musician); } musicianRepo.Save(); // let's check if all data was stored var seedBands = BandDataLayer.GetBands(); var bandRepo = new GenericRepository <Band>(db); var dbbands = bandRepo.GetAll().Select(y => y.Name).ToList(); foreach (var band in seedBands) { if (!dbbands.Contains(band.Name)) { bandRepo.Add(band); } } bandRepo.Save(); Console.WriteLine("Data Stored to Database!"); Console.WriteLine(""); } } catch (Exception ex) { Console.WriteLine("An error occured while trying to seed the database: " + ex.Message); } }
static void PrintMusicians() { Console.WriteLine("Mucisians Are..."); using (var db = new DB_Bands()) { var repo = new MusicianRepository(db); foreach (var musician in repo.GetAll()) { Console.WriteLine("Name: " + musician.Name); } } Console.WriteLine(""); }
/// <summary> /// Deleted a musician; this is not the most efficient way to edit a record; just demonstrating the repository in action. /// </summary> static void DeleteMusician() { using (var db = new DB_Bands()) { var repo = new MusicianRepository(db); var random = new Random(); var musicians = repo.GetAll(); var index = random.Next(0, musicians.Count); var musicianId = musicians[index].MusicianId; var randomMusician = repo.GetById(musicianId); repo.Delete(randomMusician); repo.Save(); Console.WriteLine("Deleted: " + randomMusician.Name); } Console.WriteLine(""); }
private MusicianRepository ReadMusicians(XElement xmlElement, XNamespace xmlNamespace) { MusicianRepository musicianRepository = new MusicianRepository(); IEnumerable <Musician> musicians = from musician in xmlElement.Descendants(xmlNamespace + MusicXmlConstants.MUSICIAN_NODE) select new Musician() { Id = musician.Attribute(MusicXmlConstants.MUSICIAN_ID).Value, Name = musician.Element(xmlNamespace + MusicXmlConstants.MUSICIAN_NAME).Value }; foreach (Musician musician in musicians) { musicianRepository.Add(musician); } return(musicianRepository); }
static void DeleteAllDatabaseRecords() { using (var db = new DB_Bands()) { var musicianRepo = new MusicianRepository(db); var bandRepo = new BandRepository(db); var musicians = musicianRepo.GetAll(); foreach (var musician in musicians) { musicianRepo.Delete(musician); } musicianRepo.Save(); var bands = bandRepo.GetAll(); foreach (var band in bands) { bandRepo.Delete(band); } bandRepo.Save(); } }
public MusicianBusiness() { musicianRepository = new MusicianRepository(); }