Exemplo n.º 1
0
        private void CreateNotif(SystemUser createdSystemUser, string notifType, int goalId, MentifiGoalProgress goalProgress)
        {
            var mentors = _businessToBusinessRepository.GetPagedList(
                predicate: a =>
                a.BusinessId2 == createdSystemUser.BusinessId && a.IsActive == true &&
                a.Business1.EduBusinessType != (int)EduBusinessType.Admin,
                include: a => a.Include(b => b.Business1).ThenInclude(b => b.SystemUser), pageSize: int.MaxValue).Items;
            MentifiGoalProgress lastGoalProgress = null;
            EduUniversity       eduUniversity    = null;
            Resource            resource         = null;
            var goal = _goalRepository.GetFirstOrDefault(predicate: a => a.MentifiGoalId == goalId,
                                                         include: a => a.Include(b => b.MentifiGoalProgress));

            if (goal != null)
            {
                lastGoalProgress = goal.MentifiGoalProgress.OrderByDescending(a => a.MentifiGoalProgressId)
                                   .FirstOrDefault();
                eduUniversity = _universityRepository.GetFirstOrDefault(predicate: a => a.BusinessId == (createdSystemUser.Business.UniversityId ?? createdSystemUser.BusinessId));
                resource      =
                    _resourceRepository.GetAll(
                        a => a.ResourceName == "Mentifi_Message_GoalProgressNotification_Subject").GetAwaiter().GetResult().FirstOrDefault();
            }
            foreach (var mentor in mentors)
            {
                var mentorSystemUser = mentor.Business1.SystemUser.FirstOrDefault();
                if (mentorSystemUser != null)
                {
                    var model = new Notification
                    {
                        SystemUserId     = mentorSystemUser.SystemUserId,
                        CreatedOn        = DateTime.Now,
                        CreatedBy        = createdSystemUser.SystemUserId,
                        SystemUserType   = Constant.USERTYPE_ADVISER,
                        NotificationType = notifType,
                        IsShowed         = false,
                        RegardingId      = createdSystemUser.SystemUserId,
                        Message          = string.Empty
                    };
                    _notificationRepository.Insert(model);

                    _busInstance.Publish(new NotificationAdded
                    {
                        NotificationType = notifType,
                        SystemUserID     = mentorSystemUser.SystemUserId,
                        SystemUserType   = Constant.USERTYPE_ADVISER,
                        CreatedOn        = DateTime.UtcNow,
                        IsShowed         = false,
                        CreatedBy        = createdSystemUser.SystemUserId,
                    });

                    if (goal != null)
                    {
                        _emailApi.AddGoalProgress(new EmailParam()
                        {
                            Recipient = new[]
                            {
                                mentorSystemUser.EmailAddress
                            },
                            SystemUserId = mentorSystemUser.SystemUserId,
                            Payload      = new[]
                            {
                                mentorSystemUser.FullName,
                                createdSystemUser.FullName,
                                goal.GoalDescription,
                                lastGoalProgress?.ProgressPercentage.ToString(),
                                goalProgress?.ProgressPercentage.ToString(),
                                goalProgress?.Reason,
                                _configuration["MentifiWebUrl"],
                                eduUniversity.UniversityNameAlias,
                                resource?.ResourceValue,
                                eduUniversity.MenteeAlias
                            }
                        }).GetAwaiter().GetResult();
                    }
                }
            }
        }
