コード例 #1
0
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #2
0
        public async Task CreateBatch(Lote input)
        {
            foreach (var item in input.Logs)
            {
                var user = _context.User.FirstOrDefault(x => x.IP == item.IP);
                if (user != null)
                {
                    item.UserId = user.Id;
                }
                else
                {
                    user      = new User();
                    user.IP   = item.IP;
                    user.Nome = "User IP " + item.IP;
                    _context.User.Add(user);
                    await _context.SaveChangesAsync();

                    item.UserId = user.Id;
                }
                _context.Log.Add(item);
            }

            await _context.SaveChangesAsync();
        }