示例#1
0
        public ActionResult EditGanre(Ganre ganre)
        {
            Model1 db = new Model1();

            db.Entry(ganre).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#2
0
        public void SaveUpdate(Ganre orderDto)
        {
            Ganre ganre = new Ganre
            {
                FirstName = orderDto.FirstName
            };

            db.Ganre.Update(ganre);
            db.Save();
        }
示例#3
0
        public void MakeGanre(GanreDTO orderDto)
        {
            Ganre ganre = new Ganre
            {
                FirstName = orderDto.FirstName,
            };

            db.Ganre.Create(ganre);
            db.Save();
        }
示例#4
0
        public ActionResult Delete(int id)
        {
            Model1 db = new Model1();
            Ganre  b  = db.Ganres.Find(id);

            if (b == null)
            {
                return(HttpNotFound());
            }
            return(View(b));
        }
示例#5
0
        public ActionResult DeleteConfirmed(int id)
        {
            Model1 db = new Model1();
            Ganre  b  = db.Ganres.Find(id);

            if (b == null)
            {
                return(HttpNotFound());
            }
            db.Ganres.Remove(b);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#6
0
        //private Task PlaySong(string path)
        //{
        //    return Task.Run(() =>
        //    {

        //    });

        //}

        public void FilterByGenre(Ganre ganre)
        {
            var newSongCollection = new List <Song>();

            for (int i = 0; i < this.Items.Count; i++)
            {
                if ((this.Items[i].Ganre & ganre) != 0)
                {
                    newSongCollection.Add(this.Items[i]);
                }
            }

            Items = newSongCollection;
        }
示例#7
0
        public ActionResult EditGanre(int?id)
        {
            Model1 db = new Model1();

            if (id == null)
            {
                return(HttpNotFound());
            }
            Ganre ganre = db.Ganres.Find(id);

            if (ganre != null)
            {
                return(View(ganre));
            }
            return(HttpNotFound());
        }
示例#8
0
 public ActionResult Create(Ganre ganres)
 {
     using (Model1 db = new Model1())
     {
         if (ModelState.IsValid)
         {
             db.Ganres.Add(ganres);
             db.SaveChanges();
         }
         else
         {
             return(View(ganres));
         }
     }
     return(Redirect("Index"));
 }
        public ActionResult AddGanre([Bind(Include = "Title, Description")] Ganre ganre)
        {
            //if (string.IsNullOrEmpty(ganre.Title))
            //{
            //    ModelState.AddModelError("Title", "Input title!");
            //}

            if (ModelState.IsValid)
            {
                //dbGanre.Create(ganre);
                db1.Ganres.Add(ganre);
                db1.SaveChanges();
                return(RedirectToAction("ShowAll"));
            }


            return(View(ganre));
        }
示例#10
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Ganre ganre)
        {
            if (!IsDuplicate(ganre))
            {
                if (ModelState.IsValid)
                {
                    _context.Add(ganre);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(ganre));
            }
            else
            {
                ModelState.AddModelError("Name", "Такий жанр уже існує");
            }

            return(View(ganre));
        }
示例#11
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Ganre ganre)
        {
            if (id != ganre.Id)
            {
                return(NotFound());
            }
            var model = _context.Ganres.FirstOrDefault(g => g.Name.Equals(ganre.Name) && g.Id != id);

            if (model == null)
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(ganre);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!GanreExists(ganre.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(ganre));
            }
            else
            {
                ModelState.AddModelError("Name", "Такий жанр уже існує");
            }

            return(View(ganre));
        }
示例#12
0
 public Band(string name, Ganre ganre)
 {
     Name  = name;
     Ganre = ganre;
 }
示例#13
0
        private bool IsDuplicate(Ganre model)
        {
            var ganre = _context.Ganres.FirstOrDefault(g => g.Name.Equals(model.Name));

            return(ganre == null ? false : true);
        }
        public async Task SongController_PostEdit_ShoudReturnRedirectWithViewModel()
        {
            //Arrenge
            int     modelId        = 0;
            string  modelName      = null;
            decimal modelPrice     = 0;
            double  modelDuration  = 0;
            int     modelArtistId  = 0;
            Ganre   modelGanre     = 0;
            string  successMessage = null;

            int     resultModelId       = 1;
            string  resultModelName     = "TestSong";
            decimal resultModelPrice    = 2;
            double  resultModelDuration = 3;
            int     resultModelArtistId = 4;
            Ganre   resultModelGanre    = Ganre.Disco;

            var adminSongService = this.GetAdminSongServiceBaseMock();

            adminSongService.Setup(s => s.ExistAsync(It.IsAny <int>()))
            .ReturnsAsync(true);

            var adminArtistService = this.GetAdminArtistServiceMock();

            adminArtistService.Setup(a => a.ExistAsync(It.IsAny <int>()))
            .ReturnsAsync(true);

            adminSongService.Setup(s => s.EditAsync(
                                       It.IsAny <int>(),
                                       It.IsAny <string>(),
                                       It.IsAny <decimal>(),
                                       It.IsAny <double>(),
                                       It.IsAny <int>(),
                                       It.IsAny <Ganre>()
                                       ))
            .Callback((int id, string name, decimal price, double duration, int artistId, Ganre ganre) =>
            {
                modelId       = id;
                modelName     = name;
                modelPrice    = price;
                modelDuration = duration;
                modelArtistId = artistId;
                modelGanre    = ganre;
            })
            .Returns(Task.CompletedTask);

            adminSongService
            .Setup(a => a.IsGanreExist(It.IsAny <int>()))
            .Returns(true);

            var tempDate = new Mock <ITempDataDictionary>();

            tempDate.SetupSet(t => t[WebConstants.TempDataSuccessMessageKey] = It.IsAny <string>())
            .Callback((string key, object message) => successMessage         = message as string);

            var controller = new SongsController(adminArtistService.Object, adminSongService.Object);

            controller.TempData = tempDate.Object;

            //Act
            var result = await controller.Edit(resultModelId, new SongFormViewModel
            {
                Name     = resultModelName,
                Price    = resultModelPrice,
                Duration = resultModelDuration,
                ArtistId = resultModelArtistId,
                Ganre    = resultModelGanre
            });

            //Assert
            modelId.Should().Be(resultModelId);
            modelName.Should().Be(resultModelName);
            modelPrice.Should().Be(resultModelPrice);
            modelDuration.Should().Be(resultModelDuration);
            modelArtistId.Should().Be(resultModelArtistId);
            modelGanre.Should().Be(resultModelGanre);

            successMessage.Should().Be($" Song {resultModelName} has been edited successfully");

            result.Should().BeOfType <RedirectToActionResult>();

            result.As <RedirectToActionResult>().ActionName.Should().Be("ListAll");
        }
