public void Check_That_Genre_Service_Adds_Genre()
        {
            // A
            var mock = new Mock <IUnitOfWork>();

            mock.Setup(m => m.GenreRepository.Insert(It.IsAny <Genre>()));

            var genreService = new GenreService(mock.Object);

            GenreModel genreModel = GetGenreModel();

            // A
            genreService.Add(genreModel);

            // A
            mock.Verify(m => m.GenreRepository.Insert(It.IsAny <Genre>()));
        }
Beispiel #2
0
        public int Add(PLGenre item)
        {
            if (PLValidation.IsItemNull(item))
            {
                Console.WriteLine("Cant add null");
                return(0);
            }
            int addResult = _curGenrelWorkerService.Add(new BLLGenre {
                GenreName = item.GenreName, Description = item.Description
            });

            if (addResult > 0)
            {
                Console.WriteLine($"Item {item.GenreName} was added");
            }
            else
            {
                Console.WriteLine($"Item add error");
            }
            return(addResult);
        }
Beispiel #3
0
        public IHttpActionResult Post([FromBody] GenreCreateDto genre)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                Genre newGenre = new Genre()
                {
                    Name = genre.Name
                };

                genreService.Add(newGenre);
                genreService.Save();

                var dtoGenre = new GenreDto(newGenre);
                return(Ok(dtoGenre));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public ActionResult Create(GenreViewModel genreViewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var genre = new Genre()
                    {
                        Type = genreViewModel.Type
                    };

                    genreService.Add(genre);
                    genreService.Save();

                    return(RedirectToAction("Index"));
                }
                catch
                {
                    ModelState.AddModelError("", "Database error!");
                    return(View(genreViewModel));
                }
            }
            return(View(genreViewModel));
        }
Beispiel #5
0
 public Genre Add([FromBody] Genre genre)
 {
     return(_genreService.Add(genre));
 }