//================================================================================ public List <vmMusicianResult> GetMusiciansByFirstLastNames(vmMusicianSearch vmMS) { List <vmMusicianResult> vmMRs = new List <vmMusicianResult>(); List <AppUser> aus = _repo.Query <AppUser>().Where(b => b.LastName == vmMS.LastName && b.FirstName == vmMS.FirstName).ToList(); if (aus == null) { return(null); } else { foreach (AppUser au in aus) { UserMusician um = _repo.Query <UserMusician>().Where(c => c.AppUserId == au.AppUserId).FirstOrDefault(); if (um != null) { Musician m = _repo.Query <Musician>().Where(d => d.MusicianId == um.MusicianId).FirstOrDefault(); MusicianInstrument mi = _repo.Query <MusicianInstrument>().Where(e => e.MusicianId == m.MusicianId && e.IsPrimary == true).FirstOrDefault(); Instrument i = _repo.Query <Instrument>().Where(f => f.InstrumentId == mi.InstrumentId).FirstOrDefault(); vmMusicianResult vmMRtemp = new vmMusicianResult { AppUserId = au.AppUserId, FirstName = au.FirstName, LastName = au.LastName, City = au.City, PrimeInstrument = i.InstrumentName }; vmMRs.Add(vmMRtemp); } } return(vmMRs); } }
//================================================================================ public List <vmMusicianResult> GetMusicianCitiesByInstrument(vmMusicianSearch vmMS) { List <vmMusicianResult> vmMRs = new List <vmMusicianResult>(); Instrument i = _repo.Query <Instrument>().Where(n => n.InstrumentName == vmMS.PrimeInstrument).FirstOrDefault(); if (i == null) { return(null); } else { List <MusicianInstrument> mis = _repo.Query <MusicianInstrument>().Where(q => q.InstrumentId == i.InstrumentId && q.IsPrimary == true).ToList(); foreach (MusicianInstrument mitemp in mis) { Musician mus = _repo.Query <Musician>().Where(r => r.MusicianId == mitemp.MusicianId).FirstOrDefault(); UserMusician um = _repo.Query <UserMusician>().Where(s => s.MusicianId == mus.MusicianId).FirstOrDefault(); AppUser au = _repo.Query <AppUser>().Where(t => t.AppUserId == um.AppUserId).FirstOrDefault(); vmMusicianResult vmMRtemp = new vmMusicianResult { AppUserId = au.AppUserId, FirstName = au.FirstName, LastName = au.LastName, City = au.City, PrimeInstrument = i.InstrumentName }; vmMRs.Add(vmMRtemp); } return(vmMRs); } }
//================================================================================ public List <vmMusicianResult> GetMusiciansByCityInstrument(vmMusicianSearch vmMS) { List <vmMusicianResult> vmMRs = new List <vmMusicianResult>(); List <AppUser> aus = _repo.Query <AppUser>().Where(t => t.City == vmMS.City).ToList(); if (aus.Count == 0) { return(null); } else { foreach (AppUser au in aus) { UserMusician um = _repo.Query <UserMusician>().Where(s => s.AppUserId == au.AppUserId).FirstOrDefault(); if (um == null) { } else { Musician mus = _repo.Query <Musician>().Where(r => r.MusicianId == um.MusicianId).FirstOrDefault(); if (mus == null) { } else { MusicianInstrument mi = _repo.Query <MusicianInstrument>().Where(q => q.MusicianId == mus.MusicianId && q.IsPrimary == true).FirstOrDefault(); Instrument inst = _repo.Query <Instrument>().Where(n => n.InstrumentId == mi.InstrumentId).FirstOrDefault(); Instrument i = _repo.Query <Instrument>().Where(n => n.InstrumentName == vmMS.PrimeInstrument).FirstOrDefault(); if (i == null) { return(null); } else { if (inst.InstrumentId == i.InstrumentId) { vmMusicianResult vmMRtemp = new vmMusicianResult { AppUserId = au.AppUserId, FirstName = au.FirstName, LastName = au.LastName, City = au.City, PrimeInstrument = i.InstrumentName }; vmMRs.Add(vmMRtemp); } } } } } return(vmMRs); } }
//===================================================================== //Methods(). //===================================================================== public List <vmMusiciansGenresByInstrument> GetMusiciansGenresByInstrument(int Id) { AppUser AU = new AppUser(); Musician Mus = new Musician(); UserMusician UM = new UserMusician(); MusicianInstrument MI = new MusicianInstrument(); Instrument Inst = new Instrument(); MusicianGenre MG = new MusicianGenre(); Genre GG = new Genre(); List <MusicianGenre> MGs = new List <MusicianGenre>(); List <MusicianInstrument> MIs = new List <MusicianInstrument>(); List <vmMusiciansGenresByInstrument> vmMGIs = new List <vmMusiciansGenresByInstrument>(); if (Id != 0) { Inst = _repo.Query <Instrument>().Where(a => a.InstrumentId == Id).FirstOrDefault(); MIs = _repo.Query <MusicianInstrument>().Where(a => a.InstrumentId == Id).ToList(); foreach (MusicianInstrument mi in MIs) { Mus = _repo.Query <Musician>().Where(b => b.MusicianId == mi.MusicianId).FirstOrDefault(); UM = _repo.Query <UserMusician>().Where(c => c.MusicianId == Mus.MusicianId).FirstOrDefault(); AU = _repo.Query <AppUser>().Where(d => d.AppUserId == UM.AppUserId).FirstOrDefault(); MGs = _repo.Query <MusicianGenre>().Where(e => e.MusicianId == Mus.MusicianId).ToList(); List <vmGenre> vmGGs = new List <vmGenre>(); foreach (MusicianGenre MGTemp in MGs) { GG = _repo.Query <Genre>().Where(f => f.GenreId == MGTemp.GenreId).FirstOrDefault(); vmGenre vmGG = new vmGenre(); vmGG.GenreId = GG.GenreId; vmGG.GenreName = GG.GenreName; vmGGs.Add(vmGG); } ; vmMusiciansGenresByInstrument vmMGI = new vmMusiciansGenresByInstrument { InstrumentId = Id, InstrumentName = Inst.InstrumentName, AppUserId = AU.AppUserId, LastName = AU.LastName, FirstName = AU.FirstName, IsMusician = AU.IsMusician, MusicianId = Mus.MusicianId, StageName = Mus.StageName, vmGenres = vmGGs }; vmMGIs.Add(vmMGI); } } return(vmMGIs); }
//================================================================================ public List <vmMusicianResult> GetMusicianInstrumentsByCity(vmMusicianSearch vmMS) { List <vmMusicianResult> vmMRs = new List <vmMusicianResult>(); List <AppUser> aus = _repo.Query <AppUser>().Where(g => g.City == vmMS.City).ToList(); if (aus.Count == 0) { return(null); } else { foreach (AppUser au in aus) { UserMusician um = _repo.Query <UserMusician>().Where(h => h.AppUserId == au.AppUserId).FirstOrDefault(); if (um == null) { } else { Musician m = _repo.Query <Musician>().Where(j => j.MusicianId == um.MusicianId).FirstOrDefault(); MusicianInstrument mi = _repo.Query <MusicianInstrument>().Where(k => k.MusicianId == m.MusicianId && k.IsPrimary == true).FirstOrDefault(); Instrument i = _repo.Query <Instrument>().Where(mm => mm.InstrumentId == mi.InstrumentId).FirstOrDefault(); vmMusicianResult vmMRtemp = new vmMusicianResult { AppUserId = au.AppUserId, LastName = au.LastName, FirstName = au.FirstName, City = au.City, PrimeInstrument = i.InstrumentName }; vmMRs.Add(vmMRtemp); } } return(vmMRs); } }
public List <vmMusiciansInstrumentsByGenre> Get(int id) { if (id != 0) { Genre GG = new Genre(); List <MusicianGenre> MGs = new List <MusicianGenre>(); List <vmMusiciansInstrumentsByGenre> vmMIGs = new List <vmMusiciansInstrumentsByGenre>(); GG = repo.Query <Genre>().Where(a => a.GenreId == id).FirstOrDefault(); MGs = repo.Query <MusicianGenre>().Where(b => b.GenreId == id).ToList(); foreach (MusicianGenre MG in MGs) { List <Musician> MMs = new List <Musician>(); MMs = repo.Query <Musician>().Where(c => c.MusicianId == MG.MusicianId).ToList(); foreach (Musician MM in MMs) { UserMusician UM = new UserMusician(); UM = repo.Query <UserMusician>().Where(d => d.MusicianId == MM.MusicianId).FirstOrDefault(); AppUser AU = new AppUser(); AU = repo.Query <AppUser>().Where(e => e.AppUserId == UM.AppUserId).FirstOrDefault(); List <MusicianInstrument> MIs = new List <MusicianInstrument>(); MIs = repo.Query <MusicianInstrument>().Where(f => f.MusicianId == MM.MusicianId).ToList(); List <vmInstrument> vmInsts = new List <vmInstrument>(); foreach (MusicianInstrument MI in MIs) { Instrument Inst = new Instrument(); Inst = repo.Query <Instrument>().Where(g => g.InstrumentId == MI.InstrumentId).FirstOrDefault(); vmInstrument vmInst = new vmInstrument { InstrumentId = Inst.InstrumentId, InstrumentName = Inst.InstrumentName }; vmInsts.Add(vmInst); } ; vmMusiciansInstrumentsByGenre vmMIG = new vmMusiciansInstrumentsByGenre { GenreId = GG.GenreId, GenreName = GG.GenreName, AppUserId = AU.AppUserId, LastName = AU.LastName, FirstName = AU.FirstName, IsMusician = AU.IsMusician, MusicianId = MM.MusicianId, StageName = MM.StageName, IsMusicianForHire = MM.IsMusicianForHire, vmInstruments = vmInsts }; vmMIGs.Add(vmMIG); } ; } ; return(vmMIGs); } else { return(null); } }
//================================================================= //Methods(). //================================================================= public vmMusicianProfile GetUserById(int id) { //Use the variable, id, to find the Application User's row (AppUser) in the AppUser table ( collection // of AppUser's. var user = _repo.Query <AppUser>().Where(a => a.AppUserId == id).FirstOrDefault(); //Use the AppUseId found within that row to find the row containing that number in the //UserMusician join table. UserMusician um = new UserMusician(); if (user != null) { um = _repo.Query <UserMusician>().Where(b => b.AppUserId == user.AppUserId).FirstOrDefault(); } //Use the MusicianId from that row to find the musician in the Musician table. Musician mus = new Musician(); if (user != null) { mus = _repo.Query <Musician>().Where(c => c.MusicianId == um.MusicianId).FirstOrDefault(); } //============================================================================================= //Similarly, use the MusicianId from that row to find the list of MusicianInstruments from //the MusicianInstrument table. List <MusicianInstrument> ms = new List <MusicianInstrument>(); if (mus != null) { ms = _repo.Query <MusicianInstrument>().Where(d => d.MusicianId == mus.MusicianId).ToList(); } //Build the collection of instruments from the join table. //Using the InstrumentId found in each row of the resulting list build a list of instruments //that the musician plays. List <vmInstrumentMusProfile> tempIs = new List <vmInstrumentMusProfile>(); if (ms != null) { foreach (MusicianInstrument musI in ms) { Instrument inst = _repo.Query <Instrument>().Where(g => g.InstrumentId == musI.InstrumentId).FirstOrDefault(); vmInstrumentMusProfile vmInst = new vmInstrumentMusProfile { InstrumentId = inst.InstrumentId, InstrumentName = inst.InstrumentName, PrimaryInstrument = musI.IsPrimary }; tempIs.Add(vmInst); } ; //==================================================================================== //Similarly, use the MusicianId from that row to find the list of genres that the //musician plays from the MusicianGenre table. var mg = _repo.Query <MusicianGenre>().Where(h => h.MusicianId == mus.MusicianId).ToList(); List <vmGenre> tempGs = new List <vmGenre>(); foreach (MusicianGenre musG in mg) { Genre gen = _repo.Query <Genre>().Where(j => j.GenreId == musG.GenreId).FirstOrDefault(); vmGenre vmGen = new ViewModels.vmGenre { GenreId = gen.GenreId, GenreName = gen.GenreName, IsPrimary = musG.IsPrimary }; tempGs.Add(vmGen); } ; //==================================================================================== //Similarly, use the MusicianId from that row to find the list of languages that the //musician speaks from the MusicianLanguage table. var mL = _repo.Query <MusicianLanguage>().Where(k => k.MusicianId == mus.MusicianId).ToList(); List <vmSpokenLanguage> tempLs = new List <vmSpokenLanguage>(); foreach (MusicianLanguage musL in mL) { SpokenLanguage Lan = _repo.Query <SpokenLanguage>().Where(q => q.SpokenLanguageId == musL.SpokenLanguageId).FirstOrDefault(); vmSpokenLanguage vmLan = new ViewModels.vmSpokenLanguage { SpokenLanguageId = Lan.SpokenLanguageId, Language = Lan.Language }; tempLs.Add(vmLan); } ; //==================================================================================== //Similarly, use the MusicianId from that row to find the list of photographs of the //musician from the MusicianPhotograph table. var mP = _repo.Query <MusicianPhotograph>().Where(r => r.MusicianId == mus.MusicianId).ToList(); List <vmPhotograph> tempPs = new List <vmPhotograph>(); foreach (MusicianPhotograph musP in mP) { Photograph Ph = _repo.Query <Photograph>().Where(q => q.PhotographId == musP.PhotographId).FirstOrDefault(); vmPhotograph vmPh = new ViewModels.vmPhotograph { PhotographId = Ph.PhotographId, PhotographURL = Ph.PhotographURL }; tempPs.Add(vmPh); } ; //==================================================================================== var mp = new vmMusicianProfile { AppUserId = user.AppUserId, UserName = user.UserName, PassWord = user.PassWord, LastName = user.LastName, FirstName = user.FirstName, City = user.City, State = user.State, PostalCode = user.PostalCode, Email = user.Email, ReceiveAdvertisements = user.ReceiveAdvertisements, IsMusician = user.IsMusician, MusicianId = mus.MusicianId, StageName = mus.StageName, CellPhone = mus.CellPhone, Biography = mus.Biography, IsMusicianForHire = mus.IsMusicianForHire, Rate = mus.Rate, Rating = mus.Rating, InstrumentsMusProfile = tempIs, Genres = tempGs, Languages = tempLs, Photographs = tempPs }; return(mp); } else { return(null); } }
//==================================================================================== public vmMusicianProfile PostAddMusicianProfile(vmMusicianProfile vmMP) { AppUser AppUserToPost = new AppUser { AppUserId = vmMP.AppUserId, UserName = vmMP.UserName, PassWord = vmMP.PassWord, LastName = vmMP.LastName, FirstName = vmMP.FirstName, City = vmMP.City, State = vmMP.State, PostalCode = vmMP.PostalCode, Email = vmMP.PostalCode, ReceiveAdvertisements = vmMP.ReceiveAdvertisements, IsMusician = vmMP.IsMusician }; if (AppUserToPost.AppUserId == 0) { _repo.Add(AppUserToPost); } else { _repo.Update(AppUserToPost); } //======================================================================= AppUser tempAppUser = _repo.Query <AppUser>().Where(r => r.UserName == AppUserToPost.UserName && r.PassWord == AppUserToPost.PassWord && r.LastName == AppUserToPost.LastName && r.FirstName == AppUserToPost.FirstName && r.City == AppUserToPost.City && r.State == AppUserToPost.State ).FirstOrDefault(); //======================================================================= if (vmMP.AppUserId == 0) { vmMP.AppUserId = tempAppUser.AppUserId; } //======================================================================= Musician MusicianToPost = new Musician { MusicianId = vmMP.MusicianId, StageName = vmMP.StageName, CellPhone = vmMP.CellPhone, Biography = vmMP.Biography, Rate = vmMP.Rate, Rating = vmMP.Rating, IsMusicianForHire = vmMP.IsMusicianForHire }; //======================================================================= if (MusicianToPost.MusicianId == 0) { _repo.Add(MusicianToPost); } else { _repo.Update(MusicianToPost); } //================================================================================== Musician tempMusician = _repo.Query <Musician>().Where(s => s.StageName == MusicianToPost.StageName && s.CellPhone == MusicianToPost.CellPhone && s.Biography == MusicianToPost.Biography && s.Rate == MusicianToPost.Rate && s.Rating == MusicianToPost.Rating && s.IsMusicianForHire == MusicianToPost.IsMusicianForHire).FirstOrDefault(); //================================================================================================================ if (vmMP.MusicianId == 0) { vmMP.MusicianId = tempMusician.MusicianId; } //================================================================================= if (tempAppUser != null && tempMusician != null) { UserMusician umTest = _repo.Query <UserMusician>().Where(t => t.AppUserId == tempAppUser.AppUserId && t.MusicianId == tempMusician.MusicianId).FirstOrDefault(); if (umTest == null) { UserMusician newUm = new UserMusician { AppUser = tempAppUser, AppUserId = tempAppUser.AppUserId, Musician = tempMusician, MusicianId = tempMusician.MusicianId }; _repo.Add(newUm); } //============================================================================== if (vmMP.InstrumentsMusProfile != null) { foreach (vmInstrumentMusProfile i in vmMP.InstrumentsMusProfile) { Instrument newI = _repo.Query <Instrument>().Where(u => u.InstrumentId == i.InstrumentId).FirstOrDefault(); MusicianInstrument testMI = _repo.Query <MusicianInstrument>().Where(v => v.InstrumentId == newI.InstrumentId && v.MusicianId == tempMusician.MusicianId).FirstOrDefault(); if (testMI == null) { MusicianInstrument newMI = new MusicianInstrument { Instrument = newI, InstrumentId = newI.InstrumentId, Musician = tempMusician, MusicianId = tempMusician.MusicianId, IsPrimary = i.PrimaryInstrument }; _repo.Add(newMI); } else { testMI.IsPrimary = i.PrimaryInstrument; _repo.Update(testMI); } } } //============================================================================= if (vmMP.Genres != null) { foreach (vmGenre g in vmMP.Genres) { Genre newG = _repo.Query <Genre>().Where(w => w.GenreId == g.GenreId).FirstOrDefault(); MusicianGenre testMG = _repo.Query <MusicianGenre>().Where(x => x.GenreId == newG.GenreId && x.MusicianId == tempMusician.MusicianId).FirstOrDefault(); if (testMG == null) { MusicianGenre newMG = new MusicianGenre { Genre = newG, GenreId = newG.GenreId, Musician = tempMusician, MusicianId = tempMusician.MusicianId, IsPrimary = g.IsPrimary }; _repo.Add(newMG); } else { testMG.IsPrimary = g.IsPrimary; _repo.Update(testMG); } } } //============================================================================ if (vmMP.Languages != null) { foreach (vmSpokenLanguage s in vmMP.Languages) { SpokenLanguage newS = _repo.Query <SpokenLanguage>().Where(y => y.SpokenLanguageId == s.SpokenLanguageId).FirstOrDefault(); if (newS != null) { MusicianLanguage testML = _repo.Query <MusicianLanguage>().Where(z => z.SpokenLanguageId == newS.SpokenLanguageId && z.MusicianId == tempMusician.MusicianId).FirstOrDefault(); if (testML == null) { MusicianLanguage newML = new MusicianLanguage { SpokenLanguage = newS, SpokenLanguageId = newS.SpokenLanguageId, Musician = tempMusician, MusicianId = tempMusician.MusicianId, }; _repo.Add(newML); } } } } //============================================================================ if (vmMP.Photographs != null) { foreach (vmPhotograph p in vmMP.Photographs) { Photograph newP = _repo.Query <Photograph>().Where(w => w.PhotographId == p.PhotographId).FirstOrDefault(); MusicianPhotograph testMP = _repo.Query <MusicianPhotograph>().Where(z => z.PhotographId == newP.PhotographId && z.MusicianId == tempMusician.MusicianId).FirstOrDefault(); if (testMP == null) { MusicianPhotograph newMP = new MusicianPhotograph { Photograph = newP, PhotographId = newP.PhotographId, Musician = tempMusician, MusicianId = tempMusician.MusicianId }; _repo.Add(newMP); } } } //============================================================================ } ; return(vmMP); }