public IActionResult CreateGenre([FromBody] GenreDto genreDto) { if (genreDto == null) { return(BadRequest()); } if (genreRepo.GenreExists(genreDto.GenreName)) { ModelState.AddModelError("", "Naziv zanra vec postoji!"); return(StatusCode(404, ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var genreObj = mapper.Map <Genre>(genreDto); if (!genreRepo.CreateGenre(genreObj)) { ModelState.AddModelError("", $"Doslo je do greske u spasavanju {genreObj.GenreName}"); return(StatusCode(500, ModelState)); } return(CreatedAtRoute("GetGenre", new { id = genreObj.GenreId }, genreObj)); }
public IActionResult CreateGenre([FromBody] GenreDTO genreDto) { if (genreDto is null) { _logger.LogError($"The genreDTO returned a null"); return(BadRequest(ModelState)); } if (_genreRepo.GenreExist(genreDto.Name)) { ModelState.AddModelError("", "Genre already exist!"); _logger.LogError($"There is already another resource with name, {genreDto.Name} in the database"); return(StatusCode(404, ModelState)); } if (!ModelState.IsValid) { _logger.LogError("The model state of the DTO is not valid"); return(BadRequest(ModelState)); } var genreObj = _mapper.Map <GenreModel>(genreDto); if (!_genreRepo.CreateGenre(genreObj)) { _logger.LogError($"An error occured while trying to create resource with the name: {genreObj.Name}"); ModelState.AddModelError("", $"Something wrong occured when trying to save record {genreObj.Name}"); return(StatusCode(500, ModelState)); } _logger.LogInformation($"{genreObj.Name} was successfully created"); return(CreatedAtRoute("GetGenreById", new { genreId = genreObj.Id }, genreObj)); }
public Album AddNewAlbum(Album album) { using (var scope = new TransactionScope()) { if (!DoesArtistExist(album.Artist)) { album.Artist.Id = _artistRepository.CreateArtist(album.Artist); } if (!DoesGenreExist(album.Genre)) { album.Genre.Id = _genreRepository.CreateGenre(album.Genre); } if (!album.TracksCountValid()) { return(null); } var id = _albumRepository.CreateAlbum(album); album.Id = id; scope.Complete(); return(album); } }
public ActionResult PostGenre(CreateGenreDto createGenreDto) { Genre genre = _mapper.Map <Genre>(createGenreDto); _repo.CreateGenre(genre); _repo.SaveChanges(); ReadGenreDto readGenreDto = _mapper.Map <ReadGenreDto>(genre); return(CreatedAtRoute(nameof(GetGenreById), new { id = genre.Id }, readGenreDto)); }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var entity = _mapper.Map <MusicStore.Database.Entities.Genre>(GenreModel); entity.Id = Guid.NewGuid().ToString(); _genreRepository.CreateGenre(entity); await _genreRepository.SaveAsync(); return(RedirectToPage("./Index")); }
public IActionResult Post([FromBody] GenreRequest genreRequest) { if (genreRequest == null) { return(StatusCode(400, ModelState)); } if (!ModelState.IsValid) { return(StatusCode(400, ModelState)); } try { var genre = genreRepository.CreateGenre(genreRequest); return(Ok(genre)); } catch (Exception e) { throw e; } }
public async Task <ActionResult <int> > Post(Genre genre) { await genreRepository.CreateGenre(genre); return(genre.Id); }
public void CreateGenre(GenreViewModel genre) { var dbRow = _mapper.Map <Genre>(genre); _genreRepository.CreateGenre(dbRow); }