示例#1
0
        public void SendInvites(InviteData inviteData)
        {
            try
            {
                int countInvitationsForDay = invitationRepository.GetCountInvitations(4);

                var validationData = new ValidationData()
                                     .AddNumbers(inviteData.Numbers)
                                     .AddMessage(inviteData.Message)
                                     .AddPermissibleNumberOfInvitations(countInvitationsForDay, 128)
                                     .AddRequiredAmountInvitationsPerCallRule(16)
                                     .AddMaxMessageLength(128);

                var validation = new Validation();
                validation.ValidateRules(validationData);

                invitationRepository.Invite(7, inviteData.Numbers);

                message.Send(validationData.Message);
            }
            catch (BadRequestException e)
            {
                logger.LogError($"{e.Code} {e.Message}");
                throw;
            }
            catch (Exception e)
            {
                string errorMessage = $"500 INTERNAL SMS_SERVICE: {e.Message}";
                logger.LogError(errorMessage);
                throw new InternalSmsServiceException(500, errorMessage);
            }
        }
示例#2
0
        public static async ETTask <Invite> CreateInvite(this InviteComponent self, InviteData inviteData)
        {
            Invite invite = ComponentFactory.CreateWithId <Invite>(IdGenerater.GenerateId());

            invite.SetData(inviteData);
            self._Create(invite);
            await self.MemorySync.Create(invite);

            return(invite);
        }
        public IHttpActionResult Invite(InviteData inviteData)
        {
            var validationResult = _inviteDataValidator.Validate(inviteData);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.Errors.BuildModelState()));
            }

            var store   = _storeService.GetById(inviteData.StoreId);
            var company = _memberService.GetByIds(new[] { inviteData.CompanyId }).First();

            inviteData.Emails.ProcessWithPaging(50, (currentEmails, currentCount, totalCount) =>
            {
                var companyMembers = currentEmails.Select(email => new CompanyMember
                {
                    FullName      = email,
                    Emails        = new[] { email },
                    Organizations = new[] { inviteData.CompanyId },
                    IsActive      = false
                }).ToArray();
                _memberService.SaveChanges(companyMembers.Cast <Member>().ToArray());

                foreach (var companyMember in companyMembers)
                {
                    var token = companyMember.Id;

                    var uriBuilder   = new UriBuilder(inviteData.CallbackUrl);
                    var query        = HttpUtility.ParseQueryString(uriBuilder.Query);
                    query["invite"]  = token;
                    uriBuilder.Query = query.ToString();

                    var notification         = _notificationManager.GetNewNotification <CorporateInviteEmailNotification>(inviteData.StoreId, "Store", inviteData.Language);
                    notification.Url         = uriBuilder.ToString();
                    notification.CompanyName = company.Name;
                    notification.Message     = inviteData.Message;

                    notification.StoreName = store.Name;
                    notification.Sender    = store.Email;
                    notification.IsActive  = true;

                    notification.AdminName  = inviteData.AdminName;
                    notification.AdminEmail = inviteData.AdminEmail;

                    notification.Recipient = companyMember.Emails.Single();

                    _notificationManager.ScheduleSendNotification(notification);
                }
            });

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#4
0
 public void UpdateRow(InviteData row)
 {
     if (row.role != null)
     {
         this.role = row;
         Image component = base.FindTransform("headIcon").GetComponent <Image>();
         ResourceManager.SetSprite(component, UIUtils.GetRoleSmallIcon((int)row.role.career));
         base.FindTransform("roleName").GetComponent <Text>().set_text(this.role.role.name);
         base.FindTransform("fightValue").GetComponent <Text>().set_text(string.Empty + this.role.role.fighting.ToString());
         base.FindTransform("level").GetComponent <Text>().set_text("Lv" + this.role.role.level.ToString());
         ResourceManager.SetSprite(this.m_spVIPLevel1, GameDataUtils.GetNumIcon10(row.role.vipLv, NumType.Yellow));
         ResourceManager.SetSprite(this.m_spVIPLevel2, GameDataUtils.GetNumIcon1(row.role.vipLv, NumType.Yellow));
         this.InitCdTime(this.role.cdTime);
     }
 }
示例#5
0
    private void OnUpdateUIGrid(UIGridBase gridBase, int index)
    {
        if (null == m_inviteData ||
            null == m_inviteData.inviteDatas ||
            m_inviteData.inviteDatas.Count <= index)
        {
            return;
        }
        UIInviteGrid grid = gridBase as UIInviteGrid;
        InviteData   data = m_inviteData.inviteDatas[index];

        if (null != grid && null != data)
        {
            grid.SetData(data.userId, data.name, data.icon, (uint)data.lv);
        }
    }
