예제 #1
0
        public Category Update(UpdateCmd command)
        {
            Category result = null;

            if (command.IsValid())
            {
                result = _categoryRepository.GetById(command.Id);

                if (!_categoryRepository.Notification.HasNotifications)
                {
                    command.Apply(ref result);
                    _categoryRepository.Add(result);
                }

                if (_categoryRepository.Notification.HasNotifications)
                {
                    Notification.AddNotifications(_categoryRepository.Notification.Notifications);
                }
            }
            else
            {
                command.Undo(ref result);
                Notification.AddNotifications(command.Validation);
            }

            return(result);
        }
예제 #2
0
        public void Delete(DeleteCmd command)
        {
            Notification.Clear();

            if (command.IsValid())
            {
                IEnumerable <Category> results = _categoryRepository.Filter(new FilterCmd()
                {
                    Category = command.Id
                });

                if (Notification.IsValid())
                {
                    foreach (Category item in results)
                    {
                        _categoryRepository.Remove(item);
                    }
                }

                if (_categoryRepository.Notification.HasNotifications)
                {
                    Notification.AddNotifications(_categoryRepository.Notification.Notifications);
                }
            }
            else
            {
                Notification.AddNotifications(command.Validation);
            }
        }
        public async override Task <TwoFactAuth> Handle(Account request, CancellationToken cancellationToken)
        {
            var result = await _validator.ValidateAsync(request);

            if (!result.IsValid)
            {
                Notification.AddNotifications(result);
                return(default);
예제 #4
0
        public void AdicionaNotificacaoManual()
        {
            Notification Test = new Notification();

            Test.AddNotifications("oi");
            Assert.AreEqual("oi", Test.Notifications.FirstOrDefault());
            Assert.AreEqual(1, Test.GetNumberOfNotifications);
        }
예제 #5
0
        public void RecebendoReferenciaNula()
        {
            Notification Test = new Notification();
            Notification err  = null;

            Test.AddNotifications(err);
            Assert.AreEqual(0, Test.GetNumberOfNotifications);
        }
예제 #6
0
        public void ValidaAdicaoNotificacaoDeOutraNotificacao()
        {
            Notification Test         = new Notification();
            String       ErroMessagem = "Numero fora de intervalo";

            Test.ValidItsBetween(5, 0, 5, ErroMessagem);
            Notification Test2 = new Notification();

            Test2.AddNotifications(Test);
            Assert.AreEqual(0, Test2.GetNumberOfNotifications);
            Test.ValidItsBetween(6, -5, 5, ErroMessagem);
            Test2.AddNotifications(Test);
            Assert.AreEqual(1, Test2.GetNumberOfNotifications);
            Assert.AreEqual(false, Test2.ItsValid);
            Assert.AreEqual(false, Test.ItsValid);
            Test2.AddNotifications("teste");
            Assert.AreEqual(2, Test2.GetNumberOfNotifications);
        }
예제 #7
0
        protected bool Validate(IValidation validate)
        {
            bool result = validate.IsValid();

            Validation = validate.Validation;
            Notification.AddNotifications(validate.Validation);

            return(result);
        }
예제 #8
0
        public async override Task <User> Handle(RegisterUser request, CancellationToken cancellationToken)
        {
            var user = Mapper.Map(request).ToANew <User>();

            var result = await _validator.ValidateAsync(user);

            if (!result.IsValid)
            {
                Notification.AddNotifications(result);
                return(default);
예제 #9
0
        public IEnumerable <Category> Filter(FilterCmd command)
        {
            Notification.Clear();
            IEnumerable <Category> results = new List <Category>();

            if (command.IsValid())
            {
                results = _categoryRepository.Filter(command);

                if (Notification.HasNotifications)
                {
                    Notification.AddNotifications(_categoryRepository.Notification.Notifications);
                }
            }
            else
            {
                Notification.AddNotifications(command.Validation);
            }

            return(results);
        }
예제 #10
0
        public Category Insert(InsertCmd command)
        {
            Category result = null;

            if (command.IsValid())
            {
                command.Apply(ref result);
                _categoryRepository.Add(result);

                if (_categoryRepository.Notification.HasNotifications)
                {
                    Notification.AddNotifications(_categoryRepository.Notification.Notifications);
                }
            }
            else
            {
                command.Undo(ref result);
                Notification.AddNotifications(command.Validation);
            }

            return(result);
        }