Exemplo n.º 1
0
        //================================================================================
        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);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Adds an instrument to a musician
 /// </summary>
 /// <param name="Musician"></param>
 /// <param name="Instrument"></param>
 public static void AddInstrumentToMusician(Musician Musician,
                                            Instrument Instrument)
 {
     using (var context = new BandBookerContext())
     {
         var m = (from x in context.Musician
                  where x.MusicianId == Musician.MusicianId
                  select x).FirstOrDefault();
         var currentMI = (from x in context.MusicianInstrument
                          where x.MusicianId == Musician.MusicianId &&
                          x.InstrumentId == Instrument.InstrumentId
                          select x).FirstOrDefault();
         if (currentMI == null)
         {
             var inst = (from x in context.Instrument
                         where x.InstrumentId == Instrument.InstrumentId
                         select x).FirstOrDefault();
             var mi = new MusicianInstrument()
             {
                 Musician   = m,
                 Instrument = inst
             };
             m.MusicianInstrument.Add(mi);
             context.SaveChanges();
         }
     }
 }
        public async void UnassignMusicianInstrument(int musicianId, int instrumentId)
        {
            MusicianInstrument musicianInstrument = await FindByMusicianIdAndInstrumentId(musicianId, instrumentId);

            if (musicianInstrument != null)
            {
                Remove(musicianInstrument);
            }
        }
Exemplo n.º 4
0
        //================================================================================
        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);
            }
        }
        public async Task AssignMusicianInstrument(int musicianId, int instrumentId)
        {
            MusicianInstrument musicianInstrument = await FindByMusicianIdAndInstrumentId(musicianId, instrumentId);

            if (musicianInstrument == null)
            {
                musicianInstrument = new MusicianInstrument {
                    MusicianId = musicianId, InstrumentId = instrumentId
                };
                await AddAsync(musicianInstrument);
            }
        }
Exemplo n.º 6
0
        //=====================================================================
        //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 void Add(MusicianInstrument newMusicianInstrument)
        //{
        //    _context.Add(newMusicianInstrument);
        //    _context.SaveChanges();
        //}

        //public void Delete(int id)
        //{
        //    _context.MusicianInstrument.Where(g => g.Id == id)
        //       .ToList().ForEach(g => _context.MusicianInstrument.Remove(g));
        //    _context.SaveChanges();
        //}

        public void Add(int musicianId, int instrumentId)
        {
            var musician   = _context.Musician.FirstOrDefault(g => g.Id == musicianId);
            var instrument = _context.Instrument.FirstOrDefault(g => g.Id == instrumentId);

            var newMusicianInstrument = new MusicianInstrument
            {
                Musician   = musician,
                Instrument = instrument
            };

            _context.Add(newMusicianInstrument);
            _context.SaveChanges();
        }
Exemplo n.º 8
0
        public async Task <MusicianInstrumentResponse> UnassignMusicianInstrumentAsync(int musicianId, int instrumentId)
        {
            try
            {
                MusicianInstrument musicianInstrument = await _musicianInstrumentRepository.FindByMusicianIdAndInstrumentId(musicianId, instrumentId);

                _musicianInstrumentRepository.Remove(musicianInstrument);
                await _unitOfWork.CompleteAsync();

                return(new MusicianInstrumentResponse(musicianInstrument));
            }
            catch (Exception ex)
            {
                return(new MusicianInstrumentResponse($"An error ocurred while unassigning Instrument to Musician: {ex.Message}"));
            }
        }
Exemplo n.º 9
0
        //================================================================================
        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 void Remove(MusicianInstrument musicianInstrument)
 {
     _context.MusicianInstruments.Remove(musicianInstrument);
 }
 public async Task AddAsync(MusicianInstrument musicianInstrument)
 {
     await _context.MusicianInstruments.AddAsync(musicianInstrument);
 }
 public void Update(MusicianInstrument newMusicianInstrument)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 13
0
        //====================================================================================
        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);
        }