/// <summary>
        /// Saves keys
        /// </summary>
        private void OnSaveCommand()
        {
            // check app sid length
            if (this.AppSidText.Length != 36)
            {
                DialogManager.ShowErrorDialog("Incorrect APP SID length! APP SID should be 36 symbols length.");
                return;
            }

            // check app key length
            if (this.AppKeyText.Length != 32)
            {
                DialogManager.ShowErrorDialog("Incorrect APP KEY length! APP KEY should be 32 symbols length.");
                return;
            }

            // update keys to provide new values
            CoreApi.UpdateKeys(this.AppKeyText, this.AppSidText);

            // encrypt keys and save in settings
            byte[] encryptedAppKey = SecurityUtility.Encrypt(Encoding.UTF8.GetBytes(this.AppKeyText));
            byte[] encryptedAppSid = SecurityUtility.Encrypt(Encoding.UTF8.GetBytes(this.AppSidText));
            UserSettingsUtility.SaveCredentials(encryptedAppKey, encryptedAppSid);

            this.view.Close();
        }
Beispiel #2
0
        public ActionResult UpdateAdv()
        {
            var ids   = Request.Form["AdvId"];
            int advId = int.Parse(ids);
            var adv   = db.AdvInfo.First(p => p.AdvId == advId);

            if (Request.Form["hidRefuse"] != "1")
            {
                foreach (var key in Request.Form.AllKeys)
                {
                    if (key.Contains("rward|"))
                    {
                        var       keyInfo   = key.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                        AdvReward advReward = new AdvReward();
                        advReward.AdvId        = advId;
                        advReward.AdvRewardId  = int.Parse(keyInfo[1]);
                        advReward.RewardTypeId = int.Parse(keyInfo[2]);
                        advReward.AdvRewardUrl = Request.Form[key];
                        db.AdvReward.Attach(advReward);
                        db.Entry(advReward).State = EntityState.Modified;
                    }
                }
                adv.Status     = SystemStaticData.LookUpAdvStatusId(SystemStaticData.AdvDictionary.Normal);
                adv.ContentUrl = Request.Form["ContentUrl"];
                adv.ModifyAt   = DateTime.Now;

                var securityKey = ConfigurationManager.AppSettings["Key"];
                var securityIV  = ConfigurationManager.AppSettings["IV"];
                var websiteURL  = ConfigurationManager.AppSettings["WebSiteURl"];
                var baseStr     = advId.ToString();

                var costFeeURL = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx37b646528bc2c1d2&redirect_uri={0}?para={1}&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect", websiteURL, SecurityUtility.Encrypt(baseStr, securityKey, securityIV));
                adv.CostFeeUrl = costFeeURL;
            }
            else
            {
                //更新adv状态
                adv.Status = SystemStaticData.LookUpAdvStatusId(SystemStaticData.AdvDictionary.Refuse);
                var userAccount = db.UserAccount.First(p => p.UserId == adv.UserId);
                //退款
                userAccount.AccountBalance += adv.TotalCash;
                //记录账户日志
                LogAccountHistory(userAccount.AccountId, adv.TotalCash, "广告审核未通过,退回扣款");
                db.UserAccount.Attach(userAccount);
                db.Entry(userAccount).State = EntityState.Modified;
            }

            db.SaveChanges();
            return(RedirectToAction("AdvList", "Adv"));
        }
        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());
        }