public async Task UpdateAsync(UpdateProductDto input) { // Remover primeiro as existentes var productDb = _productManager.GetProductByID(input.Id); foreach (var provider in productDb.Providers.ToList()) { productDb.Providers.Remove(provider); } foreach (var providerId in input.ProviderIds) { var providerDb = _providerManager.GetProviderByID(providerId); productDb.Providers.Add(providerDb); } // Se o estoque mudou, cria uma movimentação if (productDb.Stock != input.Stock) { var userId = 1; if (AbpSession.UserId != null) { userId = unchecked ((int)AbpSession.UserId); } User user = await _userManager.FindByIdAsync(userId); var movement = new Movement(); movement.Product = productDb; movement.User = user; movement.PreviousQtd = productDb.Stock; movement.CurrentQtd = input.Stock; // Se o estoque aumentou, cria uma movimentação positiva if (productDb.Stock > input.Stock) { movement.Signal = "-"; } else { movement.Signal = "+"; } await _movementManager.Create(movement); } productDb.Name = input.Name; productDb.Description = input.Description; productDb.Brand = input.Brand; productDb.EntryDate = input.EntryDate; productDb.ExpirationDate = input.ExpirationDate; productDb.Value = input.Value; productDb.Stock = input.Stock; _productManager.Update(productDb); }