Пример #1
0
        public ActionResult Create([Bind(Include = "SongTitle,MusicianId,SingerId,AlbumId,MusicGenresId,PathMusic")] Song song, HttpPostedFileBase Music)
        {
            try
            {
                if (Music.ContentLength > 0)
                {
                    string filename = Path.GetFileName(Music.FileName);
                    string path     = Path.Combine(Server.MapPath("~/UploadMusic/"), filename);
                    Music.SaveAs(path);
                    song.PathMusic  = "~/UploadMusic/" + filename;
                    song.WhoUp      = "Admin";
                    song.Views      = 0;
                    song.DateUpload = DateTime.Today.Date;
                    db.Songs.Add(song);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception)
            {
                ViewBag.Error = "Loi upload File";
                return(View());
            }


            ViewBag.AlbumId       = new SelectList(db.Albums, "AlbumId", "AlbumTitle", song.AlbumId);
            ViewBag.MusicGenresId = new SelectList(db.MusicGenres, "MusicGenresId", "MusicGenresName", song.MusicGenresId);
            ViewBag.MusicianId    = new SelectList(db.Musicians, "MusicianId", "MusicianName", song.MusicianId);
            ViewBag.SingerId      = new SelectList(db.Singers, "SingerId", "SingerName", song.SingerId);
            return(View(song));
        }
Пример #2
0
        public IActionResult Post([FromBody] Lyric lyric)
        {
            if (lyric == null)
            {
                return(BadRequest(new BaseAPIResponse()
                {
                    IsSuccess = false,
                    Message = "Boş geçilemez"
                }));
            }
            dbContext.Lyrics.Add(lyric);

            try
            {
                dbContext.SaveChanges();
                return(Ok(new BaseAPIResponse()
                {
                    IsSuccess = true,
                    Message = "Başarıyla eklendi",
                    Result = lyric
                }));
            }
            catch (Exception)
            {
                return(BadRequest(new BaseAPIResponse()
                {
                    IsSuccess = false,
                    Message = "Bir hata oluştu"
                }));
            }
        }
Пример #3
0
        public ActionResult AddToCart(int id)
        {
            var messgae  = "";
            var cartItem = db.Carts.SingleOrDefault(c => c.AlbumId == id && c.UserName == User.Identity.Name);

            if (cartItem == null)
            {
                cartItem = new Cart()
                {
                    AlbumId  = id,
                    UserName = User.Identity.Name,
                    Quantity = 1,
                    Date     = DateTime.Now
                };
                db.Carts.Add(cartItem);
                db.SaveChanges();
                messgae = "添加" + db.Albums.Find(id).AlbumName + "成功";
            }
            else
            {
                cartItem.Quantity++;
                db.Entry(cartItem).State = EntityState.Modified;
                db.SaveChanges();
                messgae = db.Albums.Find(id).AlbumName + "数量成功加+1";
            }
            return(RedirectToAction("Index"));
        }
Пример #4
0
        public IActionResult DeleteMusician(int id)
        {
            if (_context.Musician.Any(c => c.IdMusician == id))
            {
                var ListOfSongsOnAlbums = (from o in _context.Musician
                                           join m_t in _context.Musician_Track on o.IdMusician equals m_t.IdMusician
                                           join t in _context.Tracks on m_t.IdTrack equals t.IdTrack
                                           where (o.IdMusician == id && t.IdMusicAlbum != 0)
                                           select t
                                           ).ToList();
                if (ListOfSongsOnAlbums.Count > 0)
                {
                    throw new Exception("Artist already has tracks appearing on albums!");
                }
                else
                {
                    var musician = _context.Musician.Where(m => m.IdMusician == id).FirstOrDefault();
                    var res      = new MusicianDeleteResponse()
                    {
                        IdMusician    = id,
                        FirstName     = musician.FirstName,
                        LastName      = musician.LastName,
                        NickName      = musician.Nickname,
                        DeletedTracks = new List <Track>()
                    };

                    var MusicianTrack = _context.Musician_Track.Where(e => e.IdMusician == musician.IdMusician).ToList();
                    foreach (var m_t in MusicianTrack)
                    {
                        _context.Musician_Track.Remove(m_t);
                    }
                    var ListOfSongsNotOnAlbums = (from o in _context.Musician
                                                  join m_t in _context.Musician_Track on o.IdMusician equals m_t.IdMusician
                                                  join t in _context.Tracks on m_t.IdTrack equals t.IdTrack
                                                  where (o.IdMusician == id && t.IdMusicAlbum == 0)
                                                  select t).ToList();

                    foreach (var track in ListOfSongsNotOnAlbums)
                    {
                        res.DeletedTracks.Add(track);
                        MusicianTrack = _context.Musician_Track.Where(e => e.IdTrack == track.IdTrack).ToList();
                        foreach (var m_t in MusicianTrack)
                        {
                            _context.Musician_Track.Remove(m_t);
                        }
                        _context.Tracks.Remove(track);
                        _context.SaveChanges();
                    }


                    _context.Musician.Remove(musician);
                    _context.SaveChanges();
                    return(Ok(res));
                }
            }
            else
            {
                throw new Exception("Artist doesn't exist!");
            }
        }
Пример #5
0
 public IActionResult Post([FromBody] Album album)
 {
     if (album == null)
     {
         return(BadRequest(new BaseAPIResponse()
         {
             Message = "Boş geçilemez",
             IsSuccess = false
         }));
     }
     dbContext.Albums.Add(album);
     try
     {
         dbContext.SaveChanges();
         return(Ok(new BaseAPIResponse()
         {
             IsSuccess = true,
             Result = album,
             Message = "Başarıyla eklendi"
         }));
     }
     catch
     {
         return(BadRequest(new BaseAPIResponse()
         {
             Message = "Bir hata oluştu",
             IsSuccess = false
         }));
     }
 }
Пример #6
0
        public ActionResult Delete(int id)
        {
            Album album = db.Albums.Find(id);

            db.Albums.Remove(album);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public IActionResult Create(Genre genre)
 {
     if (ModelState.IsValid)
     {
         _context.Genres.Add(genre);
         _context.SaveChanges();
         return(RedirectToAction("Details"));
     }
     return(View());
 }
 public IActionResult Create(Artist art)
 {
     if (ModelState.IsValid)
     {
         _context.Artists.Add(art);
         _context.SaveChanges();
         return(RedirectToAction("Details"));
     }
     return(View());
 }
Пример #9
0
 public IActionResult Create(Artist artist)
 {
     if (ModelState.IsValid)
     {
         db.Add(artist);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View());
 }
Пример #10
0
        public ActionResult Create([Bind(Include = "Id,Name,RealName,Gender,BirthCountry")] Artist artist)
        {
            if (ModelState.IsValid)
            {
                db.Artists.Add(artist);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(artist));
        }
Пример #11
0
        public ActionResult Create([Bind(Include = "Id,Name")] Playlist playlist)
        {
            if (ModelState.IsValid)
            {
                db.Playlists.Add(playlist);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(playlist));
        }
Пример #12
0
        public ActionResult Create([Bind(Include = "Id,Name")] Genre genre)
        {
            if (ModelState.IsValid)
            {
                db.Genres.Add(genre);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(genre));
        }
Пример #13
0
        public IActionResult CreateArtist([Bind("ArtistID, Name, Bio")] Artist artists)
        {
            if (ModelState.IsValid && !_db.Artists.Any(a => a.Name == artists.Name))
            {
                _db.Add(artists);
                _db.SaveChanges();
                return(RedirectToAction("IndexArtist"));
            }

            return(View(artists));
        }
Пример #14
0
        public ActionResult Create([Bind(Include = "Id,Name,Artist,GenreId")] Song song)
        {
            if (ModelState.IsValid)
            {
                db.Songs.Add(song);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(song));
        }
Пример #15
0
        public ActionResult Create([Bind(Include = "UserId,Fullname,Username,Password,Email,Avatar,IsAdmin")] Account account)
        {
            if (ModelState.IsValid)
            {
                db.Accounts.Add(account);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(account));
        }
Пример #16
0
        private void SeedGenres()
        {
            SeedGenreIfNotExists(_dbContext, MusicTestsDataObjectsValues.GenreA);
            SeedGenreIfNotExists(_dbContext, MusicTestsDataObjectsValues.GenreB);
            SeedGenreIfNotExists(_dbContext, MusicTestsDataObjectsValues.GenreC);


            _dbContext.SaveChanges();

            _objects.LoadGenres();
        }
Пример #17
0
        public ActionResult Create([Bind(Include = "Id,FullName,Email,Phone,StartSuscription")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Пример #18
0
        public ActionResult Create([Bind(Include = "Id,Name")] Genre genre)
        {
            if (ModelState.IsValid)
            {
                genre.Songs = new List<Song>();
                db.Genres.Add(genre);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(genre);
        }
Пример #19
0
 public IActionResult Create(Album album)
 {
     if (ModelState.IsValid)
     {
         _context.Albums.Add(album);
         _context.SaveChanges();
         return(RedirectToAction("Details"));
     }
     ViewBag.ArtistList = new SelectList(_context.Artists, "ArtistID", "Name");
     ViewBag.GenreList  = new SelectList(_context.Genres, "GenreID", "Name");
     return(View());
 }
Пример #20
0
 public IActionResult Create(Album album)
 {
     if (ModelState.IsValid)
     {
         db.Add(album);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Artists = new SelectList(db.Artists.ToList(), "ArtistID", "Name");
     ViewBag.Genres  = new SelectList(db.Genres.ToList(), "GenreID", "Name");
     return(View());
 }
Пример #21
0
        public void Update(Album album)
        {
            var dbAlbum = context.Albums
                          .Where(a => a.Id == album.Id)
                          .Include(a => a.Songs)
                          .SingleOrDefault();

            if (dbAlbum != null)
            {
                // Update parent
                context.Entry(dbAlbum).CurrentValues.SetValues(album);

                // Delete children
                foreach (var song in dbAlbum.Songs.ToList())
                {
                    if (!album.Songs.Any(s => s.Id == song.Id))
                    {
                        var dbSong = dbAlbum.Songs
                                     .Where(s => s.Id == song.Id)
                                     .SingleOrDefault();

                        dbSong.AlbumId = null;
                    }
                }

                // Update and Insert children
                foreach (var song in album.Songs)
                {
                    var dbSong = dbAlbum.Songs
                                 .Where(c => c.Id == song.Id)
                                 .SingleOrDefault();

                    if (dbSong != null)
                    {
                        // Update child
                        context.Entry(dbSong).CurrentValues.SetValues(song);
                    }
                    else
                    {
                        // Insert child
                        var newSong = new Song
                        {
                            Name     = song.Name,
                            ArtistId = song.ArtistId,
                            AlbumId  = song.AlbumId
                        };
                        dbAlbum.Songs.Add(song);
                    }
                }

                context.SaveChanges();
            }
        }
Пример #22
0
        public ActionResult Create(Song song)
        {
            ViewBag.Genres = db.Genres.ToList();
            if (ModelState.IsValid)
            {
                db.Songs.Add(song);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(song));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Release")] Album album)
        {
            if (ModelState.IsValid)
            {
                db.Albums.Add(album);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.TrackList = new MultiSelectList(db.PlayListTracks, "TrackId", "Track.Name");
            return(View(album));
        }
Пример #24
0
        public ActionResult Create([Bind(Include = "Id,Title,Duration,Genero,UserId")] Song song)
        {
            if (ModelState.IsValid)
            {
                db.Songs.Add(song);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserId = new SelectList(db.Users, "Id", "FullName", song.UserId);
            return(View(song));
        }
        protected void Wishlist_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            //change to owned
            if (e.CommandName == "Owned")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                gvWishlist.SelectRow(index);

                string title  = gvWishlist.SelectedRow.Cells[2].Text;
                string artist = gvWishlist.SelectedRow.Cells[3].Text;
                string format = gvWishlist.SelectedRow.Cells[4].Text;

                var currentRecord = db.PhysicalMusics.First(b => b.musicTitle == title && b.musicArtist == artist && b.musicFormat == format && b.musicWant == true);

                while (currentRecord != null)
                {
                    currentRecord.musicOwned = true;
                    currentRecord.musicWant  = false;
                    db.SaveChanges();

                    gvWishlist.DataBind();

                    try
                    {
                        currentRecord = db.PhysicalMusics.First(b => b.musicTitle == title && b.musicArtist == artist && b.musicFormat == format && b.musicWant == true);
                    }
                    catch (InvalidOperationException ex)
                    {
                        currentRecord = null;
                    }
                }
            }
            //Delete from db and update gridview
            else if (e.CommandName == "Delete!")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                gvWishlist.SelectRow(index);

                string title  = gvWishlist.SelectedRow.Cells[2].Text;
                string artist = gvWishlist.SelectedRow.Cells[3].Text;
                string format = gvWishlist.SelectedRow.Cells[4].Text;

                var currentRecord = db.PhysicalMusics.Where(b => b.musicTitle == title && b.musicArtist == artist && b.musicFormat == format && b.musicWant == true);

                if (currentRecord != null)
                {
                    db.PhysicalMusics.RemoveRange(currentRecord);
                    db.SaveChanges();

                    gvWishlist.DataBind();
                }
            }
        }
Пример #26
0
        private void SeedGenres()
        {
            SeedGenreIfNotExists(_dbContext, MusicDataObjectsValues.GenreLatin);
            SeedGenreIfNotExists(_dbContext, MusicDataObjectsValues.GenreSchlager);
            SeedGenreIfNotExists(_dbContext, MusicDataObjectsValues.GenreJazz);
            SeedGenreIfNotExists(_dbContext, MusicDataObjectsValues.GenreRenB);
            SeedGenreIfNotExists(_dbContext, MusicDataObjectsValues.GenreRock);
            SeedGenreIfNotExists(_dbContext, MusicDataObjectsValues.GenrePop);
            SeedGenreIfNotExists(_dbContext, MusicDataObjectsValues.GenreElectricMusic);
            SeedGenreIfNotExists(_dbContext, MusicDataObjectsValues.GenreFolk);
            SeedGenreIfNotExists(_dbContext, MusicDataObjectsValues.GenreDutch);

            _dbContext.SaveChanges();
        }
Пример #27
0
 public IActionResult Create([Bind("ArtistID, Name, Bio")] Artist artist)
 {
     if (_context.Artists.SingleOrDefault(m => (m.Name == artist.Name && m.ArtistID != artist.ArtistID)) != null)
     {
         ViewData["Error"] = "Artist Name must be unique.";
     }
     else if (ModelState.IsValid)
     {
         _context.Add(artist);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewData["Name"] = artist.Name;
     return(View(artist));
 }
Пример #28
0
        public void RateSong(string SongId, string RatingValue, string user)
        {
            var users = context.Users.Where(p => p.Email == user).FirstOrDefault();

            context.Users_Songs.Add(new Users_Songs {
                SongId = Convert.ToInt32(SongId), UserId = users.UserId
            });
            context.SaveChanges();
            var    songsData     = context.Songs.FirstOrDefault(q => q.SongId == Convert.ToInt32(SongId));
            double updatedRating = ((songsData.Rating * songsData.NumberOfRatings) + Convert.ToInt32(RatingValue)) / (songsData.NumberOfRatings + 1);

            songsData.Rating          = updatedRating;
            songsData.NumberOfRatings = songsData.NumberOfRatings + 1;
            context.SaveChanges();
        }
Пример #29
0
 public IActionResult Create([Bind("GenreID,Name")] Genre genre)
 {
     if (_context.Genres.SingleOrDefault(m => (m.Name == genre.Name && m.GenreID != genre.GenreID)) != null)
     {
         ViewData["Error"] = "Genre Name must be unique.";
     }
     else if (ModelState.IsValid)
     {
         _context.Add(genre);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewData["Name"] = genre.Name;
     return(View(genre));
 }
Пример #30
0
        public ActionResult GenreCreate(ManagViewModel Manag)
        {
            Genre genre = MapTo(Manag);

            if (Manag != null)
            {
                db.Genres.Add(genre);
                db.SaveChanges();
                return(RedirectToAction("GenreIndex"));
            }
            return(View());
        }
Пример #31
0
        public static void Main()
        {
            Database.SetInitializer(
                new MigrateDatabaseToLatestVersion<MusicDbContext, Configuration>());

            var db = new MusicDbContext();
            var artist = new Artist()
            {
                Name = "Someone",
                Country = "UK",
                DateOfBirth = new DateTime(1977, 05, 06)
            };

            db.Artists.Add(artist);

            db.SaveChanges();
        }