示例#1
0
        protected ActionResult CustomResponse(object result = null)
        {
            if (OperacaoValida())
            {
                _logger.Info(result);
                return(Ok(new
                {
                    success = true,
                    data = result,
                }));
            }

            var objReturnError = new
            {
                success = false,
                errors  = _notifier.GetNotifications().Select(n => n.Message)
            };

            _logger.Error(objReturnError);

            var firstNotification = _notifier.GetNotifications().First();

            if (firstNotification.ErrorType == Core.Enums.ETypeError.NotFound)
            {
                return(NotFound(objReturnError));
            }

            return(BadRequest(objReturnError));
        }
        public void Handle_ShouldAddANotification()
        {
            // Arrange
            var notification  = _notificationFixture.GetNotification();
            var notifications = _notifier.GetNotifications();

            // Act
            _notifier.Handle(notification);
            var result = notifications.Any(n => n.Equals(notification));

            // Assert
            result.Should().BeTrue();
        }
示例#3
0
 protected ActionResult CustomResponse(object obj = null)
 {
     if (OperationValid())
     {
         return(Ok(new
         {
             success = true,
             data = obj == null ? _notifier.GetNotifications().Select(n => n.Message) : obj
         }));
     }
     return(BadRequest(new
     {
         success = false,
         data = _notifier.GetNotifications().Select(n => n.Message)
     }));
 }
示例#4
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var notifications = await Task.FromResult(_notifier.GetNotifications());

            notifications.ForEach(x => ViewData.ModelState.AddModelError(string.Empty, x.Message));
            return(View());
        }
示例#5
0
        protected ActionResult CustomResponse(object result = null)
        {
            if (ValidOperation())
            {
                return(Ok(new
                {
                    success = true,
                    data = result,
                    alerts = _notifier.GetNotifications().Where(p => p.Type == MessageType.Alert).Select(n => n.Message)
                }));
            }

            return(BadRequest(new
            {
                success = false,
                errors = _notifier.GetNotifications().Where(p => p.Type == MessageType.Error).Select(n => n.Message)
            }));
        }
示例#6
0
        protected ActionResult CustomResponse(object result = null)
        {
            if (!IsOperationValid())
            {
                return(BadRequest(new { success = false, errors = _notifier.GetNotifications().Select(n => n.Message), data = result }));
            }

            return(Ok(new { success = true, data = result }));
        }
示例#7
0
        protected ActionResult CustomResponse(object result = null)
        {
            _logger.LogInformation("Call custom response");
            if (!IsValid())
            {
                _logger.LogInformation("Operation is invalid");
                return(BadRequest(_notifier.GetNotifications()));
            }

            return(Ok(result));
        }
        protected bool IsValid()
        {
            if (_notifier.HasNotifications())
            {
                foreach (var erro in _notifier.GetNotifications())
                {
                    _toastNotification.AddErrorToastMessage(erro.Message);
                }

                return(false);
            }

            return(true);
        }
示例#9
0
        protected ActionResult CustomResponse(object result = null)
        {
            if (IsValid())
            {
                return(Ok(new
                {
                    success = true
                }));
            }

            return(BadRequest(new ValidationProblemDetails(new Dictionary <string, string[]>
            {
                { "Mensagens", _notifier.GetNotifications().Select(x => x.Message).ToArray() }
            })));
        }
示例#10
0
        protected ActionResult ApiResponse(object result = null)
        {
            if (IsValid())
            {
                return(Ok(result));
            }

            ModelStateDictionary errors = new ModelStateDictionary();

            foreach (var notification in _notifier.GetNotifications())
            {
                errors.AddModelError(notification.Property, notification.Message);
            }

            return(BadRequest(new ValidationProblemDetails(errors)));
        }
示例#11
0
        public void Update_User_Not_Found()
        {
            User user = null;

            mockRepository.FindById(Arg.Any <string>()).Returns(user);

            var notification = new Notification("");

            mockNotifier.Handle(notification);
            var erros = mockNotifier.GetNotifications();

            mockNotifier.HasNotification().Returns(true);

            appService.Update("60259848d73bfsss5", Title, FirstName, LastName);

            Assert.True(mockNotifier.HasNotification());
        }
示例#12
0
        protected ActionResult CustomResponse(object result = null)
        {
            if (this.ValidOperation())
            {
                return(Ok
                       (
                           result
                       ));
            }

            return(BadRequest
                   (
                       new {
                errors = _notifier.GetNotifications().Select(n => n.Message)
            }
                   ));
        }
示例#13
0
        public void Get_User_Not_Found()
        {
            User user = null;

            mockRepository.FindOneAsync(Arg.Any <Expression <Func <User, bool> > >()).Returns(user);

            var notification = new Notification("");

            mockNotifier.Handle(notification);
            var erros = mockNotifier.GetNotifications();

            mockNotifier.HasNotification().Returns(true);

            appService.GetByEmail(Email_Invalido);

            Assert.True(mockNotifier.HasNotification());
        }
示例#14
0
 protected IActionResult CustomResponse(Object result = null)
 {
     if (ResponseValid())
     {
         return(Ok(new
         {
             success = true,
             data = result
         }));
     }
     else
     {
         return(BadRequest(new
         {
             errors = notifier.GetNotifications().Select(n => n.Message)
         }));
     }
 }
        protected ActionResult CustomResponse(object result = null)
        {
            if (ValidOperation())
            {
                return(Ok(new
                {
                    success = true,
                    data = result
                }));
            }



            return(NotFound(new
            {
                success = false,
                errors = _notifier.GetNotifications().Select(n => n.Message)
            }));
        }
示例#16
0
 protected ActionResult OkResult(object result = null)
 {
     if (HasNotification())
     {
         return(BadRequest(new
         {
             success = false,
             errors = _notifier.GetNotifications().Select(n => n.Message)
         }));
     }
     if (result != null)
     {
         return(Ok(new
         {
             Success = true,
             Data = result
         }));
     }
     return(Ok());
 }
示例#17
0
 public void GetNotifications(Action <LazuriteNotification[]> callback)
 {
     callback(Notifier.GetNotifications());
 }
示例#18
0
 public List <Notification> GetNotifications()
 {
     return(_notifier.GetNotifications());
 }