public async Task <Example> UpdateExample(Guid id, Example request)
        {
            var oldExample = await _exampleRepository.GetByIdAsync(id);

            if (oldExample == null)
            {
                await _notifications.AddNotificationAsync(new DomainNotification("ExampleBusiness", "Example não encontrado."));

                return(await Task.FromResult(request));
            }

            var newExample = Example.ExampleFactory.UpdateExample(oldExample, request.Descricao);

            if (!await IsValidAsync(newExample))
            {
                return(await Task.FromResult(request));
            }

            _exampleRepository.Update(newExample);


            if (await Commit())
            {
                return(await Task.FromResult(newExample));
            }

            return(request);
        }
Ejemplo n.º 2
0
        protected async Task <bool> Commit()
        {
            if (await _notifications.HasNotificationsAsync())
            {
                return(false);
            }
            if (await _uow.Commit())
            {
                return(true);
            }

            await _notifications.AddNotificationAsync(new DomainNotification("Commit", "Ocorreu um erro ao salvar os dados no banco"));

            return(false);
        }
 protected async Task NotifyError(string key, string value)
 {
     await _notifications.AddNotificationAsync(new DomainNotification(key, value));
 }