示例#1
0
        public void setUp()
        {
            reportSubmission = MockRepository.GenerateMock <ReportSubmission>();
            CargoRepository         cargoRepository         = new CargoRepositoryInMem();
            HandlingEventRepository handlingEventRepository = new HandlingEventRepositoryInMem();
            HandlingEventFactory    handlingEventFactory    = new HandlingEventFactory(cargoRepository,
                                                                                       new VoyageRepositoryInMem(),
                                                                                       new LocationRepositoryInMem());

            TrackingId         trackingId         = new TrackingId("ABC");
            RouteSpecification routeSpecification = new RouteSpecification(L.HONGKONG, L.ROTTERDAM, DateTime.Parse("2009-10-10"));
            Cargo cargo = new Cargo(trackingId, routeSpecification);

            cargoRepository.store(cargo);

            HandlingEvent handlingEvent = handlingEventFactory.createHandlingEvent(
                DateTime.Parse("2009-10-02"),
                trackingId,
                null,
                L.HONGKONG.UnLocode,
                HandlingActivityType.RECEIVE,
                new OperatorCode("ABCDE")
                );

            handlingEventRepository.store(handlingEvent);

            cargo.Handled(handlingEvent.Activity);

            reportPusher        = new ReportPusher(reportSubmission, cargoRepository, handlingEventRepository);
            eventSequenceNumber = handlingEvent.SequenceNumber;
        }
        public void setUp()
        {
            reportSubmission = MockRepository.GenerateMock<ReportSubmission>();
            CargoRepository cargoRepository = new CargoRepositoryInMem();
            HandlingEventRepository handlingEventRepository = new HandlingEventRepositoryInMem();
            HandlingEventFactory handlingEventFactory = new HandlingEventFactory(cargoRepository,
                new VoyageRepositoryInMem(),
                new LocationRepositoryInMem());

            TrackingId trackingId = new TrackingId("ABC");
            RouteSpecification routeSpecification = new RouteSpecification(L.HONGKONG, L.ROTTERDAM, DateTime.Parse("2009-10-10"));
            Cargo cargo = new Cargo(trackingId, routeSpecification);
            cargoRepository.store(cargo);

            HandlingEvent handlingEvent = handlingEventFactory.createHandlingEvent(
                DateTime.Parse("2009-10-02"),
                trackingId,
                null,
                L.HONGKONG.UnLocode,
                HandlingActivityType.RECEIVE,
                new OperatorCode("ABCDE")
                );
            handlingEventRepository.store(handlingEvent);

            cargo.Handled(handlingEvent.Activity);

            reportPusher = new ReportPusher(reportSubmission, cargoRepository, handlingEventRepository);
            eventSequenceNumber = handlingEvent.SequenceNumber;
        }
示例#3
0
 public ReportPusher(ReportSubmission reportSubmission,
                     CargoRepository cargoRepository,
                     HandlingEventRepository handlingEventRepository)
 {
     this.reportSubmission        = reportSubmission;
     this.cargoRepository         = cargoRepository;
     this.handlingEventRepository = handlingEventRepository;
 }
示例#4
0
 public ReportPusher(ReportSubmission reportSubmission,
                     CargoRepository cargoRepository,
                     HandlingEventRepository handlingEventRepository)
 {
     this.reportSubmission = reportSubmission;
     this.cargoRepository = cargoRepository;
     this.handlingEventRepository = handlingEventRepository;
 }
示例#5
0
        public Task ReportAsync(ReportSubmission <Reply> submission)
        {
            // Defer notifications for execution after request completes
            _deferredTaskManager.AddTask(async ctx =>
            {
                // Get users to notify
                var users = await _platoUserStore.QueryAsync()
                            .Select <UserQueryParams>(q =>
                {
                    q.RoleName.IsIn(new[]
                    {
                        DefaultRoles.Administrator,
                        DefaultRoles.Staff
                    });
                })
                            .ToList();

                // No users to notify
                if (users?.Data == null)
                {
                    return;
                }

                // If anonymous use bot as sender
                var from = submission.Who ??
                           await _platoUserStore.GetPlatoBotAsync();

                // Send notifications
                foreach (var user in users.Data)
                {
                    // Web notification
                    if (user.NotificationEnabled(_userNotificationTypeDefaults, WebNotifications.ReplyReport))
                    {
                        await _notificationManager.SendAsync(new Notification(WebNotifications.ReplyReport)
                        {
                            To   = user,
                            From = from
                        }, submission);
                    }

                    // Email notification
                    if (user.NotificationEnabled(_userNotificationTypeDefaults, EmailNotifications.ReplyReport))
                    {
                        await _notificationManager.SendAsync(new Notification(EmailNotifications.ReplyReport)
                        {
                            To = user
                        }, submission);
                    }
                }
            });

            return(Task.CompletedTask);
        }
示例#6
0
        public IActionResult SubmitReport([FromBody] ReportSubmission reportSubmission)
        {
            Entry       targetEntry = DatabaseHelpers.Context.QueryByDisplayID <Entry>(reportSubmission.EntryDisplayId);
            UserAccount currentUser = GetCurrentUser();

            if (currentUser.ID == targetEntry.Author.ID)
            {
                return(BadRequest("Reporting own posts is not allowed."));
            }

            DatabaseHelpers.Entries.ReportEntry(targetEntry, currentUser, reportSubmission.Reason);

            return(Ok());
        }