예제 #1
0
        public ActionResult Create(Models.Genre model)
        {
            if (ModelState.IsValid)
            {
                if (!genreService.ExistsGenre(model.Name))
                {
                    var dbModel = new Domain.Genre();
                    dbModel.InjectFrom(model);
                    genreService.AddGenre(dbModel);
                    TempData["message"] = string.Format("{0} has been saved", model.Name);
                }

                else
                {
                    ModelState.AddModelError("Name", "This genre is already in the database!!");

                    return(View(model));
                }
                //genreRepository.Add(dbModel);

                //transform the object
                //unitOfWork.Commit();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
예제 #2
0
        private void AddGenre()
        {
            Genre g = new Genre {
                Id = 0, Name = _name
            };

            _genreSvc.AddGenre(g);
        }
예제 #3
0
        public ActionResult AddGenre(string genreName)
        {
            var genre = new Genre();

            genre.Name = genreName;
            genreService.AddGenre(genre);

            return(Json(new { genreId = genre.Id }));
        }
        public void AddGenre_ReceivesValidParameter_True()
        {
            //assign
            GenreCreateDto newGenre = new GenreCreateDto()
            {
                Name = "Genre", HeadGenreId = null
            };
            Genre nullGenre = null;

            genreRepositoryMoq.Setup((p) => p.GetSingleAsync(It.IsAny <Expression <Func <Genre, bool> > >()))
            .Returns(Task.FromResult(nullGenre));

            //act
            service.AddGenre(newGenre);

            //assert
            genreRepositoryMoq.Verify(p => p.Create(It.IsAny <Genre>()), Times.Once);
            unitofworkMoq.Verify(p => p.CommitAsync(), Times.Once);
        }
예제 #5
0
        public ActionResult Add(GenreViewModel item)
        {
            if (ModelState.IsValid)
            {
                var genre = mapper.Map <Genre>(item);

                genreService.AddGenre(genre);
                return(RedirectToAction("Index"));
            }
            return(Add());
        }
        public ActionResult Create(GenreViewModel model)
        {
            if (ModelState.IsValid)
            {
                var dev = mapper.Map <Genre>(model);
                genService.AddGenre(dev);

                return(RedirectToAction("Index"));
            }
            return(Create());
        }
예제 #7
0
        public IActionResult AddGenre([FromBody] GenreDto genreDto)
        {
            GenreDto genreDtoObj = _genreService.AddGenre(genreDto);

            if (genreDtoObj == null)
            {
                return(BadRequest("Failed to add genre!"));
            }

            return(Ok(genreDtoObj));
        }
예제 #8
0
        public ActionResult Create([Bind(Include = "Id,Title")] GenreViewModel genreViewModel)
        {
            if (ModelState.IsValid)
            {
                genreViewModel.Id = Guid.NewGuid();
                Genre genre = Mapper.Map <GenreViewModel, Genre>(genreViewModel);
                _service.AddGenre(genre);
                return(RedirectToAction("Index"));
            }

            return(View(genreViewModel));
        }
예제 #9
0
 public ActionResult Create(Genre genre)
 {
     if (ModelState.IsValid)
     {
         genreService.AddGenre(genre);
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View(genre));
     }
 }
예제 #10
0
        public async Task <IActionResult> Post([FromBody] CreateGanreModel value)
        {
            GenreCreateDto genre = new GenreCreateDto()
            {
                Name        = value.Name,
                HeadGenreId = value.HeadGenre
            };

            await genreService.AddGenre(genre);

            return(StatusCode((int)HttpStatusCode.Created, "Genre was added!"));
        }
예제 #11
0
        public IActionResult AddGenre([FromBody] GenreModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                throw new InvalidModelStateException(ModelState);
            }

            _genreService.AddGenre(model);
            return(Ok(true));
        }
예제 #12
0
        public HttpResponseMessage Add(HttpRequestMessage request, GenreViewModel genreVM)
        {
            HttpResponseMessage response = null;

            if (!ModelState.IsValid)
            {
                response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
            else
            {
                Genre newGenre = Mapper.Map <Genre>(genreVM);
                genreService.AddGenre(newGenre);
                genreVM  = Mapper.Map <Genre, GenreViewModel>(newGenre);
                response = request.CreateResponse <GenreViewModel>(HttpStatusCode.Created, genreVM);
            }
            return(response);
        }
예제 #13
0
 public IActionResult Post([FromBody] Genre genre)
 {
     if (genre == null)
     {
         return(BadRequest());
     }
     else if (genre.Id == 0)
     {
         _genre.AddGenre(genre);
         return(Ok());
     }
     else
     {
         _genre.UpdateGenre(genre);
         return(Ok());
     }
 }
예제 #14
0
        public ActionResult Post([FromBody] Genre newItem)
        {
            if (newItem is null)
            {
                return(BadRequest());
            }

            var existingGenres = _genreService.AsQueryable().ToList();

            foreach (var existingGenre in existingGenres)
            {
                if (newItem.Name.ToLower() == existingGenre.Name.ToLower())
                {
                    return(BadRequest($"Genre {newItem.Name} already exists!"));
                }
            }

            var item = _genreService.AddGenre(newItem);

            return(Ok(item));
        }
예제 #15
0
 public void Post([FromBody] Genre genre)
 {
     _genreservice.AddGenre(genre);
 }
예제 #16
0
        public async Task <IActionResult> Add(GenreDtoAdd newItem)
        {
            var result = await _genreService.AddGenre(newItem);

            return(Ok(result));
        }
예제 #17
0
        public IActionResult Create(CreateGenreViewModel model)
        {
            Boolean success = _genreService.AddGenre(_mapper.Map <MusicCore.Genre>(model.genre));

            return(RedirectToAction("Genres"));
        }