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)); }
private void AddGenre() { Genre g = new Genre { Id = 0, Name = _name }; _genreSvc.AddGenre(g); }
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); }
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()); }
public IActionResult AddGenre([FromBody] GenreDto genreDto) { GenreDto genreDtoObj = _genreService.AddGenre(genreDto); if (genreDtoObj == null) { return(BadRequest("Failed to add genre!")); } return(Ok(genreDtoObj)); }
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)); }
public ActionResult Create(Genre genre) { if (ModelState.IsValid) { genreService.AddGenre(genre); return(RedirectToAction("Index")); } else { return(View(genre)); } }
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!")); }
public IActionResult AddGenre([FromBody] GenreModel model) { if (model == null) { return(BadRequest()); } if (!ModelState.IsValid) { throw new InvalidModelStateException(ModelState); } _genreService.AddGenre(model); return(Ok(true)); }
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); }
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()); } }
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)); }
public void Post([FromBody] Genre genre) { _genreservice.AddGenre(genre); }
public async Task <IActionResult> Add(GenreDtoAdd newItem) { var result = await _genreService.AddGenre(newItem); return(Ok(result)); }
public IActionResult Create(CreateGenreViewModel model) { Boolean success = _genreService.AddGenre(_mapper.Map <MusicCore.Genre>(model.genre)); return(RedirectToAction("Genres")); }