Exemplo n.º 1
0
 public async Task <ActionResult> DeleteMovie(int id)
 {
     try
     {
         MotionPictures toDelete = _dbContext.MotionPictures.SingleOrDefault(x => x.ID == id);
         // TODO: Check null
         _dbContext.MotionPictures.Remove(toDelete);
         await _dbContext.SaveChangesAsync();
     }
     catch (Exception e)
     {
         return(BadRequest("Error deleting record"));
     }
     return(Ok());
 }
Exemplo n.º 2
0
        public async Task <ActionResult <MotionPictures> > AddMovies(MotionPictures data)
        {
            MotionPictures toAdd = data;

            try
            {
                _dbContext.MotionPictures.Add(toAdd);
                await _dbContext.SaveChangesAsync();
            }
            catch (Exception e)
            {
                return(BadRequest("Unable to add movie!" + e.Message));
            }
            return(Ok(toAdd));
        }
Exemplo n.º 3
0
 public async Task <ActionResult <MotionPictures> > UpdateMovie(MotionPictures updatedMovie)
 {
     _dbContext.Entry(updatedMovie).State = EntityState.Modified;
     try
     {
         await _dbContext.SaveChangesAsync();
     }
     catch (Exception e)
     {
         if (!_dbContext.MotionPictures.Any(x => x.ID == updatedMovie.ID))
         {
             return(NotFound("No movie with ID " + updatedMovie.ID + " was found!"));
         }
         else
         {
             return(BadRequest("Error updating record"));
         }
     }
     return(Ok(updatedMovie));
 }