コード例 #1
0
        public ActionResult SaveArtist(Artist postedArtist)
        {
            if (!ModelState.IsValid)
            {
                throw new CallbackException("Model binding failed.", 500);
            }

            var artistBus = new ArtistBusiness();

            // attach to context
            var artist = artistBus.Attach(postedArtist);

            if (!artistBus.Validate())
            {
                throw new CallbackException("Please correct the following: " + artistBus.ValidationErrors.ToString());
            }

            if (!artistBus.Save())
            {
                throw new CallbackException("Unable to save artist: " + artistBus.ErrorMessage);
            }

            var albumBus = new AlbumBusiness();
            var albums   = albumBus.GetAlbumsForArtist(artist.Id);

            return(new JsonNetResult(new ArtistResponse
            {
                Artist = artist,
                Albums = albums
            }));
        }
コード例 #2
0
        public ActionResult SaveAlbum(Album dtoAlbum)
        {
            if (dtoAlbum == null)
            {
                throw new CallbackException("No album provided for saving.", 500);
            }

            if (!ModelState.IsValid)
            {
                throw new CallbackException("Model binding failed.", 500);
            }

            var id = dtoAlbum.Id;

            var albumBus = new AlbumBusiness();

            if (!albumBus.Validate(dtoAlbum))
            {
                throw new CallbackException("Album didn't validate: " + albumBus.ErrorMessage);
            }

            if (!albumBus.SaveAlbum(dtoAlbum))
            {
                throw new CallbackException("Album save failed: " + albumBus.ErrorMessage);
            }

            return(new JsonNetResult(albumBus.Entity));
        }
コード例 #3
0
        public ActionResult DeleteAlbum(int id)
        {
            var albumBus = new AlbumBusiness();

            if (!albumBus.Delete(id, saveChanges: true, useTransaction: true))
                throw new CallbackException("Couldn't delete album: " + albumBus.ErrorMessage);

            return Json(true, JsonRequestBehavior.AllowGet);
        }
コード例 #4
0
        public ActionResult Create()
        {
            AlbumBusiness albumBusiness = new AlbumBusiness();

            int   idAlbum = Convert.ToInt32(ConfigurationManager.AppSettings["AlbumUtilizado"].ToString());
            Album album   = albumBusiness.BuscarAlbum(idAlbum);

            ViewBag.Album = album;

            return(View());
        }
コード例 #5
0
        public ActionResult DeleteAlbum(int id)
        {
            var albumBus = new AlbumBusiness();

            if (!albumBus.Delete(id, saveChanges: true, useTransaction: true))
            {
                throw new CallbackException("Couldn't delete album: " + albumBus.ErrorMessage);
            }

            return(Json(true, JsonRequestBehavior.AllowGet));
        }
コード例 #6
0
        public void GetAlbumsTest()
        {
            var albumBus = new AlbumBusiness();
            var albums = albumBus.GetAllAlbums();
            Assert.IsNotNull(albums, albumBus.ErrorMessage);

            var albumList = albums.ToList();

            Console.WriteLine(albumList.Count);

            Assert.IsTrue(albumList.Count > 0, "List should return some data.");
        }
コード例 #7
0
        public ActionResult GetAlbum(int id = -1)
        {
            if (id < 1)
                throw new CallbackException("Invalid album id passed.");

            var albumBus = new AlbumBusiness();
            var album = albumBus.Load(id);
            
            if (album == null)
                throw new CallbackException("Invalid album id passed.");

            return new JsonNetResult(album);
        }
コード例 #8
0
        public void GetAlbumsTest()
        {
            var albumBus = new AlbumBusiness();
            var albums   = albumBus.GetAllAlbums();

            Assert.IsNotNull(albums, albumBus.ErrorMessage);

            var albumList = albums.ToList();

            Console.WriteLine(albumList.Count);

            Assert.IsTrue(albumList.Count > 0, "List should return some data.");
        }
コード例 #9
0
        public ActionResult Edit()
        {
            AlbumBusiness   albumBusiness   = new AlbumBusiness();
            OfertasBusiness ofertasBusiness = new OfertasBusiness();

            int   idAlbum = Convert.ToInt32(ConfigurationManager.AppSettings["AlbumUtilizado"].ToString());
            Album album   = albumBusiness.BuscarAlbum(idAlbum);

            ViewBag.Album = album;

            Ofertas oferta = ofertasBusiness.BuscarOferta(int.Parse(this.RouteData.Values["id"].ToString()));

            return(View(oferta));
        }
コード例 #10
0
        //
        // GET: /VisualizarAlbum/

        public ActionResult Index()
        {
            AlbumBusiness AlbumBusiness = new AlbumBusiness();

            try
            {
                int   idAlbum = Convert.ToInt32(ConfigurationManager.AppSettings["AlbumUtilizado"].ToString());
                Album album   = AlbumBusiness.BuscarAlbum(idAlbum);
                return(View(album));
            }
            catch (BusinessException ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View());
            }
        }
コード例 #11
0
        public ActionResult GetAlbum(int id = -1)
        {
            if (id < 1)
            {
                throw new CallbackException("Invalid album id passed.");
            }

            var albumBus = new AlbumBusiness();
            var album    = albumBus.Load(id);

            if (album == null)
            {
                throw new CallbackException("Invalid album id passed.");
            }

            return(new JsonNetResult(album));
        }
コード例 #12
0
        public ActionResult SaveAlbum(Album dtoAlbum)
        {
            if (dtoAlbum == null)
                throw new CallbackException("No album provided for saving.", 500);

            if (!ModelState.IsValid)
                throw new CallbackException("Model binding failed.", 500);

            var id = dtoAlbum.Id;

            var albumBus = new AlbumBusiness();
            
            if (!albumBus.Validate(dtoAlbum))
                throw new CallbackException("Album didn't validate: " + albumBus.ErrorMessage);

            if (!albumBus.SaveAlbum(dtoAlbum))
                throw new CallbackException("Album save failed: " + albumBus.ErrorMessage);

            return new JsonNetResult(albumBus.Entity);
        }
コード例 #13
0
        public ActionResult Get(int id = -1)
        {
            if (id < 1)
            {
                throw new CallbackException("Invalid id passed.");
            }

            var artistBus = new ArtistBusiness();
            var artist    = artistBus.Load(id);

            if (artist == null)
            {
                throw new CallbackException("Invalid id passed.");
            }

            var albumBus = new AlbumBusiness();
            var albums   = albumBus.GetAlbumsForArtist(artist.Id);

            return(new JsonNetResult(new ArtistResponse
            {
                Artist = artist,
                Albums = albums
            }));
        }
コード例 #14
0
 public ActionResult Index()
 {
     var albumBus = new AlbumBusiness();
     return new JsonNetResult(albumBus.GetAllAlbums());
 }
コード例 #15
0
        public ActionResult Index()
        {
            var albumBus = new AlbumBusiness();

            return(new JsonNetResult(albumBus.GetAllAlbums()));
        }
コード例 #16
0
 public AlbumController(AlbumBusiness AlbumBusiness)
 {
     this._AlbumBusiness = AlbumBusiness;
 }