protected IActionResult Error(string message = null, HttpStatusCode statusCode = HttpStatusCode.InternalServerError) { if (IsValidOperation()) { if (message == null) { return(new ObjectResult(null) { StatusCode = (int)statusCode }); } else { return(new ObjectResult(new { errors = message }) { StatusCode = (int)statusCode }); } } else { var result = new ObjectResult(new { errors = _notifications.GetNotifications().Select(n => n.Value) }) { StatusCode = (int)HttpStatusCode.InternalServerError }; return(result); } }
protected new IActionResult BadRequest() { var response = new ContentResult { StatusCode = (int)HttpStatusCode.BadRequest, Content = JsonConvert.SerializeObject( new { Notifications = _notification.GetNotifications() } ) }; return(response); }
protected string RetornaNotificacaoFormatada() { string result = ""; _notification.GetNotifications().ForEach(a => result += $"<p> {a.Value} </p>"); return(result); }
public async Task <IViewComponentResult> InvokeAsync() { var notifications = await Task.FromResult(_notifications.GetNotifications()); notifications.ForEach(n => ViewData.ModelState.AddModelError(string.Empty, n.Value)); return(View()); }
private void Validar() { foreach (var error in Notification.GetNotifications()) { AddError(error.Value); } }
protected IActionResult Response <T>(T result) { if (ValidOperation()) { return(Ok(new ReturnContentJson <T>(true, result))); } var instance = Activator.CreateInstance <T>(); return(BadRequest(new ReturnContentJson <T>(false, instance, Notifications.GetNotifications().Select(n => n.Value)))); }
public async Task <Result> Return() { var result = Result.Ok; if (_notifications.HasNotificationsWithKey("Error")) { result = Result.Error; } result.AddMessages(_notifications.GetNotifications()); return(await Task.FromResult(result)); }
public Result Return() { var result = Result.Ok; if (_notifications.HasNotificationsWithKey("Error")) { result = Result.Error; } result.AddMessages(_notifications.GetNotifications()); return(result); }
protected IActionResult GetResponse(object result) { if (_notifications != null && _notifications.HasNotifications()) { return(BadRequest(_notifications.GetNotifications().Select(n => n.Value))); } if (result == null) { return(Ok()); } return(Ok(result)); }
protected string ObterMensagensNotificacoesDominio() { var notificacoes = _notifications.GetNotifications(); string mensagens = string.Empty; if (notificacoes != null) { for (int i = 0; i < notificacoes.Count; i++) { if (i == 0) { mensagens = notificacoes[i].Valor; } else { mensagens += "<br />" + notificacoes[i].Valor; } } } return(mensagens); }
protected new IActionResult Response(object result = null) { if (OperacaoValida()) { return(Ok(new { success = true, data = result })); } return(BadRequest(new { success = false, errors = _notifications.GetNotifications().Select(n => n.Value) })); }
public new IActionResult Response(object obj = null) { if (!OperationIsValid()) { return(BadRequest(new { success = false, errors = _domainNotificationHandler.GetNotifications().Select(n => n.Value) })); } return(Ok(new { success = true, data = obj })); }
protected new IActionResult Response(object result = null) { if (OperacaoValida()) { return(Ok( new { success = true, data = result })); } //Todas notificações com key "-1", não podem ser apresentadas ao usuário, apenas logadas. return(Ok(new { success = false, errors = _notifications.GetNotifications().Where(n => n.Key != "-1").Select(n => n.Value) })); }
//CreateReponse always check for Domain Notifications (errors) before send results //This will secure that the application never will deliver wrong or incomplete data //DomainNotificationHandler notifications are filled on the AppServices operations protected IActionResult CreateResponse(object result = null, HttpStatusCode statusCode = HttpStatusCode.OK) { if (_domainNotificationHandler.HasNotifications()) { return(BadRequest(new { success = false, result = "Ocorreu um erro ao retornar os resultados.", data = _domainNotificationHandler .GetNotifications() })); } return(StatusCode((int)statusCode, new { success = true, result = "A operação foi concluída com sucesso.", data = result })); }
protected IActionResult CreateResponse(object result = null, HttpStatusCode statusCode = HttpStatusCode.OK) { if (_domainNotificationHandler.HasNotifications()) { _logger.LogWarning("Retornando resposta do Controller: BadRequest devido à {notifications}.", _domainNotificationHandler.GetNotifications()); return(BadRequest(new { success = false, result = "Ocorreu um erro ao retornar os resultados.", data = _domainNotificationHandler .GetNotifications() })); } _logger.LogInformation("Retornando resposta do Controller: Operação concluída com sucesso, dados retornados: {data}.", result); return(StatusCode((int)statusCode, new { success = true, result = "A operação foi concluída com sucesso.", data = result })); }
public IViewComponentResult Invoke() { var notificationJson = TempData["SuccessNotification"]; if (notificationJson != null) { var successNotification = JsonConvert.DeserializeObject <CommandSuccessNotification>(notificationJson.ToString(), new JsonSerializerSettings { Converters = new List <JsonConverter> { new SuccessNotificationJsonConverter() } }); if (successNotification != null) { _domainNotificationHandler.AddNotification(successNotification); } } var notifications = _domainNotificationHandler.GetNotifications(); return(View(notifications)); }
public List <DomainNotification> GetNotifications() { return(_notifications.GetNotifications()); }
private string CriarMensagemDeNotificacaoCustomizada(IDomainNotificationHandler notificacaoDeDominio) { var notificacaoes = notificacaoDeDominio.GetNotifications().Select(_ => _.Value); return(JsonConvert.SerializeObject(notificacaoes)); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var user = new IdentityUser { UserName = Input.Email, Email = Input.Email }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { await _userManager.AddClaimAsync(user, new Claim("Eventos", "Ler")); await _userManager.AddClaimAsync(user, new Claim("Eventos", "Gravar")); var organizador = new OrganizadorViewModel { Id = Guid.Parse(user.Id), Email = user.Email, Nome = Input.Nome, CPF = Input.CPF }; _organizadorAppService.Registrar(organizador); if (!OperacaoValida()) { await _userManager.DeleteAsync(user); foreach (var error in _notifications.GetNotifications()) { ModelState.AddModelError(string.Empty, error.Value); } return(Page()); } _logger.LogInformation("O usuário criou uma nova conta com senha."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirme seu e-mail", $"Por favor, confirme sua conta <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public List <DomainNotification> GetInMemoryBusNotifications() { return(_dnh.GetNotifications()); }
private object NotificationsFormated() { return(_notifications.GetNotifications().Select(n => $"{n.Key} : {n.Value}")); }