Exemple #1
0
        public void InspectAlert(Alert alert)
        {
            bool condionAns      = socialMediaManager.VerifyCondition(alert);
            int  notificationNmr = 1;

            if (condionAns == true)
            {
                AlertType type = alert.Type;
                if (type != AlertType.mail)
                {
                    //TODO controleer of notification al in database is opgenomen
                    if (!alertRepository.NotificationExists(alert.AlertId))
                    {
                        Notification notification = new Notification()
                        {
                            NotificationId = notificationNmr, DateTime = DateTime.Now, Alert = alert
                        };
                        alertRepository.CreateNotification(notification);
                        alert.Notifications.Add(notification);
                        //TODO klopt niet, moet een user wel als attribuut in Alert opgenomen worden?
                        alertRepository.UpdateAlert(alert);
                        notificationNmr++;
                    }
                }
                if (type != AlertType.notification)
                {
                    this.SendMail(alert);
                }
            }
        }
        private void CompareSentimentWithSelf(Alert alert)
        {
            double newSentiment = socialMediaRepository.ReadAverageSentimentFromItem(alert.Item, DateTime.Now, DateTime.Now.AddHours(-FREQUENTIE));
            double oldSentiment = socialMediaRepository.ReadAverageSentimentFromItem(alert.Item, DateTime.Now.AddHours(-FREQUENTIE), DateTime.Now.AddHours(-(FREQUENTIE * 2)));

            if (newSentiment >= oldSentiment * (alert.ConditionPerc / 100))
            {
                Notification n = new Notification()
                {
                    DateTime = DateTime.Now, Alert = alert
                };
                n.Content = String.Format("{0} wordt nu {1}% positiever gezien dan eerder", alert.Item.Name, alert.ConditionPerc);
                alertRepository.CreateNotification(n);
                alert.Notifications.Add(n);
                alertRepository.UpdateAlert(alert);
                SendAlert(alert, n);
            }
            ;
        }
        public async Task <IActionResult> AddAlert([FromBody] AlertData alData)
        {
            User user = await _auth.GetUser(this.User.Identity.Name);

            Permissions permissions = await _auth.GetPermissions(user.Id);

            if (permissions.AddAlert == false)
            {
                return(Unauthorized());
            }

            if (ModelState.IsValid)
            {
                //check if new or updating alert

                Alert alert = _repo.GetAlertByInvId(alData.AlertInvId).Result;

                if (alert == null)
                {
                    alert.Threshold = alData.Threshold;
                    //alert.DateUnder = alData.DateUnder;

                    var updatedAlert = await _repo.UpdateAlert(alert);
                }
                else //create a new alert
                {
                    var alertToCreate = new Alert
                    {
                        Threshold = alData.Threshold,
                        //DateUnder = alData.DateUnder,
                        DateUnder = DateTime.MinValue,
                        //DateOrdered = alData.DateOrdered,
                        DateOrdered = DateTime.MinValue,
                        //AlertOn = alData.AlertOn,
                        AlertOn = true,
                        //AlertTriggered = alData.AlertTriggered,
                        AlertTriggered = false,
                        AlertInvId     = alData.AlertInvId
                    };

                    //Create new alert
                    var createdAlert = await _repo.AddAlert(alertToCreate);

                    //Add Alert to Inv and Inv to Alert
                    alertToCreate.AlertInv = await _inv.SetAlert(alertToCreate);

                    //Update Alert
                    var updatedAlert = await _repo.UpdateAlert(alertToCreate);
                }

                //created at root status code
                return(StatusCode(201));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }