Ejemplo n.º 1
0
        /// <summary>
        /// Stage A.1.1: Send not targeted entity to building administrators
        /// </summary>
        /// <param name="createdentity"></param>
        /// <returns></returns>
        private async Task SendNotificationsToAdmins(SomeModelOne createdentity)
        {
            var buildingId             = (await somewhatRepositoryOne.getBuildingIdByApartId(createdentity.apartId)).buildingId;
            var adminMask              = AccessMaskHelper.BuildMask(sAdmin: true, admin: true);
            var adminsWithNotification = await getUsersWithEnabledNotificationsInSomeScope(buildingId, adminMask);

            adminsWithNotification.AsParallel().ForAll(user => sendentityCreatedNotification(createdentity, buildingId, user));
        }
Ejemplo n.º 2
0
        private void SendentityCreatedNotification(SomeModelOne createdentity, string someEntityBuildingId, IMongoEntity user)
        {
            var update = new UpdateModel()
            {
                updateType    = UpdateType.entityCreated,
                parentId      = createdentity._id,
                message       = $"New entity created: {createdentity.header}",
                buildingId    = buildingId,
                updateOwnerId = user._id
            };

            updateSenderProxy.sendNotificationsToCertainUserSync(update, null);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Stage B.1.3: Sending notifications / updates for rejected entity
 /// </summary>
 /// <param name="updatedentity"></param>
 /// <param name="buildingId"></param>
 /// <returns></returns>
 private async Task SendentityRejectedStatus(SomeModelOne updatedentity, string someEntityBuildingId)
 {
     var additionalMessage = (updatedentity.rejectionComment != null) ?
                             $" with message {updatedentity.rejectionComment}" : string.Empty;
     var update = new UpdateModel()
     {
         buildingId    = buildingId,
         updateOwnerId = updatedentity.authorId,
         updateType    = UpdateType.entitiestatusChanged,
         parentId      = updatedentity._id,
         message       = $"entity {updatedentity.header} was rejected{additionalMessage}"
     };
     await updateSenderProxy.sendNotificationsToCertainUserAsync(update, null);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Stage B.1.1: Sending entity is finished update
 /// </summary>
 /// <param name="updatedentity"></param>
 /// <param name="buildingId"></param>
 /// <returns></returns>
 private async Task SendentityFinishedStatus(SomeModelOne updatedentity, string someEntityBuildingId)
 {
     if (updatedentity.executerId == null)
     {
         logger.Fatal($"WTF, how entity w/o {nameof(updatedentity.executerId)} passed into `sendentityFinishedStatus`");
         return; // base thread should not be ended
     }
     var update = new UpdateModel()
     {
         buildingId    = buildingId,
         updateOwnerId = updatedentity.executerId,
         updateType    = UpdateType.entitiestatusChanged,
         parentId      = updatedentity._id,
         message       = $"entity {updatedentity.header} closed with mark {updatedentity.feedback.mark}"
     };
     await updateSenderProxy.sendNotificationsToCertainUserAsync(update, null);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Stage B.1.2: Sending entity in progress update (reviewed, assigned, closed)
        /// Author`s related notifications
        /// </summary>
        /// <param name="updatedentity"></param>
        /// <param name="buildingId"></param>
        /// <param name="isAssigned"></param>
        /// <returns></returns>
        private async Task SendentityInProgress(SomeModelOne updatedentity, string someEntityBuildingId, bool isAssigned = false)
        {
            string newStatus = "unknown";

            switch (updatedentity.status)
            {
            case SomeModelOne.entitiestatus.Reviewed:
                newStatus = "reviewed";
                break;

            case SomeModelOne.entitiestatus.Assigned:
                newStatus = "assigned";
                break;

            case SomeModelOne.entitiestatus.Closed:
                newStatus = "closed";
                break;

            default:
                logger.Warn($"Status {nameof(updatedentity.status)} is not supported `sendentityInProgress`");
                break;
            }
            var update = new UpdateModel()
            {
                buildingId    = buildingId,
                updateOwnerId = updatedentity.executerId,
                updateType    = UpdateType.entitiestatusChanged,
                parentId      = updatedentity._id,
                message       = $"entity {updatedentity.header} changed status to {newStatus}" // TODO: Translate
            };
            await updateSenderProxy.sendNotificationsToCertainUserAsync(update, null);

            if (isAssigned)
            {
                if (updatedentity.executerId == null)
                {
                    logger.Fatal($"`sendentityInProgress` isAssigned was true, but there is no executer",
                                 JsonConvert.SerializeObject(updatedentity, Formatting.Indented));
                    return;
                }
                update.updateType    = UpdateType.entityWasAssignedToYou;
                update.updateOwnerId = updatedentity.executerId; update.message = $"You was assigned to {updatedentity.header}";
                await updateSenderProxy.sendNotificationsToCertainUserAsync(update, null);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Stage A.1.2: Send targeted entity to staff which assigned to certain position
        /// </summary>
        /// <param name="createdentity"></param>
        /// <returns></returns>
        private async Task SendNotificationsToPositionsOwners(SomeModelOne createdentity)
        {
            if (createdentity.positionId == null)
            {
                logger.Fatal($"{nameof(SomeEntityCollectionWatcher)} wtf, impossible entity passed into func `sendNotificationsToPositionsOwners`");
                return;
            } // Thread should continue
            var users = await positionsRepository.getPersonalForCertainPosition(createdentity.positionId);

            var buildingId = (await somewhatRepositoryOne.getBuildingIdByApartId(createdentity.apartId)).buildingId;

            if (users.relatedPersonal.Length > 0)
            {
                var usersWithEnabledNotifications = await userRepository.filterUsersWithEnabledNotifications(
                    users.relatedPersonal, (long)Notifications.entities);

                usersWithEnabledNotifications.AsParallel().WithDegreeOfParallelism(4)
                .ForAll(user => sendentityCreatedNotification(createdentity, buildingId, user));
            }
        }