Esempio n. 1
0
        public async Task <IActionResult> PutTransaction(int id, Transaction transaction)
        {
            if (id != transaction.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <ActionResult <User> > Register(User user)
        {
            if (_context.User.Where(x => x.Username == user.Username).Any())
            {
                return(Conflict());
            }
            string hash, salt;

            new SaltedHash().GetHashAndSaltString(user.Password, out hash, out salt);
            user.Password = hash;
            user.Salt     = salt;
            user.Role     = "registered";
            _context.User.Add(user);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetUser", "Users", new { id = user.Id }, user));
        }