示例#6
0
 private void OnUIGridEventDlg(UIEventType eventType, object data, object param)
 {
     switch (eventType)
     {
     case UIEventType.Click:
     {
         UIInviteGrid grid = data as UIInviteGrid;
         if (null != m_inviteData && null != m_inviteData.inviteBtnClickAction)
         {
             InviteData inviteData = m_inviteData.GetInviteData(grid.UserId);
             if (null != data && null != param)
             {
                 m_inviteData.inviteBtnClickAction.Invoke(inviteData);
             }
         }
     }
     break;
     }
 }
        public void InviteUsers(BasicUser invitedBy, string comments, FriendProvider friendProvider, IList <IBasicUser> contacts, bool includeInvitationCode)
        {
            // Make sure we get the complete user.
            BasicUser user = basicUserRepository.Get(invitedBy.Id);

            // If we are including the invitation code is because we are in Beta, no more than 10 invites per user.
#if !DEBUG
            if (includeInvitationCode)
            {
                if (user.Friends.Count + contacts.Count >= MAX_TO_INVITE)
                {
                    if (MAX_TO_INVITE - user.Friends.Count > 0)
                    {
                        throw new LimitOfFriendsExceededException(string.Format("You can add up to {0} more friends in the Beta period.", MAX_TO_INVITE - user.Friends.Count));
                    }
                    else
                    {
                        throw new LimitOfFriendsExceededException(string.Format("You have reached the {0} contacts limit in the Beta period.", MAX_TO_INVITE));
                    }
                }
            }
#endif

            basicUserRepository.DbContext.BeginTransaction();
            foreach (IBasicUser contact in contacts)
            {
                if (contact.EmailAddress.Trim() == string.Empty || user.EmailAddress.Trim().ToLower() == contact.EmailAddress.Trim().ToLower())
                {
                    continue;
                }

                // Call the Friend Creator service
                Friend f = friendCreatorService.Create(contact.EmailAddress.Trim().ToLower(), contact.FirstName, contact.LastName, friendProvider);

                // Make sure it does not have it as a friend to send the email.
                if (!user.HasFriend(f))
                {
                    // Save the Friend into the user collection
                    f.BasicUser = user;
                    user.AddFriend(f);
                }

                // TODO: Review how to get the Url from the controller
                string     confirmUrl = string.Format("/Friend/InvitedMe/default.aspx");
                InviteData inviteData = new InviteData {
                    Friend = f, AcceptUrl = confirmUrl, InvitationCode = Guid.NewGuid().ToString()
                };

                if (f.User is InvitedUser)
                {
                    if (includeInvitationCode)
                    {
                        // Create an invitation code
                        InvitationCode ic = new InvitationCode();
                        ic.EmailAddress = f.User.EmailAddress;
                        ic.Code         = inviteData.InvitationCode;
                        ic.InvitedBy    = f.BasicUser;
                        invitationCodeRepository.SaveOrUpdate(ic);

                        messageSenderService.SendWithTemplate("invitation_with_code", user, inviteData, f.User.EmailAddress);
                    }
                    else
                    {
                        messageSenderService.SendWithTemplate("invitation", user, f, f.User.EmailAddress);
                    }
                }
                else
                {
                    messageSenderService.SendWithTemplate("acceptinvite", user, inviteData, f.User.EmailAddress);
                }
            }

            basicUserRepository.SaveOrUpdate(user);
            basicUserRepository.DbContext.CommitTransaction();
        }
 public void SetData(InviteData data)
 {
     this.data          = data;
     this.data.InviteId = Id;
 }
示例#9
0
        protected override async ETTask Run(MapUnit mapUnit, C2M_TeamInvite message, Action <M2C_TeamInvite> reply)
        {
            await ETTask.CompletedTask;

            M2C_TeamInvite response = new M2C_TeamInvite();

            try
            {
                if (mapUnit.Room == null)
                {
                    response.Error = ErrorCode.ERR_RoomIdNotFound;
                    reply(response);
                    return;
                }

                if (mapUnit.Room.Type != RoomType.Team)
                {
                    response.Error = ErrorCode.ERR_RoonTypeError;
                    reply(response);
                    return;
                }

                if (mapUnit.Room.State != RoomState.Start)
                {
                    response.Error = ErrorCode.ERR_RoomTeamStateCanNotInvite;
                    reply(response);
                    return;
                }

                User user = await UserDataHelper.FindOneUser(mapUnit.Uid);

                if (user == null)
                {
                    response.Error = ErrorCode.ERR_AccountDoesntExist;
                    reply(response);
                    return;
                }

                // 建立邀請
                InviteData inviteData = new InviteData()
                {
                    SenderName    = user.name,
                    SenderUid     = mapUnit.Uid,
                    ReceiverUid   = message.ReceiverUid,
                    TeamRoomId    = mapUnit.Room.Id,
                    RoadSettingId = mapUnit.Room.info.RoadSettingId
                };

                var player       = CacheExHelper.GetFromCache <Player>(mapUnit.Uid);
                var lobbySession = SessionHelper.GetLobbySession(player.lobbyAppId);
                L2M_CreateInvite l2M_CreateInvite = (L2M_CreateInvite)await lobbySession.Call(new M2L_CreateInvite
                {
                    InviteInfo = inviteData,
                });

                if (l2M_CreateInvite.Error != ErrorCode.ERR_Success)
                {
                    response.Error = ErrorCode.ERR_InviteIdNotFind;
                    reply(response);
                    return;
                }

                Invite inviteEntity = BsonSerializer.Deserialize <Invite>(l2M_CreateInvite.Json);
                CacheExHelper.WriteInCache(inviteEntity, out inviteEntity);

                // 告知對方
                Player inviteTarget = CacheExHelper.GetFromCache <Player>(message.ReceiverUid);
                if (inviteTarget != null)
                {
                    //在線上 廣播給指定玩家邀請訊息
                    G2C_TeamInviteReceiver g2c_TeamInviteReceiver = new G2C_TeamInviteReceiver();
                    g2c_TeamInviteReceiver.InviteId   = inviteEntity.Id;
                    g2c_TeamInviteReceiver.SenderName = inviteEntity.data.SenderName;
                    GateMessageHelper.BroadcastTarget(g2c_TeamInviteReceiver, message.ReceiverUid);
                }
                // 推播
                User u = await UserDataHelper.FindOneUser(message.ReceiverUid);

                var firebase = Game.Scene.GetComponent <FirebaseComponent>();
                var lang     = Game.Scene.GetComponent <LanguageComponent>();
                // 多國2-'{0}'邀請你一起組隊!
                var body = lang.GetString(u.language, 2L);
                await firebase.SendOneNotification(u.firebaseDeviceToken, string.Empty, string.Format(body, user.name));

                response.Error = ErrorCode.ERR_Success;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }