public async Task <IActionResult> Create([FromBody] GenreCreateDTO genreDTO) { var location = GetControllerActionNames(); try { _logger.LogInfo($"{location}: Started Create Genre"); if (genreDTO == null) { _logger.LogError($"{location}: Empty request"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _logger.LogError($"{location}: Wrong model state"); return(BadRequest(ModelState)); } var genre = _mapper.Map <Genre>(genreDTO); var IsSuccess = await _genreRepository.Create(genre); if (!IsSuccess) { return(InternalError($"{location} : Creation failed")); } return(Created("Create", new { genre })); } catch (Exception ex) { return(InternalError($"{location} : Something wrong {ex.Message}")); } }
public async Task <GenreDTO> PutAsync(GenreCreateDTO genre) { this.Logger.LogTrace($"{nameof(this.PutAsync)} called"); var result = await this.GenreCreateService.CreateAsync(this.Mapper.Map <GenreUpdateModel>(genre)); return(this.Mapper.Map <GenreDTO>(result)); }
public IActionResult AddNewGenre(GenreCreateDTO genre) { var guid = genreService.AddNewGenre(genre); string location = linkGenerator.GetPathByAction("GetGenreByID", "Genre", new { genreID = guid }); return(Created(location, guid)); }
public async Task <ActionResult> Put(int id, [FromBody] GenreCreateDTO model) { try { var entity = _automapper.Map <Genre>(model); entity.Id = id; _db.Entry(entity).State = EntityState.Modified; await _db.SaveChangesAsync(); return(NoContent()); } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <ActionResult> Post([FromBody] GenreCreateDTO model) { try { var entity = _automapper.Map <Genre>(model); await _db.AddAsync(entity); await _db.SaveChangesAsync(); var genreDTO = _automapper.Map <GenreDTO>(entity); return(new CreatedAtRouteResult("GetGenreById", new { id = genreDTO.Id }, genreDTO)); } catch (Exception ex) { return(BadRequest(ex)); } }
public Guid AddNewGenre(GenreCreateDTO genre) { return(genreRepository.AddNewGenre(mapper.Map <Genre>(genre))); }