コード例 #1
0
        // GET: Albums/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Album album = repo.Get(id.Value);

            if (album == null)
            {
                return(HttpNotFound());
            }
            return(View(album));
        }
コード例 #2
0
        public IActionResult GetAlbum([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var album = albumRepo.Get(id);

            if (album == null)
            {
                return(NotFound());
            }

            return(Ok(album));
        }
コード例 #3
0
        public IActionResult MostrarDetalle(int id)
        {
            var   albumRepo = new AlbumRepository();
            Album album     = albumRepo.Get(id);

            return(View(album));
        }
コード例 #4
0
ファイル: AlbumController.cs プロジェクト: dongdundang/WebMVC
 public JsonResult GetAll()
 {
     using (AlbumRepository rep = new AlbumRepository())
     {
         return(Json(rep.Get(x => x.Activate == true), JsonRequestBehavior.AllowGet));
     }
 }
コード例 #5
0
ファイル: AlbumController.cs プロジェクト: dongdundang/WebMVC
 public JsonResult GetAlbumById(int id)
 {
     using (AlbumRepository rep = new AlbumRepository())
     {
         var album = rep.Get(x => x.Activate == true && x.Id == id).First();
         return(Json(album, JsonRequestBehavior.AllowGet));
     }
 }
コード例 #6
0
        public ActionResult List()
        {
            var email = User.Identity.Name;

            var model = AlbumRepository.Get(email).ToModel();

            return(PartialView("List", model));
        }
        public void Get_Empty_ReturnsAllAlbums()
        {
            var albums = new List <Album>
            {
                new Album {
                    Id = Guid.NewGuid()
                },
                new Album {
                    Id = Guid.NewGuid()
                }
            };

            _context.Albums.AddRange(albums);
            _context.SaveChanges();

            var results = _albumRepository.Get().ToList();

            Assert.AreEqual(albums.Count, results.Count);
        }
コード例 #8
0
        public Album Get(int id)
        {
            Album album = albumRepository.Get(id);

            if (album == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            return(album);
        }
コード例 #9
0
        // -------------------- Download --------------------
        public FileResult GetAlbumInArchive(long idAlbum)
        {
            var album   = AlbumRepository.Get(idAlbum);
            var zipName = string.Format("Martin S. - {0}.zip", album.Name);
            var zipPath = Path.Combine(Server.MapPath("~/Content/Song"), zipName);

            if (FileStandard.Exists(zipPath))
            {
                FileStandard.Delete(zipPath);
            }

            var zipFile = ZipFile.Create(zipPath);

            zipFile.BeginUpdate();

            var count = 1;

            // Add song in archive
            foreach (var song in album.Songs)
            {
                var globalMp3Path = Server.MapPath("~/" + FileHelper.PathToSong(album.Name, song.Mp3FileName));
                var dataSource    = new StaticDiskDataSource(globalMp3Path);
                var cyrillicName  = song.Name;
                var romanName     = cyrillicName.FromCyrillicToRomanAlphabet();
                var songFileName  = string.Format("{0}. Martin S. - {1}.mp3", count++, romanName);
                zipFile.Add(dataSource, songFileName);
            }

            // Add readme in archive
            var readmePath = Server.MapPath("~/" + FileHelper.PathToSong(album.Name, "readme.txt"));

            FileStandard.WriteAllText(readmePath, album.ReadmeInArchive);
            var readmeDataSource = new StaticDiskDataSource(readmePath);

            zipFile.Add(readmeDataSource, Path.GetFileName(readmePath));

            // Add cover in archive
            var coverPath       = Server.MapPath("~/" + FileHelper.PathToCoverForAlbum(album.CoverFileName));
            var coverDataSource = new StaticDiskDataSource(coverPath);

            zipFile.Add(coverDataSource, Path.GetFileName(coverPath).FromCyrillicToRomanAlphabet());

            zipFile.CommitUpdate();
            zipFile.Close();

            var fileBytes = FileStandard.ReadAllBytes(zipPath);
            var fileName  = Path.GetFileName(zipPath);

            return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Zip, fileName));
        }
コード例 #10
0
ファイル: AlbumController.cs プロジェクト: JinOptimist/Martin
        // -------------------- Song Region --------------------

        public ActionResult AddSong(long albumId, long?songId)
        {
            var model = new Song();

            if (songId.HasValue)
            {
                model = SongRepository.Get(songId.Value);
            }
            else
            {
                model.Album = AlbumRepository.Get(albumId);
            }

            return(View(model));
        }
コード例 #11
0
        //
        // GET: /Store/AddToCart/5
        public ActionResult AddToCart(int id)
        {
            Console.WriteLine("ShoppingCartsController AddTocard - AlbumId: " + id.ToString());
            // Retrieve the album from the database
            var albumRepo = new AlbumRepository();
            var album     = albumRepo.Get(id);

            if (album != null)
            {
                var cart = ShoppingCartRepository.GetCart(HttpContext);
                cart.AddToCart(album);
            }
            // Go back to the main store page for more shopping
            return(RedirectToAction("Index", "Home"));
        }
コード例 #12
0
ファイル: AlbumController.cs プロジェクト: JinOptimist/Martin
        public ActionResult AddSong(Song model)
        {
            var album    = AlbumRepository.Get(model.Album.Id);
            var folder   = Path.Combine("song", album.Name);
            var songName = SaveAttach(folder, Request.Files["Song"]);

            if (model.Id <= 0)
            {
                var order = SongRepository.Count(model.Album.Id) + 1;
                model.Order = order;
            }

            if (model.Id <= 0 || !string.IsNullOrEmpty(songName))
            {
                model.Mp3FileName = songName;
            }

            SongRepository.Save(model);
            return(RedirectToAction("Albums"));
        }
コード例 #13
0
 private void AddOrGetAlbumId(SongTagFile songTag, Song song)
 {
     if (songTag.Album != null)
     {
         var album = AlbumRepository.Get(x => x.Title == songTag.Album).FirstOrDefault();
         if (album == null)
         {
             song.Album = new Album()
             {
                 Title = songTag.Album
             };
             AlbumRepository.Insert(song.Album);
             this.Save();
         }
         else
         {
             song.AlbumId = album.Id;
         }
     }
 }
コード例 #14
0
ファイル: AlbumController.cs プロジェクト: JinOptimist/Martin
        public ActionResult Delete(long id)
        {
            var album   = AlbumRepository.Get(id);
            var zipPath = Path.Combine(Server.MapPath("~/Content/Song"), album.Name + ".zip");

            if (System.IO.File.Exists(zipPath))
            {
                System.IO.File.Delete(zipPath);
            }

            var albumPath = Path.Combine(Server.MapPath("~/Content/Song"), album.Name);

            if (System.IO.File.Exists(albumPath))
            {
                System.IO.File.Delete(albumPath);
            }

            AlbumRepository.Delete(id);
            AlbumRepository.Reorder();

            return(RedirectToAction("Albums"));
        }
コード例 #15
0
ファイル: AlbumController.cs プロジェクト: JinOptimist/Martin
        public ActionResult Edit(long id)
        {
            var model = AlbumRepository.Get(id);

            return(View("Add", model));
        }
コード例 #16
0
        // GET: Album/Edit/5
        public ActionResult Edit(Guid id)
        {
            var model = AlbumRepository.Get(id).ToModel();

            return(View(model));
        }
コード例 #17
0
 public HttpResponseMessage GetAlbumById(int id)
 {
     return(Request.CreateResponse(HttpStatusCode.OK, repository.Get(id)));
 }
コード例 #18
0
        public IActionResult Get()
        {
            AlbumRepository repo = new AlbumRepository(_configuration);

            return(Ok(repo.Get()));
        }