示例#15
0
        public async Task CreateAsync(string name, decimal price, double duration, int artistId, Ganre ganre)
        {
            var song = new Song
            {
                Name     = name,
                Price    = price,
                Duration = duration,
                ArtistId = artistId,
                Ganre    = ganre
            };

            await this.db.Songs.AddAsync(song);

            await this.db.SaveChangesAsync();
        }
示例#16
0
        public async Task EditAsync(int id, string name, decimal price, double duration, int artistId, Ganre ganre)
        {
            var song = await this.db.Songs.FindAsync(id);

            if (song == null)
            {
                return;
            }

            song.Name     = name;
            song.Price    = price;
            song.Duration = duration;
            song.ArtistId = artistId;
            song.Ganre    = ganre;

            this.db.Songs.Update(song);
            await this.db.SaveChangesAsync();
        }
示例#17
0
        public void PrintGanre()
        {
            Ganre ganre = this.Ganre;

            Console.WriteLine("Жанр музыки");
            if ((ganre & Ganre.Afro) == Ganre.Afro)
            {
                Console.WriteLine(Ganre.Afro);
            }
            if ((ganre & Ganre.Avant_garde) == Ganre.Avant_garde)
            {
                Console.WriteLine(Ganre.Avant_garde);
            }
            if ((ganre & Ganre.Blues) == Ganre.Blues)
            {
                Console.WriteLine(Ganre.Blues);
            }
            if ((ganre & Ganre.Caribbean) == Ganre.Caribbean)
            {
                Console.WriteLine(Ganre.Caribbean);
            }
            if ((ganre & Ganre.Comedy) == Ganre.Comedy)
            {
                Console.WriteLine(Ganre.Comedy);
            }
            if ((ganre & Ganre.Country) == Ganre.Country)
            {
                Console.WriteLine(Ganre.Country);
            }
            if ((ganre & Ganre.Easy_listening) == Ganre.Easy_listening)
            {
                Console.WriteLine(Ganre.Easy_listening);
            }
            if ((ganre & Ganre.Electronic) == Ganre.Electronic)
            {
                Console.WriteLine(Ganre.Electronic);
            }
            if ((ganre & Ganre.Folk) == Ganre.Folk)
            {
                Console.WriteLine(Ganre.Folk);
            }
            if ((ganre & Ganre.Hip_hop) == Ganre.Hip_hop)
            {
                Console.WriteLine(Ganre.Hip_hop);
            }
            if ((ganre & Ganre.Jazz) == Ganre.Jazz)
            {
                Console.WriteLine(Ganre.Jazz);
            }
            if ((ganre & Ganre.Latin) == Ganre.Latin)
            {
                Console.WriteLine(Ganre.Latin);
            }
            if ((ganre & Ganre.Pop) == Ganre.Pop)
            {
                Console.WriteLine(Ganre.Pop);
            }
            if ((ganre & Ganre.Soul) == Ganre.Soul)
            {
                Console.WriteLine(Ganre.Soul);
            }
            if ((ganre & Ganre.Rock) == Ganre.Rock)
            {
                Console.WriteLine(Ganre.Rock);
            }
            if ((ganre | Ganre.None) == Ganre.None)
            {
                Console.WriteLine(Ganre.None);
            }
            // Console.WriteLine();

            //if (ganre == Ganre.None)  // Алтернативный вариант вывода жанров, рабочий
            //{
            //    Console.WriteLine(Ganre.None);
            //    return;
            //}

            //int b = 1;

            //for (int i = 0; i < 15; i++)
            //{
            //    Ganre r = (Ganre)((int)ganre & b);

            //    if (Ganre.HasFlag(r) && r != Ganre.None)
            //        Console.WriteLine((Ganre)b);

            //    b = b << 1;
            //}
        }