public async Task <IActionResult> Edit(int id, [Bind("Id,MusicianId,BandId,InfluenceScore")] MusicianBandInfluenceScore musicianBandInfluenceScore)
        {
            if (id != musicianBandInfluenceScore.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(musicianBandInfluenceScore);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MusicianBandInfluenceScoreExists(musicianBandInfluenceScore.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BandId"]     = new SelectList(_context.Band, "Id", "Id", musicianBandInfluenceScore.BandId);
            ViewData["MusicianId"] = new SelectList(_context.Musician, "Id", "Id", musicianBandInfluenceScore.MusicianId);
            return(View(musicianBandInfluenceScore));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("Id,BandName,MemberLookingFor,LookingToBeHired,Influence1,Influence2,Influence3")] Band band)
        {
            if (ModelState.IsValid)
            {
                var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
                band.ApplicationUserId = userId;
                _context.Band.Add(band);
                await _context.SaveChangesAsync();

                List <Musician> listOfMusicians = _context.Musician.ToList();
                foreach (var musician in listOfMusicians)
                {
                    MusicianBandInfluenceScore musicianBandInfluenceScore = new MusicianBandInfluenceScore();
                    var influenceScore = 0;
                    if (musician.Influence1 == band.Influence1)
                    {
                        influenceScore += 15;
                    }
                    if (musician.Influence1 == band.Influence2)
                    {
                        influenceScore += 10;
                    }
                    if (musician.Influence1 == band.Influence3)
                    {
                        influenceScore += 7;
                    }
                    if (musician.Influence2 == band.Influence1)
                    {
                        influenceScore += 10;
                    }
                    if (musician.Influence2 == band.Influence2)
                    {
                        influenceScore += 7;
                    }
                    if (musician.Influence2 == band.Influence3)
                    {
                        influenceScore += 5;
                    }
                    if (musician.Influence3 == band.Influence1)
                    {
                        influenceScore += 7;
                    }
                    if (musician.Influence3 == band.Influence2)
                    {
                        influenceScore += 5;
                    }
                    if (musician.Influence3 == band.Influence3)
                    {
                        influenceScore += 3;
                    }
                    musicianBandInfluenceScore.BandId         = band.Id;
                    musicianBandInfluenceScore.MusicianId     = musician.Id;
                    musicianBandInfluenceScore.InfluenceScore = influenceScore;
                    _context.MusicianBandInfluenceScore.Add(musicianBandInfluenceScore);
                    await _context.SaveChangesAsync();
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(band));
        }
        public async Task <IActionResult> Create([Bind("Id,MusicianId,BandId,InfluenceScore")] MusicianBandInfluenceScore musicianBandInfluenceScore)
        {
            if (ModelState.IsValid)
            {
                _context.Add(musicianBandInfluenceScore);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BandId"]     = new SelectList(_context.Band, "Id", "Id", musicianBandInfluenceScore.BandId);
            ViewData["MusicianId"] = new SelectList(_context.Musician, "Id", "Id", musicianBandInfluenceScore.MusicianId);
            return(View(musicianBandInfluenceScore));
        }
示例#4
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Instrument,LookingForBand,WantToCollaborate,Influence1,Influence2,Influence3")] Musician musician)
        {
            if (ModelState.IsValid)
            {
                var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
                musician.ApplicationUserId = userId;
                _context.Add(musician);
                await _context.SaveChangesAsync();

                List <Band> listOfBands = _context.Band.ToList();
                foreach (var band in listOfBands)
                {
                    MusicianBandInfluenceScore musicianBandInfluenceScore = new MusicianBandInfluenceScore();
                    var influenceScore = 0;
                    if (musician.Influence1 == band.Influence1)
                    {
                        influenceScore += 15;
                    }
                    if (musician.Influence1 == band.Influence2)
                    {
                        influenceScore += 10;
                    }
                    if (musician.Influence1 == band.Influence3)
                    {
                        influenceScore += 7;
                    }
                    if (musician.Influence2 == band.Influence1)
                    {
                        influenceScore += 10;
                    }
                    if (musician.Influence2 == band.Influence2)
                    {
                        influenceScore += 7;
                    }
                    if (musician.Influence2 == band.Influence3)
                    {
                        influenceScore += 5;
                    }
                    if (musician.Influence3 == band.Influence1)
                    {
                        influenceScore += 7;
                    }
                    if (musician.Influence3 == band.Influence2)
                    {
                        influenceScore += 5;
                    }
                    if (musician.Influence3 == band.Influence3)
                    {
                        influenceScore += 3;
                    }
                    musicianBandInfluenceScore.BandId         = band.Id;
                    musicianBandInfluenceScore.MusicianId     = musician.Id;
                    musicianBandInfluenceScore.InfluenceScore = influenceScore;
                    _context.MusicianBandInfluenceScore.Add(musicianBandInfluenceScore);
                    await _context.SaveChangesAsync();
                }

                var listOfMusicians = _context.Musician.ToList();
                foreach (var musicianToCheck in listOfMusicians)
                {
                    if (musician.Id != musicianToCheck.Id)
                    {
                        MusicianMusicianInfluenceScore musicianMusicianInfluenceScore = new MusicianMusicianInfluenceScore();
                        var influenceScore = 0;
                        if (musicianToCheck.Influence1 == musician.Influence1)
                        {
                            influenceScore += 15;
                        }
                        if (musicianToCheck.Influence1 == musician.Influence2)
                        {
                            influenceScore += 10;
                        }
                        if (musicianToCheck.Influence1 == musician.Influence3)
                        {
                            influenceScore += 7;
                        }
                        if (musicianToCheck.Influence2 == musician.Influence1)
                        {
                            influenceScore += 10;
                        }
                        if (musicianToCheck.Influence2 == musician.Influence2)
                        {
                            influenceScore += 7;
                        }
                        if (musicianToCheck.Influence2 == musician.Influence3)
                        {
                            influenceScore += 5;
                        }
                        if (musicianToCheck.Influence3 == musician.Influence1)
                        {
                            influenceScore += 7;
                        }
                        if (musicianToCheck.Influence3 == musician.Influence2)
                        {
                            influenceScore += 5;
                        }
                        if (musicianToCheck.Influence3 == musician.Influence3)
                        {
                            influenceScore += 3;
                        }
                        musicianMusicianInfluenceScore.MusicianId        = musician.Id;
                        musicianMusicianInfluenceScore.MusicianToCheckId = musicianToCheck.Id;
                        musicianMusicianInfluenceScore.InfluenceScore    = influenceScore;
                        _context.MusicianMusicianInfluenceScore.Add(musicianMusicianInfluenceScore);
                        await _context.SaveChangesAsync();
                    }
                    continue;
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(musician));
        }