Ejemplo n.º 1
0
        public async Task <IActionResult> PutWatchList([FromRoute] int id, [FromBody] WatchList watchList)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != watchList.WatchId)
            {
                return(BadRequest());
            }

            _context.Entry(watchList).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WatchListExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PutPopularMovies([FromRoute] int id, [FromBody] PopularMovies popularMovies)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != popularMovies.Id)
            {
                return(BadRequest());
            }

            _context.Entry(popularMovies).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PopularMoviesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> PostComments([FromBody] Comments comments)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Comments.AddAsync(comments);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetComments", new { id = comments.CommentId }, comments));
        }
Ejemplo n.º 4
0
        // This method is used to register the users
        public async Task <Users> Register(Users users, string password)
        {
            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            users.PasswordHash = Convert.ToBase64String(passwordHash);
            users.PasswordSalt = Convert.ToBase64String(passwordSalt);

            //save into database
            await _context.Users.AddAsync(users);

            await _context.SaveChangesAsync();

            return(users);
        }
Ejemplo n.º 5
0
 public async Task <bool> SaveAllAsync()
 {
     return(await _context.SaveChangesAsync() > 0);
 }