예제 #1
0
        public IActionResult GetVisitorOverview(Guid id)
        {
            try
            {
                VisitorManager  visitorMng = new VisitorManager();
                VisitorResource visitor    = visitorMng.GetRecordById(id).ToVisitorResource();

                var result = new VisitorOverviewResource(visitor);
                VisitorNotificationManager notificationsMng = new VisitorNotificationManager();
                var notifications = notificationsMng.GetRecordsByVisitorId(id);
                result.Notifications = notifications.Select(n => n.ToVisitorNotificationResource()).ToList();

                VisitManager visitMng = new VisitManager();
                var          visits   = visitMng.GetRecordsByVisitorId(id);
                result.Visits = visits.Select(v => v.ToVisitResource()).ToList();

                PositiveCaseManager positiveCasesMng = new PositiveCaseManager();
                var positiveCases = positiveCasesMng.GetRecordsByVisitorId(id);
                result.PositiveCases = positiveCases.Select(v => v.ToPositiveCaseResource()).ToList();

                return(Ok(result));
            }
            catch (EntityValidationException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch
            {
                return(Problem());
            }
        }
예제 #2
0
        public IActionResult GetPositiveCase(Guid id)
        {
            try
            {
                PositiveCaseManager        positiveCaseMng = new PositiveCaseManager();
                VisitManager               visitMng        = new VisitManager();
                VisitorNotificationManager notificationMng = new VisitorNotificationManager();
                var positiveCase = positiveCaseMng.GetRecordById(id).ToPositiveCaseResource();

                // load visitor name (needed for the autocomplete component)
                VisitorManager visitorMng = new VisitorManager();
                var            visitor    = visitorMng.GetRecordById(positiveCase.VisitorId);
                positiveCase.VisitorName = visitor.Name;

                #region Determine if all users with colliding visits were notified

                // Set date to the last minute of the day to include all the visits from that day on the retrieved visits
                DateTime visitDate = positiveCase.VisitDate.Date.AddHours(23).AddMinutes(59);
                var      positiveCaseVisitsBefore = visitMng.GetUserVisitsBeforeDate(positiveCase.VisitorId, visitDate, 2).ToList();

                // Get colliding visits
                var collidingVisits = visitMng.GetCollidingVisits(positiveCaseVisitsBefore);

                positiveCase.AllUsersNotified = true;

                foreach (var collidingVisit in collidingVisits)
                {
                    bool notificationSent = notificationMng.GetRecordsByVisitorId(collidingVisit.Visitor.Id).Any(v => v.PositiveCase.Id == id);
                    if (!notificationSent)
                    {
                        positiveCase.AllUsersNotified = false;
                        break;
                    }
                }

                #endregion

                return(Ok(positiveCase));
            }
            catch (EntityNotFoundException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch
            {
                return(Problem());
            }
        }
        public IActionResult Update(VisitorNotificationResource visitorNotification)
        {
            try
            {
                VisitorNotificationManager visitorNotificationMng = new VisitorNotificationManager();
                var visitorNotificationDb = visitorNotificationMng.GetRecordById(visitorNotification.Id);
                if (visitorNotificationDb == null)
                {
                    return(BadRequest("Invalid visitor notification id!"));
                }

                visitorNotificationDb.SentDate = visitorNotification.SentDate;

                if (visitorNotificationDb.Visitor.Id != visitorNotification.VisitorId)
                {
                    VisitorManager visitorMng = new VisitorManager();
                    Visitor        visitor    = visitorMng.GetRecordById(visitorNotification.VisitorId);
                    if (visitor == null)
                    {
                        return(BadRequest("Invalid visitor id!"));
                    }
                    visitorNotificationDb.Visitor = visitor;
                }

                if (visitorNotificationDb.PositiveCase.Id != visitorNotification.PositiveCaseId)
                {
                    PositiveCaseManager positiveCaseMng = new PositiveCaseManager();
                    PositiveCase        positiveCase    = positiveCaseMng.GetRecordById(visitorNotification.PositiveCaseId);
                    if (positiveCase == null)
                    {
                        return(BadRequest("Invalid positive case id!"));
                    }
                    visitorNotificationDb.PositiveCase = positiveCase;
                }

                visitorNotificationMng.Update(visitorNotificationDb);
                return(Ok());
            }
            catch (EntityValidationException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch
            {
                return(Problem());
            }
        }
예제 #4
0
        public IActionResult GetPositiveCaseOverview(Guid id)
        {
            try
            {
                PositiveCaseManager        positiveCaseMng = new PositiveCaseManager();
                VisitManager               visitMng        = new VisitManager();
                VisitorManager             visitorMng      = new VisitorManager();
                VisitorNotificationManager notificationMng = new VisitorNotificationManager();

                var positiveCase = positiveCaseMng.GetRecordById(id).ToPositiveCaseResource();
                var result       = new PositiveCaseOverviewResource(positiveCase);

                // load visitor name (needed for the autocomplete component)
                result.VisitorName = visitorMng.GetRecordById(positiveCase.VisitorId).Name;

                // Set date to the last minute of the day to include all the visits from that day on the retrieved visits
                result.VisitDate = result.VisitDate.Date.AddHours(23).AddMinutes(59);
                var positiveCaseVisitsBefore = visitMng.GetUserVisitsBeforeDate(result.VisitorId, result.VisitDate, 2).ToList();

                // Get colliding visits
                var collidingVisits = visitMng.GetCollidingVisits(positiveCaseVisitsBefore);


                foreach (var collidingVisit in collidingVisits)
                {
                    result.CollidingVisits.Add(new AffectedVisitsResource()
                    {
                        VisitId          = collidingVisit.Visitor.Id,
                        VisitDate        = collidingVisit.CheckIn,
                        NotificationSent = notificationMng.GetRecordsByVisitorId(collidingVisit.Visitor.Id).Any(v => v.PositiveCase.Id == id),
                        VisitorId        = collidingVisit.Visitor.Id,
                        VisitorName      = visitorMng.GetRecordById(collidingVisit.Visitor.Id).Name
                    });
                }
                result.AllUsersNotified = result.CollidingVisits.Any(c => !c.NotificationSent);

                return(Ok(result));
            }
            catch (EntityNotFoundException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                return(Problem(ex.Message));
            }
        }
 public IActionResult New(VisitorNotificationResource visitorNotification)
 {
     try
     {
         VisitorNotificationManager visitorNotificationMng = new VisitorNotificationManager();
         visitorNotificationMng.Insert(visitorNotification.ToVisitorNotification());
         return(Ok());
     }
     catch (EntityValidationException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch
     {
         return(Problem());
     }
 }
        public IActionResult Delete(Guid id)
        {
            try
            {
                VisitorNotificationManager visitorNotificationMng = new VisitorNotificationManager();
                var visitorNotificationDb = visitorNotificationMng.GetRecordById(id);

                if (visitorNotificationDb == null)
                {
                    return(BadRequest("Invalid positive case id!"));
                }

                visitorNotificationMng.Delete(id);
                return(Ok());
            }
            catch (EntityValidationException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch
            {
                return(Problem());
            }
        }