Exemplo n.º 2
0
        public async Task <string> ResourceMessage(Notification mobileAppNotification, SystemUser createdBy, EduUniversity university, SystemUser systemUser, bool isHtmlVersion = true)
        {
            Resource resource;
            var      labelSetCode  = "Mentifi";
            var      sb            = new StringBuilder();
            var      mentifiWebUrl = _configuration.GetSection("MentifiWebUrl").ToString();
            string   resourceName;

            switch (mobileAppNotification.NotificationType)
            {
            case Constant.NOTIFTYPE_NEXTACTIVITYSEQUENCE:
                //resource =
                //(await _resourceRepository.GetAll(a => a.ResourceName == labelSetCode + "_NotifNextActivitySequence")).First();
                //sb.Append(string.Format(resource.ResourceValue, mentifiWebUrl + "CRM/ShowMyActivity?q=" + SecurityUtility.Encrypt(mobileAppNotification.RegardingId.ToString())) + ";" + mobileAppNotification.CreatedOn.ToString("dd/MM/yyyy HH:mm") + ";" + createdBy?.FullName + ";" + mobileAppNotification.CreatedBy.ToString());
                return(isHtmlVersion
                        ? $"{createdBy?.FullName} has assigned you an <a href='{mentifiWebUrl + "CRM/ShowMyActivity?q=" + SecurityUtility.Encrypt(mobileAppNotification.RegardingId.ToString())}'>activity</a> ready to work on."
                        : $"{createdBy?.FullName} has assigned you an activity ready to work on.");

            case Constant.NOTIFTYPE_ASSIGNMENT:
                //resource =
                //(await _resourceRepository.GetAll(
                //    a => a.ResourceName == labelSetCode + "_NotifAssignment")).First();
                //sb.Append(string.Format(resource.ResourceValue, mentifiWebUrl + "CRM/ShowMyActivity?q=" + SecurityUtility.Encrypt(mobileAppNotification.RegardingId.ToString())) + ";" + mobileAppNotification.CreatedOn.ToString("dd/MM/yyyy HH:mm") + ";" + createdBy?.FullName + ";" + mobileAppNotification.CreatedBy.ToString());

                //break;
                return(isHtmlVersion
                        ? $"{createdBy?.FullName} has assigned you a new <a href='{mentifiWebUrl + "CRM/ShowMyActivity?q=" + SecurityUtility.Encrypt(mobileAppNotification.RegardingId.ToString())}'>activity</a>."
                        : $"{createdBy?.FullName} has assigned you a new activity.");

            case Constant.NOTIFTYPE_EDUCONNECT:
                resource =
                    (await _resourceRepository.GetAll(
                         a => a.ResourceName == labelSetCode + "_NotifBusinessJoin")).First();
                return(createdBy?.FullName + " " + resource.ResourceValue);

            case Constant.NOTIFTYPE_BUSINESSLINK:
                //resource =
                //(await _resourceRepository.GetAll(
                //    a => a.ResourceName == labelSetCode + "_NotifMessageBoardLink")).First();
                //sb.Append(createdBy?.FullName + " " + resource.ResourceValue);
                //break;
                return
                    (isHtmlVersion
                            ? $"{createdBy?.FullName} has sent you a <a href=\"{mentifiWebUrl}mentifi/network\">connection request</a>, communicate further in message board."
                            : $"{createdBy?.FullName} has sent you a connection request, communicate further in message board.");

            case Constant.NOTIFTYPE_MESSAGE:
                //resource =
                //(await _resourceRepository.GetAll(
                //    a => a.ResourceName == labelSetCode + "_NotifMessage")).First();
                //return string.Format(resource.ResourceValue, mentifiWebUrl + ");
                return(isHtmlVersion
                        ? $"{createdBy?.FullName} has sent you a <a href='{mentifiWebUrl}Message/ShowMessage?q=\"{SecurityUtility.Encrypt(mobileAppNotification.RegardingId.ToString())}\"'>hub message</a>."
                        : $"{createdBy?.FullName} has sent you a hub message.");

            case Constant.NOTIFTYPE_PRIVATEBULLETIN:
                //resource =
                //(await _resourceRepository.GetAll(
                //    a => a.ResourceName == labelSetCode + "_NotifPrivateBulletin")).First();
                //return createdBy?.FullName + " " + string.Format(resource.ResourceValue,
                //           mentifiWebUrl + "Bulletin/ShowBulletin?q=" +
                //           SecurityUtility.Encrypt(mobileAppNotification.RegardingId.ToString()));
                return(isHtmlVersion
                        ? $"{createdBy?.FullName} has shared a <a href='{0}'>private bulletin</a> with you."
                        : $"{createdBy?.FullName} has shared a private bulletin with you.");

            case Constant.NOTIFTYPE_PRIVATEBULLETINREPLY:
                //resource =
                //(await _resourceRepository.GetAll(
                //    a => a.ResourceName == labelSetCode + "_NotifPrivateBulletinReply")).First();
                //return createdBy?.FullName + " " + string.Format(resource.ResourceValue,
                //           mentifiWebUrl + "Bulletin/ShowBulletin?q=" +
                //           SecurityUtility.Encrypt(mobileAppNotification.RegardingId.ToString()));
                return(isHtmlVersion
                        ? $"{createdBy?.FullName} has replied to your <a href='{mentifiWebUrl}Bulletin/ShowBulletin?q=\"{SecurityUtility.Encrypt(mobileAppNotification.RegardingId.ToString())}\"'>private bulletin</a> post."
                        : $"{createdBy?.FullName} has replied to your private bulletin post");

            case Constant.NOTIFTYPE_NEWLYJOINED:
                resource =
                    (await _resourceRepository.GetAll(
                         a => a.ResourceName == labelSetCode + "_NotifNewlyJoined")).First();
                sb.Append(createdBy?.FullName + resource.ResourceValue);
                break;

            case Constant.NOTIFTYPE_BUSINESSJOIN:
                resource =
                    (await _resourceRepository.GetAll(
                         a => a.ResourceName == labelSetCode + "_NotifBusinessJoin")).First();
                sb.Append(createdBy?.FullName + " " + resource.ResourceValue);
                break;

            case Constant.NOTIFTYPE_LINKACTIVATE:
                resource =
                    (await _resourceRepository.GetAll(
                         a => a.ResourceName == labelSetCode + "_NotifLinkActivated")).First();
                return($"{createdBy?.FullName } {resource.ResourceValue}");

            case Constant.NOTIFTYPE_INVITEACTIVATE:
                resource =
                    (await _resourceRepository.GetAll(
                         a => a.ResourceName == labelSetCode + "_NotifInviteActive")).First();
                return(string.Format(resource.ResourceValue, university));

            case Constant.GlobalNotification.RecommendToConnect:
            case Constant.GlobalNotification.AcceptBusinessConnection:
                return($"{createdBy?.FullName} {mobileAppNotification.Message}");

            case Constant.MentifiNotification.ADDED_CONNECTION_BY_UNIVERSITY:
                //resource =
                //(await _resourceRepository.GetAll(
                //    a => a.ResourceName == "AddedConnectionWithLink")).First();
                var businessIdAdded = Convert.ToInt16(mobileAppNotification.Message);
                var businessAdded   = _businessRepository.GetFirstOrDefault(predicate: x => x.BusinessId == businessIdAdded, include: a => a.Include(b => b.SystemUser));
                var userAdded       = businessAdded.SystemUser.FirstOrDefault();
                //return string.Format(resource.ResourceValue, university.UniversityNameAlias, userAdded?.SystemUserId, userAdded?.FullName);
                return(isHtmlVersion
                        ? $"{university.UniversityNameAlias} admin, has added your connection with <b class='btn-show-profile-business' id='notif-name_{userAdded?.SystemUserId}'>{userAdded?.FullName}</b>"
                        : $"{university.UniversityNameAlias} admin, has added your connection with {userAdded?.FullName}");

            case Constant.MentifiNotification.ADDED_CONNECTION_BY_UNIVERSITY_REACHED_THE_LIMIT:
                var businessIdAddedReachedTheLimit = Convert.ToInt16(mobileAppNotification.Message);
                var businessAddedReachedTheLimit   = _businessRepository.GetFirstOrDefault(
                    predicate: a => a.BusinessId == businessIdAddedReachedTheLimit,
                    include: a => a.Include(b => b.SystemUser));
                var userAddedReachedTheLimit      = businessAddedReachedTheLimit.SystemUser.FirstOrDefault();
                var userAddedReachedTheLimitAlias = businessAddedReachedTheLimit.EduBusinessType == (int)EduBusinessType.Mentee ? university.MenteeAlias : university.MentorAlias;
                return(isHtmlVersion
                        ? $"{university.UniversityNameAlias} has added your connection with <b class='btn-show-profile-business' id='notif-name_{userAddedReachedTheLimit?.SystemUserId}'>{userAddedReachedTheLimit?.FullName}</b> & you just reached the {userAddedReachedTheLimitAlias} limit. Your remaining connect requests will be removed automatically."
                        : $"{university.UniversityNameAlias} has added your connection with {userAddedReachedTheLimit?.FullName} & you just reached the {userAddedReachedTheLimitAlias} limit. Your remaining connect requests will be removed automatically.");

            case Constant.MentifiNotification.REMOVE_CONNECTION_BY_UNIVERSITY:
                var businessIdRemoved = Convert.ToInt16(mobileAppNotification.Message);
                //resource =
                //(await _resourceRepository.GetAll(
                //    a => a.ResourceName == "RemoveConnectionWithLink")).First();
                var businessRemoved = _businessRepository.GetFirstOrDefault(predicate: x => x.BusinessId == businessIdRemoved, include: a => a.Include(b => b.SystemUser));
                var userRemoved     = businessRemoved.SystemUser.FirstOrDefault();
                //return string.Format(resource.ResourceValue, university.UniversityNameAlias, userRemoved?.SystemUserId, userRemoved?.FullName);
                return(isHtmlVersion
                        ? $"{university.UniversityNameAlias} has removed your connection request from <b class='btn-show-profile-business' id='notif-name_{userRemoved?.SystemUserId}'>{userRemoved?.FullName}</b>"
                        : $"{university.UniversityNameAlias} has removed your connection request from {userRemoved?.FullName}");

            case Constant.MentifiNotification.ACCEPT_CONNECTION_BY_UNIVERSITY:
                var businessIdAccepted = Convert.ToInt16(mobileAppNotification.Message);
                //resource =
                //(await _resourceRepository.GetAll(
                //    a => a.ResourceName == "AcceptConnectionWithLink")).First();
                var businessAccepted = _businessRepository.GetFirstOrDefault(predicate: x => x.BusinessId == businessIdAccepted, include: a => a.Include(b => b.SystemUser));
                var userAccepted     = businessAccepted.SystemUser.FirstOrDefault();

                //return string.Format(resource.ResourceValue, university.UniversityNameAlias, userAccepted?.SystemUserId, userAccepted?.FullName);
                return(isHtmlVersion
                        ? $"{university.UniversityNameAlias} has accepted your connection request from <b class='btn-show-profile-business' id='notif-name_{userAccepted?.SystemUserId}'>{userAccepted?.FullName}</b>"
                        : $"{university.UniversityNameAlias} has accepted your connection request from {userAccepted?.FullName}");

            case Constant.MentifiNotification.ACCEPT_CONNECTION_BY_UNIVERSITY_REACHED_THE_LIMIT:
                var businessIdAcceptedReachedTheLimit = Convert.ToInt16(mobileAppNotification.Message);

                var businessAcceptedReachedTheLimit = _businessRepository.GetFirstOrDefault(predicate: x => x.BusinessId == businessIdAcceptedReachedTheLimit, include: x => x.Include(y => y.SystemUser));
                var userAcceptedReachedTheLimit     = businessAcceptedReachedTheLimit.SystemUser.FirstOrDefault();

                var userAcceptedReachedTheLimitAlias = businessAcceptedReachedTheLimit.EduBusinessType == (int)EduBusinessType.Mentee ? university.MenteeAlias : university.MentorAlias;

                return
                    ($"{university.UniversityNameAlias} has accepted  your connection with <b class='btn-show-profile-business' id='notif-name_{userAcceptedReachedTheLimit?.SystemUserId}'>{userAcceptedReachedTheLimit?.FullName}</b> & you just reached the {userAcceptedReachedTheLimitAlias} limit. Your remaining connect requests will be removed automatically.");


            case Constant.MentifiNotification.REMOVE_CONNECTION_BY_MENTOR_OR_MENTEE_FROM:
                //resource =
                //(await _resourceRepository.GetAll(
                //    a => a.ResourceName == "RemoveConnectionFromWithLink")).First();
                var businessIdRemovedFrom = Convert.ToInt16(mobileAppNotification.Message);
                var userRemovedFrom       = _businessRepository.GetFirstOrDefault(predicate: x => x.BusinessId == businessIdRemovedFrom, include: x => x.Include(y => y.SystemUser))?.SystemUser.FirstOrDefault();
                //return createdBy?.FullName + " " + string.Format(resource.ResourceValue, userRemovedFrom?.SystemUserId, userRemovedFrom?.FullName);

                return(isHtmlVersion
                        ? $"{createdBy?.FullName} has removed the connection request from <b class='btn-show-profile-business' id='notif-name_{userRemovedFrom?.SystemUserId}'>{userRemovedFrom?.FullName}</b>"
                        : $"{createdBy?.FullName} has removed the connection request from {userRemovedFrom?.FullName}");

            case Constant.MentifiNotification.REMOVE_CONNECTION_BY_MENTOR_OR_MENTEE_TO:
                //resource =
                //(await _resourceRepository.GetAll(
                //    a => a.ResourceName == "RemoveConnectionToWithLink")).First();
                var businessIdRemovedTo = Convert.ToInt16(mobileAppNotification.Message);
                var userRemovedTo       = _businessRepository.GetFirstOrDefault(predicate: x => x.BusinessId == businessIdRemovedTo, include: x => x.Include(y => y.SystemUser))?.SystemUser.FirstOrDefault();
                //return createdBy?.FullName + " " + string.Format(resource.ResourceValue, userRemovedTo?.SystemUserId, userRemovedTo?.FullName);

                return(isHtmlVersion
                        ? $"{createdBy?.FullName} has removed the connection request from <b class='btn-show-profile-business' id='notif-name_{userRemovedTo?.SystemUserId}'>{userRemovedTo?.FullName}</b>"
                        : $"{createdBy?.FullName} has removed the connection request from {userRemovedTo?.FullName}");

            case Constant.NOTIFTYPE_EDUREJECT:
                resource =
                    (await _resourceRepository.GetAll(
                         a => a.ResourceName == labelSetCode + "_NotifLinkRejected")).First();
                return($"{createdBy?.FullName} {resource.ResourceValue}");

            case Constant.MentifiNotification.GOAL_ADDED:
                resourceName = isHtmlVersion ? "GoalCreatedWithLink" : "GoalCreated";
                if (isHtmlVersion)
                {
                    return
                        ($"{createdBy?.FullName} has just created a new goal.");
                }

                resource =
                    (await _resourceRepository.GetAll(
                         a => a.ResourceName == resourceName)).First();
                return(createdBy?.FullName + " " + string.Format(resource.ResourceValue, mobileAppNotification.RegardingId));

            case Constant.MentifiNotification.GOAL_EDITED:
                resourceName = isHtmlVersion ? "GoalEditedWithLink" : "GoalEdited";
                if (isHtmlVersion)
                {
                    return
                        ($"{createdBy?.FullName} has edited a goal.");
                }

                resource =
                    (await _resourceRepository.GetAll(
                         a => a.ResourceName == resourceName)).First();
                return(createdBy?.FullName + " " + string.Format(resource.ResourceValue, mobileAppNotification.RegardingId));

            case Constant.MentifiNotification.GOAL_PROGRESS_ADDED:
                resourceName = isHtmlVersion ? "GoalProgressCreatedWithLink" : "GoalProgressCreated";
                if (isHtmlVersion)
                {
                    return
                        ($"{createdBy?.FullName} has added a progress to his/her goal");
                }
                resource =
                    (await _resourceRepository.GetAll(
                         a => a.ResourceName == resourceName)).First();
                return(createdBy?.FullName + " " + string.Format(resource.ResourceValue, mobileAppNotification.RegardingId));

            case Constant.MentifiNotification.GOAL_REMOVED:
                resourceName = isHtmlVersion ? "GoalRemovedWithLink" : "GoalRemoved";
                if (isHtmlVersion)
                {
                    return
                        ($"{createdBy?.FullName} has removed a goal");
                }
                resource =
                    (await _resourceRepository.GetAll(
                         a => a.ResourceName == resourceName)).First();

                return(createdBy?.FullName + " " + string.Format(resource.ResourceValue, mobileAppNotification.RegardingId));

            case Constant.MentifiNotification.TASK_CREATED:
                resourceName = isHtmlVersion ? "TaskCreatedWithLink" : "TaskCreated";
                if (isHtmlVersion)
                {
                    return
                        ($"{createdBy?.FullName} has just added a new task.");
                }
                resource =
                    (await _resourceRepository.GetAll(
                         a => a.ResourceName == resourceName)).First();

                return(createdBy?.FullName + " " + string.Format(resource.ResourceValue, mobileAppNotification.RegardingId));

            case Constant.MentifiNotification.TASK_ASSIGNED:
                resourceName = isHtmlVersion ? "TaskAssignedWithLink" : "TaskAssigned";
                if (isHtmlVersion)
                {
                    return
                        ($"{createdBy?.FullName} has assigned you a task");
                }
                resource =
                    (await _resourceRepository.GetAll(
                         a => a.ResourceName == resourceName)).First();

                return(createdBy?.FullName + " " + string.Format(resource.ResourceValue, mobileAppNotification.RegardingId));

            case Constant.MentifiNotification.TASK_COMPLETED:
                resourceName = isHtmlVersion ? "TaskCompletedWithLink" : "TaskCompleted";
                if (isHtmlVersion)
                {
                    return
                        ($"{createdBy?.FullName} has completed a task.");
                }
                resource     =
                    resource =
                        (await _resourceRepository.GetAll(
                             a => a.ResourceName == resourceName)).First();

                return(createdBy?.FullName + " " + string.Format(resource.ResourceValue, mobileAppNotification.RegardingId));

            case Constant.MentifiNotification.TASK_CONVERTED_TO_PROJECT:
                resource =
                    (await _resourceRepository.GetAll(
                         a => a.ResourceName == "TaskConvertedToProject")).First();
                return(createdBy?.FullName + " " + resource.ResourceValue);

            case Constant.NOTIFTYPE_MENTIFIMESSAGEBOARDREQUESTSENT:
                return("You has sent a message through message board of connection request");

            case Constant.NOTIFTYPE_MENTIFIMESSAGEBOARD:
                return($"{createdBy?.FullName} has sent you a message through message board of connection request");
            }

            return(sb.ToString());
        }