Пример #1
0
        public async Task <IActionResult> PutConnections([FromBody] Connections connections)
        {
            int id = connections.Id;

            if (!_context.Connections.Any(e => e.Id == id))
            {
                BadRequest(new { message = "Can't find the connection to update" });
            }

            if (_context.Connections.Any(e => e.ConnectionName == connections.ConnectionName && e.Id != connections.Id))
            {
                return(BadRequest(new { message = "The connection name is already existed!" }));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> PutUsers([FromBody] Users users)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_context.Users.Any(e => e.Id == users.Id))
            {
                return(BadRequest(new { message = "Can't find the user to update" }));
            }

            if (_context.Users.Any(e => e.Username == users.Username && e.Id != users.Id))
            {
                return(BadRequest(new { message = "The username is already existed!" }));
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UsersExists(users.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(new { message = "Updated successfully!" }));
        }