public async Task <ActionResult <Item> > AddItem([FromBody] Item item) { if (item == null) { return(BadRequest()); } var _item = _context.Items.Where(i => i.TaesaId == item.TaesaId).FirstOrDefault(); if (_item != null) { return(BadRequest(new { message = "Item já cadastrado." })); } item.FilterAttribute(); var user = _context.Users.Include("Notifications").Where(u => u.Email.Equals(item.Email)).FirstOrDefault(); if (user == null) { user = new User { Email = item.Email }; _context.Users.Add(user); _context.SaveChanges(); } item.UserId = user.Id; _context.Add(item); _context.SaveChanges(); // Enviar Notificação if (user.Notifications != null && user.Notifications.Count > 0) { var NotificationScheme = new NotificationScheme { Title = "Aprovador Taesa", Body = "Novo item cadastrado: " + item.Title, Data = item.GetItem(), Notifications = user.Notifications }; await _pushNotification.Send(NotificationScheme); } return(CreatedAtAction("GetItem", new { id = item.Id }, item)); }
public IActionResult SendNotification(PushNotificationViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var pushNotification = _pushNotification.Send(model.Title, model.Content, _configuration.GetValue <string>("PushNotification:AppId"), _configuration.GetValue <string>("PushNotification:RestApiKey")); if (pushNotification) { ViewData["SuccessMessage"] = Model.Resources.Common.PushNotificationSuccess; } else { ViewData["ErrorMessage"] = Model.Resources.Common.PushNotificationError; } return(View(model)); }