Beispiel #1
0
        public async Task <IActionResult> OnPostAsync(string[] selectedCategories)
        {
            var newSong = new Song();

            if (selectedCategories != null)
            {
                newSong.SongCategories = new List <SongCategory>();
                foreach (var cat in selectedCategories)
                {
                    var catToAdd = new SongCategory
                    {
                        CategoryID = int.Parse(cat)
                    };
                    newSong.SongCategories.Add(catToAdd);
                }
            }
            if (await TryUpdateModelAsync <Song>(
                    newSong,
                    "Song",
                    i => i.Title, i => i.Author,
                    i => i.Price, i => i.PublishingDate, i => i.PublisherID))
            {
                _context.Song.Add(newSong);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            PopulateAssignedCategoryData(_context, newSong);
            return(Page());
        }
        public async Task <IActionResult> Edit(int id, [Bind("SongId,CategoryId")] SongCategory songCategory)
        {
            if (id != songCategory.SongId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(songCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SongCategoryExists(songCategory.SongId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "CategoryId", "CategoryId", songCategory.CategoryId);
            ViewData["SongId"]     = new SelectList(_context.Song, "SongId", "SongId", songCategory.SongId);
            return(View(songCategory));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Singer,Link")] Song song)
        {
            if (id != song.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    Category     cate         = _context.Categories.Find(2);
                    SongCategory songCategory = new SongCategory
                    {
                        Category = cate,
                        Song     = song
                    };
                    _context.Update(song);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SongExists(song.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(song));
        }
Beispiel #4
0
 public void Add(SongCategory songCategory)
 {
     _graphClient.Cypher
     .Create("(songCategory:SongCategory {newSongCategory})")
     .WithParam("newSongCategory", songCategory)
     .ExecuteWithoutResults();
 }
Beispiel #5
0
        public static void GetSongsByCategory(ObservableCollection <Song> songs, SongCategory category)
        {
            var allSongs      = getSongs();
            var filteredSongs = allSongs.Where(s => s.Category == category).ToList();

            songs.Clear();
            filteredSongs.ForEach(s => songs.Add(s));
        }
Beispiel #6
0
 public void Update(SongCategory updatedSongCategory)
 {
     _graphClient.Cypher
     .Match("(songCategory:SongCategory)")
     .Where((SongCategory songCategory) => songCategory.Id == updatedSongCategory.Id)
     .Set("songCategory.name = {newName}")
     .WithParam("newName", updatedSongCategory.Name)
     .ExecuteWithoutResults();
 }
Beispiel #7
0
        public Song(string name, SongCategory category)
        {
            Name      = name;
            Category  = category;
            AudioFile = $"Audio\\{category}\\{name}.wav";
            ImageFile = $"/Assets/Images/{category}/{name}.png";

            ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

            rating = (int)(localSettings.Values[Name + "rating"] ?? -1);
        }
        public async Task <IActionResult> Create([Bind("SongId,CategoryId")] SongCategory songCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(songCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "CategoryId", "CategoryId", songCategory.CategoryId);
            ViewData["SongId"]     = new SelectList(_context.Song, "SongId", "SongId", songCategory.SongId);
            return(View(songCategory));
        }
        public static SongCategoryModel ToSongCategoryModel(SongCategory songCategory)
        {
            if (songCategory == null)
            {
                return(null);
            }

            return(new SongCategoryModel
            {
                Id = songCategory.Id,
                Name = songCategory.Name
            });
        }
Beispiel #10
0
        public ActionResult Create(string name)
        {
            if (!string.IsNullOrEmpty(name) && !string.IsNullOrWhiteSpace(name) && db.SongCategories.FirstOrDefault(c => c.DisplayName.ToUpper() == name.ToUpper().Trim()) == null)
            {
                var category = new SongCategory();

                category.DisplayName = name;

                db.SongCategories.Add(category);
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        public async Task Create(CreateCategoryRequest req)
        {
            var query = await _categories.FindAsync(cat => cat.Category == req.Category);

            if (query.ToList().FirstOrDefault() != null)
            {
                return;
            }

            var category = new SongCategory()
            {
                Category = req.Category
            };
            await _categories.InsertOneAsync(category);
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Singer,Link")] Song song, int[] categoriesId)
        {
            if (ModelState.IsValid)
            {
                foreach (var id in categoriesId)
                {
                    var          category     = _context.Categories.Find(id);
                    SongCategory songCategory = new SongCategory
                    {
                        Category = category,
                        Song     = song
                    };
                    _context.Add(songCategory);
                }
                _context.Add(song);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(song));
        }
Beispiel #13
0
        public async Task <IActionResult> Create([Bind("SongID,NameSong,Singer,Author")] Song song, int[] categoriesId)
        {
            // Lấy danh sách category id khi người dùng check qua mảng categoryId
            if (ModelState.IsValid)
            {
                foreach (var id in categoriesId)
                {
                    var          category     = _context.Category.Find(id);
                    SongCategory songCategory = new SongCategory
                    {
                        Category = category,
                        Song     = song
                    };
                    _context.Add(songCategory);
                }
                _context.Add(song);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(song));
        }
 public static void RefreshSongCategory(SongCategory songCategory, SongCategoryModel songCategoryModel)
 {
     songCategory.Name = songCategoryModel.Name;
 }