Ejemplo n.º 1
0
        // GET: Listeners
        public async Task <IActionResult> Index(int?id
                                                , string bandID)
        {
            var viewModel = new RatingIndexData();

            viewModel.Listeners = await _context.Listeners
                                  .Include(i => i.BandsListeners)
                                  .ThenInclude(i => i.Band)
                                  .OrderBy(i => i.Name)
                                  .ToListAsync();

            if (id != null)
            {
                ViewData["ListenerID"] = id.Value;
                Listener listener = viewModel.Listeners.Where(
                    i => i.ListenerID == id.Value).Single();
                viewModel.BandsListeners = listener.BandsListeners;
            }

            if (bandID != "" && bandID != null)
            {
                ViewData["BandID"] = bandID;

                var selectedBand = viewModel.BandsListeners.Where(b => b.BandID == bandID).Single().Band;
                await _context.Entry(selectedBand).Collection(b => b.Tours).LoadAsync();

                foreach (Tour t in selectedBand.Tours)
                {
                    await _context.Entry(t).Reference(i => i.Band).LoadAsync();
                }
                viewModel.Tours = selectedBand.Tours;
            }
            return(View(viewModel));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(Member member, HttpPostedFileBase uploadImage)
        {
            if (ModelState.IsValid && uploadImage != null)
            {
                byte[] imageData = null;
                // считываем переданный файл в массив байтов
                using (var binaryReader = new BinaryReader(uploadImage.InputStream))
                {
                    imageData = binaryReader.ReadBytes(uploadImage.ContentLength);
                }
                // установка массива байтов
                member.MemberImg = imageData;

                db.Entry(member).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            else if (ModelState.IsValid)
            {
                db.Entry(member).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.BandId       = new SelectList(db.Bands, "BandId", "Name", member.BandId);
            ViewBag.MemberTypeId = new SelectList(db.MemberTypes, "MemberTypeId", "Type", member.MemberTypeId);
            return(View(member));
        }
Ejemplo n.º 3
0
        public ActionResult Edit(Band band, HttpPostedFileBase uploadImage)
        {
            if (ModelState.IsValid && uploadImage != null)
            {
                byte[] imageData = null;
                // считываем переданный файл в массив байтов
                using (var binaryReader = new BinaryReader(uploadImage.InputStream))
                {
                    imageData = binaryReader.ReadBytes(uploadImage.ContentLength);
                }
                // установка массива байтов
                band.BandImg = imageData;

                db.Entry(band).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            else if (ModelState.IsValid)
            {
                //Band thisProduct = db.Bands.Where(p => p.BandId == band.BandId).FirstOrDefault();
                //band.BandImg = thisProduct.BandImg;

                db.Entry(band).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(band));
        }
Ejemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "AlbumID,Title,GenreID,Price,ArtistID")] Album album)
 {
     if (ModelState.IsValid)
     {
         db.Entry(album).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ArtistID = new SelectList(db.Artists, "ArtistID", "Name", album.ArtistID);
     ViewBag.GenreID  = new SelectList(db.Genres, "GenreID", "Name", album.GenreID);
     return(View(album));
 }
Ejemplo n.º 5
0
        public async Task <IActionResult> PutArtist(int id, Artist artist)
        {
            if (id != artist.ArtistId)
            {
                return(BadRequest());
            }

            _context.Entry(artist).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArtistExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> PutMusic(long id, Music music)
        {
            if (id != music.Id)
            {
                return(BadRequest());
            }

            _context.Entry(music).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MusicExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 7
0
        public ActionResult Edit(int?id, string[] selectedGenres)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            //make sure album inlcudes necesary info (genres)
            Album album = db.Albums
                          .Include(a => a.Genres)
                          .Where(i => i.AlbumID == id)
                          .Single();

            if (TryUpdateModel(album, "", new string[] { "AlbumID", "ArtistID", "AlbumName", "YearRelease" }))
            {
                try
                {
                    UpdateAlbumGenres(selectedGenres, album);
                    db.Entry(album).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (RetryLimitExceededException /* dex */)
                {
                    //Log the error (uncomment dex variable name and add a line here to write a log.)
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                }
            }

            ViewBag.ArtistID = new SelectList(db.Artists, "ArtistID", "ArtistName", album.ArtistID);
            PopulateAssignedGenreData(album);
            return(View(album));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> PutSongStyles(int id, SongStyles songStyles)
        {
            if (id != songStyles.Id)
            {
                return(BadRequest());
            }

            _context.Entry(songStyles).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SongStylesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Update([FromRoute] long id, [FromBody] Artist artist)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != artist.Id)
            {
                return(BadRequest());
            }

            var entry = _context.Entry(artist);

            entry.State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArtistExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> PutAlbum([FromRoute] int id, [FromBody] Album album)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != album.AlbumId)
            {
                return(BadRequest());
            }

            _context.Entry(album).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                //if (!AlbumExists(id))
                //{
                //    return NotFound();
                //}
                //else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> PutTag([FromRoute] int id, [FromBody] Tag tag)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tag.TagId)
            {
                return(BadRequest());
            }

            _context.Entry(tag).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TagExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 12
0
        public ActionResult Edit(AlbumEditViewModel albumViewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var album = new Album()
                    {
                        AlbumArtUrl = albumViewModel.AlbumArtUrl,
                        AlbumId     = albumViewModel.AlbumId,
                        ArtistId    = albumViewModel.ArtistId,
                        GenreId     = albumViewModel.GenreId,
                        //Note lack of price in view model
                        Price = 9.99m,
                        Title = albumViewModel.Title
                    };

                    _db.Entry(album).State = EntityState.Modified;
                    _db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (DbEntityValidationException ex)
                {
                    foreach (var result in ex.EntityValidationErrors)
                    {
                        foreach (var error in result.ValidationErrors)
                        {
                            ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
                        }
                    }
                }
            }
            return(View(albumViewModel));
        }
Ejemplo n.º 13
0
 public ActionResult Edit(AlbumViewModel model, HttpPostedFileBase image)
 {
     if (ModelState.IsValid)
     {
         bool newAlbum = false;
         if (db.Albums.Find(model.Id) == null)
         {
             newAlbum = true;
         }
         Album album = ApplyItemChanges(model);
         if (image != null)
         {
             AddImageToAlbum(album, image);
         }
         if (newAlbum)
         {
             db.Albums.Add(album);
         }
         else
         {
             db.Entry(album).State = EntityState.Modified;
         }
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
Ejemplo n.º 14
0
 public void UpdatePublisher(Publisher publisher)
 {
     using (var context = new MusicContext())
     {
         context.Entry(publisher).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Ejemplo n.º 15
0
 public void UpdateArtist(Artist artist)
 {
     using (var context = new MusicContext())
     {
         context.Entry(artist).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
 public void UpdateTrackAlbum(TrackAlbum trackAlbum)
 {
     using (var context = new MusicContext())
     {
         context.Entry(trackAlbum).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
 public void UpdateGenre(Genre genre)
 {
     using (var context = new MusicContext())
     {
         context.Entry(genre).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
 public void DeletGenreById(int?id)
 {
     using (var context = new MusicContext())
     {
         var genre = context.Genres.Find(id);
         context.Entry(genre).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Ejemplo n.º 19
0
 public void DeletArtistById(int?id)
 {
     using (var context = new MusicContext())
     {
         var artist = context.Artists.Find(id);
         context.Entry(artist).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
 public void UpdateAlbum(Album album)
 {
     using (var context = new MusicContext())
     {
         var a = context.Entry(album);
         a.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
 public void DeletTrackAlbumById(int?id)
 {
     using (var context = new MusicContext())
     {
         var trackAlbum = context.TrackAlbums.Find(id);
         context.Entry(trackAlbum).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Ejemplo n.º 22
0
 public void DeletPublisherById(int?id)
 {
     using (var context = new MusicContext())
     {
         var publisher = context.Publishers.Find(id);
         context.Entry(publisher).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Ejemplo n.º 23
0
 public ActionResult Edit([Bind(Include = "ID,Title,Composer")] Piece piece)
 {
     if (ModelState.IsValid)
     {
         db.Entry(piece).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(piece));
 }
 public ActionResult Edit([Bind(Include = "MusicID,MusicName,MusicPath")] Music music)
 {
     if (ModelState.IsValid)
     {
         db.Entry(music).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", "home"));
     }
     return(View(music));
 }
Ejemplo n.º 25
0
 public ActionResult Edit([Bind(Include = "MusicID,BandName,Price,AlbumName,TrackName,ArtistName,Description,ImageURL,Rating")] Music music)
 {
     if (ModelState.IsValid)
     {
         db.Entry(music).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(music));
 }
Ejemplo n.º 26
0
 public ActionResult Edit([Bind(Include = "GenreId,Name,Description")] Genre genre)
 {
     if (ModelState.IsValid)
     {
         db.Entry(genre).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(genre));
 }
 public ActionResult Edit([Bind(Include = "AlbumID,Title,Price")] Album album)
 {
     if (ModelState.IsValid)
     {
         db.Entry(album).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(album));
 }
Ejemplo n.º 28
0
 public ActionResult Edit([Bind(Include = "ID,Name")] Feature feature)
 {
     if (ModelState.IsValid)
     {
         db.Entry(feature).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(feature));
 }
Ejemplo n.º 29
0
 public ActionResult Edit([Bind(Include = "SongID,Title,Composer,Key")] Song song)
 {
     if (ModelState.IsValid)
     {
         db.Entry(song).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(song));
 }
Ejemplo n.º 30
0
 public ActionResult Edit([Bind(Include = "Id,Title")] Artist artist)
 {
     if (ModelState.IsValid)
     {
         db.Entry(artist).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(artist));
 }