public async Task <ActionResult <CreationResult> > CreateVersionInfo(AppVersionData newAppVersion, int id = -1) { int appId = id == -1 ? (int)newAppVersion.AppID : id; AppVersion toAdd = new AppVersion { AppID = appId, Changelog = newAppVersion.Changelog, VresionName = newAppVersion.VresionName, VresionNumber = newAppVersion.VresionNumber, ReleaseDate = newAppVersion.ReleaseDate, ChannelID = newAppVersion.ChannelID }; _context.AppVersions.Add(toAdd); await _context.SaveChangesAsync(); _context.Entry(toAdd).Reference(x => x.Channel).Load(); _context.Entry(toAdd).Reference(x => x.App).Load(); Channel channel = toAdd.Channel; if (channel.ChannelName.ToLower() == "release") { App app = toAdd.App; if (app.Published) { await _notificationsHub.SendNotification("new version" + newAppVersion.VresionNumber + " of " + app.Name); } } return(new CreationResult { txt = "Done", ID = toAdd.ID + "" }); }
public async Task <HttpResponseMessage> CreateNotifications(NotificationDTO notify) { HttpResponseMessage responce; try { notify = await _notificationDataService.CreateNotification(notify); _logger.Info($"SendMailController.SendMail [notification.Id: {notify.Id} notification.Protocol: {notify.Protocol}]"); if (Enum.IsDefined(typeof(Protocol), notify.Protocol)) { switch ((Protocol)Enum.Parse(typeof(Protocol), notify.Protocol, true)) { case Protocol.Email: await _smtpService.SendAsync(notify.Receiver, notify.Body, notify.Channel); break; case Protocol.SignalR: await NotificationsHub.SendNotification(notify.Receiver, notify); break; } } responce = Request.CreateResponse(HttpStatusCode.OK, notify); } catch (Exception ex) { _logger.Error($"SendMailController.SendMail [mail.Id: {notify.Id}]", ex); responce = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } return(responce); }
public IActionResult Index() { Task.Factory.StartNew(async() => { while (true) { try { await _notificationsHub.SendNotification(DateTime.Now.ToShortDateString()); Thread.Sleep(2000); } catch (Exception ex) { } } }); return(NoContent()); }
public async Task <HttpResponseMessage> CreateNotification(NotificationDTO notification) { HttpResponseMessage responce; try { notification.Receiver = notification.Receiver?.FormatUserName(); notification = await _notificationDataService.CreateNotification(notification); _logger.Info($"NotificationController.CreateNotification [notification.Id: {notification.Id}]"); await NotificationsHub.SendNotification(notification.Receiver, notification); responce = Request.CreateResponse(HttpStatusCode.OK, notification); } catch (Exception ex) { _logger.Error($"NotificationController.CreateNotification [notification.Id: {notification.Id}]", ex); responce = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } return(responce); }