public ActionResult Create(Genre genre) {
            try {
                if (ModelState.IsValid) {
                    db.Genres.Add(genre);
                    db.SaveChanges();

                    var dbGenre = db.Genres.Where(g => g.Name == genre.Name).SingleOrDefault();
                    return Json(new { Genre = dbGenre, Error = string.Empty });
                } else {
                    //TODO: better error messages
                    string errMsg = "Something failed, probably validation";
                    var er = ModelState.Values.FirstOrDefault();
                    if (er != null && er.Value != null && !String.IsNullOrEmpty(er.Value.AttemptedValue))
                        errMsg = "\"" + er.Value.AttemptedValue + "\" Does not validate";
                    // return Json(new { Error = ModelState.Values.FirstOrDefault() });
                    return Json(new { Error = errMsg });
                }
            } catch (InvalidOperationException ioex) {
                if (ioex.Message.Contains("Sequence contains more than one element"))
                    return Json(new { Error = "Value provided exists in DB, enter a unique value" });
#if DEBUG
                return Json(new { Error = ioex.Message });
#else
                return Json(new { Error = "Internal Error with input provided" });
#endif

            } catch (Exception ex) {
#if DEBUG
                return Json(new { Error = ex.Message });
#else
                return Json(new { Error = "Internal Error with input provided" });
#endif

            }
        }
        public ActionResult Search(string q)
        {
            var result = elasticClient.Search<Album>(body => body.Query(query => query.QueryString(qs => qs.Query(q))));

            var genre = new Genre { Description = "Search results for " + q, Albums = result.Documents.ToList() };

            return View("Browse", genre);
        }
        public ActionResult Edit(Genre item)
        {
            if (ModelState.IsValid)
            {
                db.Entry(item).State = EntityState.Modified;
            }

            return View(item);
        }
 public ActionResult Edit(Genre genre)
 {
     if (ModelState.IsValid)
     {
         db.Entry(genre).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(genre);
 }
        public void When_creating_and_deleting_a_genre()
        {
            var newGenre = new Genre { Name = Name, Description = "For true warriors" };

            var savedGenre = storeRepository.SaveGenre(newGenre);
            AssertThatGenreExists(newGenre.Name);

            storeRepository.DeleteGenre(savedGenre.GenreId);
            AssertThatGenreDoesNotExist(newGenre.Name);
        }
        public ActionResult Browse(string genre)
        {
            // Retrieve Genre and its Associated Albums from database
            var genreModel = new Genre
            {
                Name = genre,
                Albums = this.storeDB.Albums.ToList()
            };

            return this.View(genreModel);
        }
        public JsonResult Create(Genre genre)
        {
            if (ModelState.IsValid)
            {
                db.Genres.Add(genre);
                db.SaveChanges();

                return Json(new { Genre = genre });
            }

            return Json(new { Error = ViewData.ModelState.Values.SelectMany(modelState => modelState.Errors) });
        }
 public ActionResult Create(Genre item)
 {
     if (ModelState.IsValid)
     {
         db.Genres.Add(item);
         return RedirectToAction("Index");
     }
     else
     {
         return View();
     }       
 }
 public static Genre GetDefault()
 {
     var genre = new Genre
                 {
                     GenreId = 123,
                     Description = "description",
                     Name = "name",
                 };
     genre.AddAlbum(AlbumMother.GetDefault(1));
     genre.AddAlbum(AlbumMother.GetDefault(2));
     genre.AddAlbum(AlbumMother.GetDefault(3));
     return genre;
 }
        public ActionResult Browse(string genre)
        {
            // Retrieve Genre and its Associated Albums from database
            var genreModel = new Genre
            {
                Name = genre,
                Albums = new List<Album>
                {
                    new Album { Title = "Album 1" },
                    new Album { Title = "Album 2" },
                    new Album { Title = "Album 3" }
                }
            };

            return this.View(genreModel);
        }
 GenreVm GenreToGenreVm(Genre genre)
 {
     if (genre == null) return null;
     var albumVms = new AlbumVm[] {};
     if (genre.Albums != null)
     {
         albumVms = genre.Albums.Select(AlbumToAlbumVm).ToArray();
     }
     return new GenreVm
            {
                GenreId = genre.GenreId,
                Name = genre.Name,
                Description = genre.Description,
                Albums = albumVms,
            };
 }
        //public string Index()
        //{
        //  return "Hello from Store.Index()";
        //}
        // GET: /Store/Browse?genre=Disco
        public ActionResult Browse(string genre)
        {
            Genre genreModel = new Genre() { Name = genre};

            List<Album> albums = new List<Album>()
                               {
                                 new Album() { Title = genre + " Album 1"},
                                 new Album() { Title = genre + " Album 2"}
                               };
            StoreBrowseViewModel viewModel = new StoreBrowseViewModel()
                                           {
                                             Genre = genreModel,
                                             Albums = albums
                                           };
            return this.View(viewModel);
        }
        //GET: /Store/Browse?genre=?Disco
        public ActionResult Browse(string genre)
        {
            var genreModel = new Genre
            {
                Name = genre
            };
            var albums = new List<Album>(){
                new Album { Title = genre + " Album 1" },
                new Album { Title = genre + " Album 2" }
            };
            var viewModel = new StoreBrowseViewModel
            {
                Genre = genreModel,
                Albums = albums
            };

            return View(viewModel);
        }
Exemple #14
0
        //
        // GET: /Store/Browse?genre=Disco

        public ActionResult Browse(string genre)
        {
            var genreModel = new Genre()
            {
                Name = genre
            };

            var albums = new List<Album>();

            for (int k=1; k<=30; k++)
                albums.Add(new Album() { Title = genre + " Album "+k, Artist = "Artist "+ k });

            var viewModel = new StoreBrowseViewModel()
            {
                Genre = genreModel,
                Albums = albums
            };

            return View(viewModel);
        }
Exemple #15
0
 /// <summary>
 /// Create a new Genre object.
 /// </summary>
 /// <param name="genreId">Initial value of the GenreId property.</param>
 public static Genre CreateGenre(global::System.Int32 genreId)
 {
     Genre genre = new Genre();
     genre.GenreId = genreId;
     return genre;
 }
Exemple #16
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Genres EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToGenres(Genre genre)
 {
     base.AddObject("Genres", genre);
 }
 public Genre SaveGenre(Genre genre)
 {
     musicStoreEntities.Genres.Add(genre);
     musicStoreEntities.SaveChanges();
     return genre;
 }
 public ActionResult Browse(string genre)
 {
     var genreModel = new Genre { Name = genre};
     return View(genreModel);
 }
 static void AssertGenreVmMatchesGenre(Genre genre, GenreVm result)
 {
     Assert.That(genre.GenreId, Is.EqualTo(result.GenreId));
     Assert.That(genre.Name, Is.EqualTo(result.Name));
     Assert.That(genre.Description, Is.EqualTo(result.Description));
 }
        //
        // GET: /Store/Search?genre=Disco
        /// <summary>
        /// Basic ElasticSearch search, for genres
        /// </summary>
        /// <referenceUrl>https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/_nest.html</referenceUrl>
        /// <param name="q">search query string</param>
        /// <returns></returns>
        public ActionResult Search(string q)
        {
            /* basic ElasticSearch query
             * use the Search method specifying what type of search for using it's type parameter.
             * A delegate modifies the search request body (could also filter, request facets, number of hits, etc.)
             */
            var client = ElasticSearchHelper.ElasticClient;
            //// uses /other-index/other-type/_search
            //var searchResultsExample1 = client.Search<Album>(s => s.Index("other-index").OtherType("other-type"));
            //// uses /_all/person/_search
            //var searchResultsExample2 = client.Search<Album>(s => s.AllIndices());
            //// uses /_search
            //var searchResultsExample3 = client.Search<Album>(s => s.AllIndices().AllTypes());

            //var result = ElasticClient.Search<Album>(body =>
            //       body.Query(query =>
            //       query.QueryString(qs => qs.Query(q))));
            var result = client.Search<Album>(
                    s => s.From(0)
                        .Size(50)   // grab first 50 results
                        .Query(query => query.QueryString(qs => qs.Query(q))));

            var genre = new Genre()
                            {
                                Name = "Search results for " + q,
                                Albums = result.Documents.ToList()
                            };

            return View("Browse", genre);
        }