예제 #1
0
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.IdUser)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutChannel(int id, DTO.ChannelDTO dto)
        {
            var channel = await _context.Channels.FindAsync(id);

            if (channel == null)
            {
                return(NotFound());
            }

            if (channel.IdUser != int.Parse(User.Identity.Name))
            {
                return(Forbid());
            }

            if (id != channel.IdChannel)
            {
                return(BadRequest());
            }

            channel.Name    = dto.Channel;
            channel.Link    = dto.Link;
            channel.Visible = dto.Visible;

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutFavorite(int id, DTO.FavoriteDTO dto)
        {
            var favorite = await _context.Favorites.FindAsync(id);

            if (favorite == null)
            {
                return(NotFound());
            }

            if (id != favorite.IdFavorite)
            {
                return(BadRequest());
            }

            favorite.Link  = dto.Link;
            favorite.Title = dto.Title;

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

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

            return(NoContent());
        }