Beispiel #1
0
        public override InviteSerialCollection GetInviteSerials(int operatorUserID, InviteSerialStatus status, string filter, int pageNumber, out int totalCount)
        {
            using (SqlQuery query = new SqlQuery())
            {
                StringBuffer Condition = new StringBuffer();

                Condition += " AND UserID = @UserID";
                query.CreateParameter <int>("@UserID", operatorUserID, SqlDbType.Int);

                if (status != InviteSerialStatus.All)
                {
                    if (status != InviteSerialStatus.Expires)
                    {
                        Condition += " AND [Status] = @Status";
                        query.CreateParameter <byte>("@Status", (byte)status, SqlDbType.TinyInt);
                    }

                    else if (status == InviteSerialStatus.Expires)
                    {
                        Condition += " AND Status <> 1 AND ExpiresDate <= GETDATE()";
                    }
                }

                if (string.IsNullOrEmpty(filter) == false)
                {
                    Condition += " AND (Serial LIKE '%'+ @word +'%' OR ToUserID IN( SELECT UserID FROM bx_Users WHERE Username LIKE '%'+ @word +'%' OR Realname  LIKE '%'+ @word +'%' ))";
                    query.CreateParameter <string>("@word", filter, SqlDbType.NVarChar, 50);
                }

                if (Condition.Length > 0)
                {
                    Condition.Remove(0, 5);
                }

                query.Pager.SortField   = "CreateDate";
                query.Pager.IsDesc      = true;
                query.Pager.TableName   = "[bx_InviteSerials]";
                query.Pager.SelectCount = true;
                query.Pager.PageSize    = 20;
                query.Pager.PageNumber  = pageNumber > 0 ? pageNumber : 1;
                query.Pager.Condition   = Condition.ToString();
                query.Pager.PrimaryKey  = "[ID]";

                totalCount = 0;
                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    InviteSerialCollection Serials = new InviteSerialCollection(reader);

                    if (reader.NextResult())
                    {
                        if (reader.Read())
                        {
                            totalCount           = reader.GetInt32(0);
                            Serials.TotalRecords = totalCount;
                        }
                    }
                    return(Serials);
                }
            }
        }
Beispiel #2
0
        //public void UpdateInviteSerialEmailAndStatus(int userID, InviteSerialCollection serials)
        //{
        //    InviteDao.Instance.UpdateInviteSerialEmailAndStatus(userID, serials);
        //}

        public bool SendInviteByEmail(AuthUser operatorUser, Guid serial, string email)
        {
            if (AllSettings.Current.EmailSettings.EnableSendEmail == false)
            {
                ThrowError(new EmailDisabledError());
                return(false);
            }

            if (string.IsNullOrEmpty(email))
            {
                ThrowError(new EmptyEmailError("email"));
            }

            else if (!ValidateUtil.IsEmail(email) == false)
            {
                ThrowError(new EmailFormatError("email", email));
            }

            InviteSerial inviteSerial = this.GetInviteSerial(serial);

            if (inviteSerial == null ||
                inviteSerial.Status == InviteSerialStatus.Expires ||
                inviteSerial.Status == InviteSerialStatus.Used ||
                inviteSerial.UserID != operatorUser.UserID
                )
            {
                ThrowError(new InviteSerialError("serial", serial.ToString()));
            }

            if (HasUnCatchedError)
            {
                return(false);
            }

            InviteEmail emailSender = new InviteEmail(
                email
                , inviteSerial.Serial
                , operatorUser.Username
                , operatorUser.UserID);

            emailSender.Send();


            if (!HasUnCatchedError)
            {
                inviteSerial.ToEmail = email;
                inviteSerial.Status  = InviteSerialStatus.Unused;

                InviteSerialCollection serials = new InviteSerialCollection();
                serials.Add(inviteSerial);

                InviteDao.Instance.UpdateInviteSerialEmailAndStatus(operatorUser.UserID, serials);

                return(true);
            }

            return(false);
        }
