Esempio n. 1
0
        public ActionResult CreateAlbum(string artist)
        {
            Artist art = (from s in db.Artists
                          where s.Name == artist
                          select s).FirstOrDefault();

            var model = new AlbumViewModel
            {
                Artists = db.Artists.ToList().Select(x => new SelectListItem
                {
                    Text = x.Name,
                    Value = x.Id.ToString()
                })
            };

            if (art != null)
            {
                model.SelectedArtistId = art.Id;
            }

            return View(model);
        }
Esempio n. 2
0
        public ActionResult CreateAlbum(AlbumViewModel collection, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                Artist artist = db.Artists.Find(collection.SelectedArtistId);
                if (file != null && file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    string path1 = Server.MapPath("/Content/images/covers/");

                    if (!Directory.Exists(path1 + artist.Name))
                        Directory.CreateDirectory(path1 + artist.Name);

                    if (!Directory.Exists(path1 + artist.Name + "/" + collection.Album.Name))
                        Directory.CreateDirectory(path1 + artist.Name + "/" + collection.Album.Name);

                    var path = Server.MapPath("/Content/images/covers/" + artist.Name + "/" + collection.Album.Name + "/" + fileName);
                    file.SaveAs(path);

                    collection.Album.Cover = "/Content/images/covers/" + artist.Name + "/" + collection.Album.Name + "/" + fileName;
                }
                else
                    collection.Album.Cover = "/Content/images/covers/unknown_album.png";

                collection.Album.Position = -1;
                collection.Album.Songs = new List<Song>();

                if (string.IsNullOrEmpty(collection.Album.Cover))
                    collection.Album.Cover = "/Content/images/covers/unknown_album.png";

                collection.Album.ArtistName = artist.Name;

                artist.Albums.Add(collection.Album);
                db.Entry(artist).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Artist", new { artist = artist.Name });
            }

            collection.Artists = db.Artists.ToList().Select(x => new SelectListItem
                                {
                                    Text = x.Name,
                                    Value = x.Id.ToString()
                                });
            return View(collection);
        }
Esempio n. 3
0
        public ActionResult EditAlbum(AlbumViewModel collection, HttpPostedFileBase file)
        {
            Album a2 = collection.Album;
            if (collection.Album != null)
            {
                a2 = db.Albums.Find(collection.Album.Id);
                a2.Name = collection.Album.Name;
            }

            if (ModelState.IsValid)
            {
                Artist newArtist = db.Artists.Find(collection.SelectedArtistId);
                Album a = db.Albums.Find(collection.Album.Id);

                if (a.ArtistName != newArtist.Name)
                {
                    Artist oldArtist = (from a1 in db.Artists
                                        where a1.Name == a.ArtistName
                                        select a1).FirstOrDefault();

                    oldArtist.Albums.Remove(a);
                    foreach (var item1 in a.Songs)
                    {
                        item1.ArtistName = a.ArtistName;
                    }
                    a.Name = collection.Album.Name;
                    a.ArtistName = newArtist.Name;

                    if (file != null && file.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(file.FileName);
                        string path1 = Server.MapPath("/Content/images/covers/");

                        if (!Directory.Exists(path1 + a.ArtistName))
                            Directory.CreateDirectory(path1 + a.ArtistName);

                        if (!Directory.Exists(path1 + a.ArtistName + "/" + a.Name))
                            Directory.CreateDirectory(path1 + a.ArtistName + "/" + a.Name);

                        var path = Server.MapPath("/Content/images/covers/" + a.ArtistName + "/" + a.Name + "/" + fileName);
                        file.SaveAs(path);

                        a.Cover = "/Content/images/covers/" + a.ArtistName + "/" + a.Name + "/" + fileName;
                    }

                    newArtist.Albums.Add(a);

                    db.Entry(oldArtist).State = EntityState.Modified;
                    db.Entry(newArtist).State = EntityState.Modified;
                    db.SaveChanges();
                    return RedirectToAction("Artist", new { artist = newArtist.Name });
                }

                foreach (var item1 in a.Songs)
                {
                    item1.ArtistName = a.ArtistName;
                }
                a.Name = collection.Album.Name;
                a.ArtistName = newArtist.Name;

                if (file != null && file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    string path1 = Server.MapPath("/Content/images/covers/");

                    if (!Directory.Exists(path1 + a.ArtistName))
                        Directory.CreateDirectory(path1 + a.ArtistName);

                    if (!Directory.Exists(path1 + a.ArtistName + "/" + a.Name))
                        Directory.CreateDirectory(path1 + a.ArtistName + "/" + a.Name);

                    var path = Server.MapPath("/Content/images/covers/" + a.ArtistName + "/" + a.Name + "/" + fileName);
                    file.SaveAs(path);

                    a.Cover = "/Content/images/covers/" + a.ArtistName + "/" + a.Name + "/" + fileName;
                }

                db.Entry(a).State = EntityState.Modified;

                db.SaveChanges();
                return RedirectToAction("Artist", new { artist = newArtist.Name });
            }
            collection.Album = a2;
            collection.Artists = db.Artists.ToList().Select(x => new SelectListItem
                                {
                                    Text = x.Name,
                                    Value = x.Id.ToString()
                                });
            return View(collection);
        }
Esempio n. 4
0
        public ActionResult EditAlbum(int id)
        {
            var model = new AlbumViewModel();
            model.Album = db.Albums.Find(id);
            Artist art = (from s in db.Artists
                          where s.Name == model.Album.ArtistName
                          select s).FirstOrDefault();

            model.Artists = db.Artists.ToList().Select(x => new SelectListItem
                            {
                                Text = x.Name,
                                Value = x.Id.ToString()
                            });

            if (art != null)
            {
                model.SelectedArtistId = art.Id;
            }

            return View(model);
        }