Exemple #1
0
        public AlertTest()
        {
            //mock setup
            alertMock  = new Mock <IRedAlert>();
            alertsMock = new List <IRedAlert> {
                alertMock.Object
            };
            addAlertMock    = new Mock <IAddAlert>();
            updateAlertMock = new Mock <IUpdateAlert>();
            redAlert        = new RedAlert();
            alerts          = new List <RedAlert>();
            //viewmodels mock setup
            alertViewModelMock  = new Mock <IAlertViewModel>();
            alertsViewModelMock = new List <IAlertViewModel>();

            //sample models
            addAlert = new AddAlert {
                vehicleId = 1, time = DateTime.Now
            };
            updateAlert = new UpdateAlert {
                vehicleId = 34, time = DateTime.Now
            };

            //controller setup

            _logger = new Mock <ILogger <RedAlertController> >();

            mockRepo = new Mock <IRepositoryWrapper>();

            var allAlerts = GetAlerts();

            alertController = new RedAlertController(_logger.Object, mockRepo.Object);
        }
Exemple #2
0
 public static void IWantToUpdateAlert(AlertsModel Alert)
 {
     LastAlert             = new AlertsModel();
     LastAlert.Activity    = Alert.Activity;
     LastAlert.Time        = Alert.Time;
     LastAlert.Date        = Alert.Date;
     LastAlert.Information = Alert.Information;
     LastAlert.No          = Alert.No;
     UpdateAlert?.Invoke(typeof(GlobalResources), EventArgs.Empty);
 }
        public IHttpActionResult updateAlert(UpdateAlert a)
        {
            a.Start_Time = DateTime.Now;
            if (a.OriginAlert == null)
            {
                a.OriginAlert = DataContext.Alerts.Include("Contacts").First(x => x.AlertId == a.OriginAlertRefId);
            }
            AlertStatus type;

            if (a.Status == "UPDATE" || a.Status == "UPDATED")
            {
                type = AlertStatus.Updated;
            }
            else if (a.Status == "RESOLVED")
            {
                type = AlertStatus.Complete;
            }
            else
            {
                type = AlertStatus.Ongoing; //should not be hit typically, error handling
            }
            DataContext.UpdateAlerts.Add(a);
            DataContext.SaveChanges();
            //saving the changes will have the context assign the new update its id
            a.OriginAlert.UpdateId = a.UpdateId;
            DataContext.SaveChanges();
            var contacts = a.getContacts().ToList();
            int count    = SendNotifications(a.getContacts().ToList(), a);


            a.OriginAlert.Status = type;

            DataContext.SaveChanges(); //changes the alert status if it was changed

            //Adds this activity to action log
            if (a.Status == "UPDATED")
            {
                var activity = new Activity(a, Module.Updated_Alert);
                DataContext.Activities.Add(activity);
                DataContext.SaveChanges();
            }
            else if (a.Status == "RESOLVED")
            {
                var activity = new Activity(a, Module.Resolved_Alert);
                DataContext.Activities.Add(activity);
                DataContext.SaveChanges();
            }

            return(Ok(count));
        }
Exemple #4
0
        public ActionResult <RedAlertViewModel> Put(int id, [FromBody] UpdateAlert alert)
        {
            var alertToUpdate = repository.Alerts.FindByCondition(c => c.Id == id).FirstOrDefault();

            //  dbContext.Entry(alertToUpdate).Reload();
            if (alertToUpdate == null)
            {
                _logger.LogWarning($"Alert with ID {id} not found.");
                return(NotFound($"Alert with ID {id} not found."));
            }

            alertToUpdate.vehicleId = alert.vehicleId;
            alertToUpdate.time      = alert.time;
            var updatedAlert = repository.Alerts.Update(alertToUpdate);

            repository.Save();

            var vehiclesInAlert     = repository.Alerts.FindByCondition(c => c.Id == id).Select(c => c.vehicleId).ToList();
            var alertFoundViewModel = new RedAlertViewModel {
                RedAlert = alertToUpdate, Vehicles = new List <Vehicle>()
            };

            return(alertFoundViewModel);
        }
 private void OnUpdateAlert(PointL position)
 {
     UpdateAlert?.Invoke(position);
 }
        public IHttpActionResult getUpdateById(int id)
        {
            UpdateAlert a = DataContext.UpdateAlerts.Find(id);

            return(Ok(a));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="toEmail"> Contact Email Address</param>
        /// <param name="subj"> Subject of the Email</param>
        /// <param name="msg"> Body of the Email</param>
        /// <param name="fullName"> concat First and Last name to be something like "Adam Perry" </param>
        /// <param name="a"> the alert object that is being used...to update the status and get image name</param>
        /// <param name="statusType"> to know what to make the status....just past the string "UPDATE" if status needs to be update....etc</param>
        /// <returns></returns>

        public int SendNotifications(List <Capstone_Project_v1.Models.Contact> contacts, UpdateAlert a)
        {
            //contacts, list of contacts to notify
            //a, the original alert
            //type, the alertstatus to set when complete

            if (a.OriginAlert == null)
            {
                a.OriginAlert = DataContext.Alerts.Find(a.OriginAlertRefId);
            }

            int count = 0;

            foreach (var c in contacts)
            {
                string preference = c.ServiceType;
                string imageName  = a.OriginAlert.ImageName;
                bool   email      = false;
                bool   text       = false;

                if (preference == "email" || preference == "both")
                {
                    email = SendEmail(c.Email, a.Title, a.Description, c.FirstName + " " + c.LastName, imageName);
                }


                // Uncomment the lines below to enable sending text messages if it was selected for the contact
                if (preference == "mobile" || preference == "both")
                {
                    text = SendText(c.PhoneNumber, a.Title + Environment.NewLine + a.Description);
                }

                if (email || text)
                {
                    count++;
                }
            }

            return(count);
        }