Beispiel #3
0
        public override InviteSerialCollection GetInviteSerials(int?ownerUserId, InviteSerialFilter filter, int pageNumber, out int totalCount)
        {
            using (SqlQuery query = new SqlQuery())
            {
                string Condition = BuildCondition(filter, query);
                if (ownerUserId != null)
                {
                    Condition += " AND UserID = @OwnerID";
                    query.CreateParameter <int>("@OwnerID", ownerUserId.Value, SqlDbType.Int);
                }



                if (filter.Pagesize < 1)
                {
                    filter.Pagesize = 20;
                }


                query.Pager.SortField   = filter.Order.Value.ToString();
                query.Pager.IsDesc      = filter.IsDesc.Value;
                query.Pager.TableName   = "[bx_InviteSerials]";
                query.Pager.SelectCount = true;
                query.Pager.PageSize    = filter.Pagesize;
                query.Pager.PageNumber  = pageNumber > 0 ? pageNumber : 1;
                query.Pager.Condition   = Condition;
                query.Pager.PrimaryKey  = "[ID]";

                totalCount = 0;
                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    InviteSerialCollection Serials = new InviteSerialCollection(reader);

                    if (reader.NextResult())
                    {
                        if (reader.Read())
                        {
                            totalCount           = reader.GetInt32(0);
                            Serials.TotalRecords = totalCount;
                        }
                    }
                    return(Serials);
                }
            }
        }
Beispiel #4
0
        public override void UpdateInviteSerialEmailAndStatus(int userID, InviteSerialCollection serials)
        {
            using (SqlQuery query = new SqlQuery())
            {
                StringBuilder sbSql = new StringBuilder();

                int i = 0;

                if (serials != null)
                {
                    foreach (InviteSerial serial in serials)
                    {
                        sbSql.Append(@"UPDATE [bx_InviteSerials] SET ToEmail = @Email").Append(i);

                        query.CreateParameter <string>("@Email" + i, serial.ToEmail, SqlDbType.VarChar, 200);

                        sbSql.Append(" ,Status = @Status").Append(i);

                        query.CreateParameter <byte>("@Status" + i, (byte)serial.Status, SqlDbType.TinyInt);

                        sbSql.Append(" ,ExpiresDate = @ExpiresDate").Append(i);

                        query.CreateParameter <DateTime>("@ExpiresDate" + i, serial.ExpiresDate, SqlDbType.DateTime);

                        sbSql.Append(@" WHERE Serial = @Serial").Append(i).Append(" ; ");

                        query.CreateParameter <Guid>("@Serial" + i, serial.Serial, SqlDbType.UniqueIdentifier);

                        i++;
                    }

                    query.CommandText = sbSql.ToString();
                    query.ExecuteNonQuery();
                }
            }
        }
Beispiel #5
0
 public abstract void UpdateInviteSerialEmailAndStatus(int userID, InviteSerialCollection serials);
Beispiel #6
0
        public override InviteSerialCollection GetInviteSerials(int? ownerUserId, InviteSerialFilter filter, int pageNumber, out int totalCount)
        {
            using (SqlQuery query = new SqlQuery())
            {
                string Condition = BuildCondition(filter, query);
                if (ownerUserId != null)
                {
                    Condition += " AND UserID = @OwnerID";
                    query.CreateParameter<int>("@OwnerID", ownerUserId.Value, SqlDbType.Int);
                }

               


                if (filter.Pagesize < 1) filter.Pagesize = 20;


                query.Pager.SortField = filter.Order.Value.ToString();
                query.Pager.IsDesc = filter.IsDesc.Value;
                query.Pager.TableName = "[bx_InviteSerials]";
                query.Pager.SelectCount = true;
                query.Pager.PageSize = filter.Pagesize;
                query.Pager.PageNumber = pageNumber > 0 ? pageNumber : 1;
                query.Pager.Condition = Condition;
                query.Pager.PrimaryKey = "[ID]";

                totalCount = 0;
                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    InviteSerialCollection Serials = new InviteSerialCollection(reader);

                    if (reader.NextResult())
                    {
                        if (reader.Read())
                        {
                            totalCount = reader.GetInt32(0);
                            Serials.TotalRecords = totalCount;
                        }
                    }
                    return Serials;
                }
            }
        }
Beispiel #7
0
        public override InviteSerialCollection GetInviteSerials(int operatorUserID, InviteSerialStatus status, string filter, int pageNumber, out int totalCount)
        {
            using (SqlQuery query = new SqlQuery())
            {
                StringBuffer Condition = new StringBuffer();

                Condition += " AND UserID = @UserID";
                query.CreateParameter<int>("@UserID", operatorUserID, SqlDbType.Int);

                if (status != InviteSerialStatus.All)
                {

                    if (status != InviteSerialStatus.Expires)
                    {
                        Condition += " AND [Status] = @Status";
                        query.CreateParameter<byte>("@Status", (byte)status, SqlDbType.TinyInt);
                    }

                    else if (status == InviteSerialStatus.Expires)
                    {
                        Condition += " AND Status <> 1 AND ExpiresDate <= GETDATE()";
                    }
                }

                if (string.IsNullOrEmpty(filter) == false)
                {
                    Condition += " AND (Serial LIKE '%'+ @word +'%' OR ToUserID IN( SELECT UserID FROM bx_Users WHERE Username LIKE '%'+ @word +'%' OR Realname  LIKE '%'+ @word +'%' ))";
                    query.CreateParameter<string>("@word", filter, SqlDbType.NVarChar, 50);
                }

                if (Condition.Length > 0)
                    Condition.Remove(0, 5);

                query.Pager.SortField = "CreateDate";
                query.Pager.IsDesc = true;
                query.Pager.TableName = "[bx_InviteSerials]";
                query.Pager.SelectCount = true;
                query.Pager.PageSize = 20;
                query.Pager.PageNumber = pageNumber > 0 ? pageNumber : 1;
                query.Pager.Condition = Condition.ToString();
                query.Pager.PrimaryKey = "[ID]";

                totalCount = 0;
                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    InviteSerialCollection Serials = new InviteSerialCollection(reader);

                    if (reader.NextResult())
                    {
                        if (reader.Read())
                        {
                            totalCount = reader.GetInt32(0);
                            Serials.TotalRecords = totalCount;
                        }
                    }
                    return Serials;
                }
            }

        }
Beispiel #8
0
        public override void UpdateInviteSerialEmailAndStatus(int userID, InviteSerialCollection serials)
        {
            using (SqlQuery query = new SqlQuery())
            {
                StringBuilder sbSql = new StringBuilder();

                int i = 0;

                if (serials != null)
                {
                    foreach (InviteSerial serial in serials)
                    {
                        sbSql.Append(@"UPDATE [bx_InviteSerials] SET ToEmail = @Email").Append(i);

                        query.CreateParameter<string>("@Email" + i, serial.ToEmail, SqlDbType.VarChar, 200);

                        sbSql.Append(" ,Status = @Status").Append(i);

                        query.CreateParameter<byte>("@Status" + i, (byte)serial.Status, SqlDbType.TinyInt);

                        sbSql.Append(" ,ExpiresDate = @ExpiresDate").Append(i);

                        query.CreateParameter<DateTime>("@ExpiresDate" + i, serial.ExpiresDate, SqlDbType.DateTime);

                        sbSql.Append(@" WHERE Serial = @Serial").Append(i).Append(" ; ");

                        query.CreateParameter<Guid>("@Serial" + i, serial.Serial, SqlDbType.UniqueIdentifier);

                        i++;
                    }

                    query.CommandText = sbSql.ToString();
                    query.ExecuteNonQuery();
                }

            }
        }