Exemplo n.º 1
0
        public async Task <IActionResult> PutVote([FromRoute] int id, [FromBody] Vote vote)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != vote.UserId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> UpdatePassword([FromRoute] int id, [FromBody] User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var currentUser = _context.Users.SingleOrDefault(u => u.Name == User.Identity.Name);

            if (currentUser.Id != id)
            {
                return(BadRequest("Tu ne peux update que ton propre password"));
            }

            currentUser.Password = user.Password;

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

            await _context.SaveChangesAsync();

            return(NoContent());
        }