Beispiel #1
0
 public IActionResult Post([FromBody] BOGenre genre)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     return(Ok(facade.GenreService.Create(genre)));
 }
Beispiel #2
0
 public BOGenre Create(BOGenre genre)
 {
     // using - invoke the dipose function. Make sure that we aren't connected to anything and database is closed.
     using (var uow = facade.UnitOfWork)
     {
         var genreEntity = uow.GenreRepository.Create(conv.Convert(genre));
         uow.Complete();
         return(conv.Convert(genreEntity));
     }
 }
Beispiel #3
0
 /// <summary>
 /// Sending/saving data to database.
 /// </summary>
 /// <returns>The convert.</returns>
 /// <param name="gen">Gen.</param>
 internal Genre Convert(BOGenre gen)
 {
     if (gen == null)
     {
         return(null);
     }
     return(new Genre()
     {
         Id = gen.Id,
         Name = gen.Name,
         Author = gen.Author
     });
 }
Beispiel #4
0
 public BOGenre Update(BOGenre rent)
 {
     using (var uow = facade.UnitOfWork)
     {
         var genreEntity = uow.GenreRepository.Get(rent.Id);
         if (genreEntity == null)
         {
             throw new InvalidOperationException("Genre not found");
         }
         uow.Complete();
         return(conv.Convert(genreEntity));
     }
 }
Beispiel #5
0
 public IActionResult Put(int id, [FromBody] BOGenre genre)
 {
     if (id != genre.Id)
     {
         return(StatusCode(405, "Path Id didn't match the Customer's Id in json object"));
     }
     try
     {
         var genreUpdated = facade.GenreService.Update(genre);
         return(Ok(genreUpdated));
     }
     catch (Exception e)
     {
         return(StatusCode(404, e.Message));
     }
 }