Ejemplo n.º 1
0
        public bool Update(UserMailEntity entity)
        {
            bool   isSuccess = false;
            string insertSQL = "UPDATE M_User_Mail SET UserID=@UserID,EventItemID=@EventItemID,CreateDate=@CreateDate,MailStatus=@MailStatus,Remark=@Remark,SendDate=@SendDate WHERE MailID=@MailID";

            SqlParameter[] prms = new SqlParameter[] {
                new SqlParameter("@UserID", SqlDbType.Int, 4),
                new SqlParameter("@EventItemID", SqlDbType.Int, 4),
                new SqlParameter("@CreateDate", SqlDbType.DateTime),
                new SqlParameter("@MailStatus", SqlDbType.Int, 4),
                new SqlParameter("@Remark", SqlDbType.NVarChar, 500),
                new SqlParameter("@SendDate", SqlDbType.DateTime),
                new SqlParameter("@MailID", SqlDbType.Int, 4)
            };

            prms[0].Value = entity.UserID;
            prms[1].Value = entity.EventItemID;
            prms[2].Value = entity.CreateDate;
            prms[3].Value = entity.MailStatus;
            prms[4].Value = entity.Remark;
            prms[5].Value = entity.SendDate;
            prms[6].Value = entity.MailID;

            try
            {
                isSuccess = SQlHelper.ExecuteNonQuery(SQlHelper.MyConnectStr, CommandType.Text, insertSQL, prms) > 0;
            }
            catch (Exception ex)
            {
                LogUtil.WriteLog(ex);
                return(false);
            }
            return(isSuccess);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据ID得到一个邮件实体
        /// </summary>
        /// <param name="id">邮件ID</param>
        /// <returns>邮件实体</returns>
        public static UserMailEntity GetUserMail(Int32 id)
        {
            if (!UserManager.IsUserLogined)
            {
                throw new UserUnLoginException();
            }

            if (id <= 0)
            {
                throw new InvalidRequstException(RequestType.UserMail);
            }

            String         userName = UserManager.CurrentUserName;
            UserMailEntity entity   = UserMailRepository.Instance.GetEntity(userName, id);

            if (entity == null)
            {
                throw new NullResponseException(RequestType.UserMail);
            }

            if (!entity.IsRead)
            {
                UserMailManager.UpdateUserMailRead(entity);
            }

            return(entity);
        }
Ejemplo n.º 3
0
        public bool Insert(UserMailEntity entity)
        {
            bool   isSuccess = false;
            string insertSQL = "INSERT INTO M_User_Mail(UserID,EventItemID,CreateDate,MailStatus,Remark) VALUES (@UserID,@EventItemID,@CreateDate,@MailStatus,@Remark)";

            SqlParameter[] prms = new SqlParameter[] {
                new SqlParameter("@UserID", SqlDbType.Int, 4),
                new SqlParameter("@EventItemID", SqlDbType.Int, 4),
                new SqlParameter("@CreateDate", SqlDbType.DateTime),
                new SqlParameter("@MailStatus", SqlDbType.Int, 4),
                new SqlParameter("@Remark", SqlDbType.NVarChar, 500)
            };

            prms[0].Value = entity.UserID;
            prms[1].Value = entity.EventItemID;
            prms[2].Value = entity.CreateDate;
            prms[3].Value = entity.MailStatus;
            prms[4].Value = entity.Remark;

            try
            {
                isSuccess = SQlHelper.ExecuteNonQuery(SQlHelper.MyConnectStr, CommandType.Text, insertSQL, prms) > 0;
            }
            catch (Exception ex)
            {
                LogUtil.WriteLog(ex);
                return(false);
            }
            return(isSuccess);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 发送用户邮件
        /// </summary>
        /// <param name="model">邮件实体</param>
        /// <returns>是否发送成功</returns>
        internal static Boolean InternalSendUserMail(UserMailEntity entity)
        {
            entity.SendDate  = DateTime.Now;
            entity.IsRead    = false;
            entity.IsDeleted = false;

            Int32 result = UserMailRepository.Instance.InsertEntity(entity);

            if (result > 0)
            {
                UserMailCache.RemoveUserUnReadMailCountCache(entity.ToUserName);//删除缓存
            }

            return(result > 0);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 更新一条邮件的状态
        /// </summary>
        /// <param name="model">对象实体</param>
        /// <returns>是否成功更新</returns>
        private static Boolean UpdateUserMailRead(UserMailEntity entity)
        {
            Boolean success = false;

            try
            {
                entity.IsRead = true;
                success       = UserMailRepository.Instance.UpdateEntityIsRead(entity) > 0;
            }
            finally
            {
                if (success)
                {
                    UserMailCache.RemoveUserUnReadMailCountCache(entity.ToUserName);//删除缓存
                }
            }

            return(success);
        }
Ejemplo n.º 6
0
        public ActionResult Send(FormCollection form)
        {
            String         result;
            UserMailEntity mail = new UserMailEntity()
            {
                ToUserName = form["tousername"],
                Title      = form["title"],
                Content    = form["content"]
            };

            if (UserMailManager.TrySendUserMail(mail, out result))
            {
                return(RedirectToSuccessMessagePage("Your mail has been successfully sent!"));
            }
            else
            {
                return(RedirectToErrorMessagePage(result));
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 尝试发送邮件
        /// </summary>
        /// <param name="model">邮件实体</param>
        /// <param name="error">出错信息</param>
        /// <returns>是否发送成功</returns>
        public static Boolean TrySendUserMail(UserMailEntity entity, out String error)
        {
            if (!UserManager.IsUserLogined)
            {
                error = "Please login first!";
                return(false);
            }

            if (String.IsNullOrEmpty(entity.Title))
            {
                error = "Title can not be NULL!";
                return(false);
            }

            if (entity.Title.Length > UserMailRepository.TITLE_MAXLEN)
            {
                error = "Title is too long!";
                return(false);
            }

            if (String.IsNullOrEmpty(entity.Content) || entity.Content.Length < UserMailRepository.CONTENT_MINLEN)
            {
                error = "Content is too short!";
                return(false);
            }

            if (entity.Content.Length > UserMailRepository.CONTENT_MAXLEN)
            {
                error = "Content is too long!";
                return(false);
            }

            if (String.IsNullOrEmpty(entity.ToUserName))
            {
                error = "Username can not be NULL!";
                return(false);
            }

            if (!RegexVerify.IsUserName(entity.ToUserName))
            {
                error = "Username is INVALID!";
                return(false);
            }

            if (String.Equals(ConfigurationManager.SystemAccount, entity.ToUserName, StringComparison.OrdinalIgnoreCase))
            {
                error = "You can not send mail to system account!";
                return(false);
            }

            if (String.Equals(UserManager.CurrentUserName, entity.ToUserName, StringComparison.OrdinalIgnoreCase))
            {
                error = "You can not send mail to yourself!";
                return(false);
            }

            if (!UserSubmitStatus.CheckLastSubmitUserMailTime(UserManager.CurrentUserName))
            {
                throw new InvalidInputException(String.Format("You can not submit user mail more than twice in {0} seconds!", ConfigurationManager.SubmitInterval.ToString()));
            }

            if (!UserManager.InternalExistsUser(entity.ToUserName))
            {
                error = String.Format("The username \"{0}\" doesn't exist!", entity.ToUserName);
                return(false);
            }

            entity.Title        = HtmlEncoder.HtmlEncode(entity.Title);
            entity.Content      = HtmlEncoder.HtmlEncode(entity.Content);
            entity.FromUserName = UserManager.CurrentUserName;

            if (!UserMailManager.InternalSendUserMail(entity))
            {
                error = "Failed to send your mail";
                return(false);
            }

            error = String.Empty;
            return(true);
        }
Ejemplo n.º 8
0
 public bool Update(UserMailEntity entity)
 {
     return(dao.Update(entity));
 }
Ejemplo n.º 9
0
 public bool Insert(UserMailEntity entity)
 {
     return(dao.Insert(entity));
 }
Ejemplo n.º 10
0
        /// <summary>
        /// 增加一条回帖
        /// </summary>
        /// <param name="post">帖子实体</param>
        /// <param name="topic">主题实体</param>
        /// <param name="parentPost">回复的帖子实体</param>
        /// <param name="postip">发布者IP</param>
        /// <param name="link">当前页面地址</param>
        /// <returns>是否成功增加</returns>
        public static Boolean InsertForumPost(ForumPostEntity post, ForumTopicEntity topic, ForumPostEntity parentPost, String postip, String link)
        {
            if (!UserManager.IsUserLogined)
            {
                throw new UserUnLoginException();
            }

            if (String.IsNullOrEmpty(post.Title))
            {
                throw new InvalidInputException("Reply title can not be NULL!");
            }

            if (post.Title.Length > ForumPostRepository.TITLE_MAXLEN)
            {
                throw new InvalidInputException("Reply title is too long!");
            }

            if (!KeywordsFilterManager.IsForumPostContentLegal(post.Title))
            {
                throw new InvalidInputException("Reply title can not contain illegal keywords!");
            }

            if (String.IsNullOrEmpty(post.Content) || post.Content.Length < ForumPostRepository.POST_MINLEN)
            {
                throw new InvalidInputException("Reply content is too short!");
            }

            if (post.Content.Length > ForumPostRepository.POST_MAXLEN)
            {
                throw new InvalidInputException("Reply content is too long!");
            }

            if (!KeywordsFilterManager.IsForumPostContentLegal(post.Content))
            {
                throw new InvalidInputException("Reply content can not contain illegal keywords!");
            }

            if (parentPost.Deepth + 1 < ForumPostRepository.DEEPTH_MIN)
            {
                throw new InvalidInputException("Reply deepth is INVALID!");
            }

            if (parentPost.Deepth + 1 > ForumPostRepository.DEEPTH_MAX)
            {
                throw new InvalidInputException("Reply deepth is too deep!");
            }

            if (topic.IsLocked)
            {
                throw new NoPermissionException("You have no privilege to reply the post!");
            }

            if (!UserSubmitStatus.CheckLastSubmitForumPostTime(UserManager.CurrentUserName))
            {
                throw new InvalidInputException(String.Format("You can not submit post more than twice in {0} seconds!", ConfigurationManager.SubmitInterval.ToString()));
            }

            post.TopicID      = parentPost.TopicID;
            post.Title        = HtmlEncoder.HtmlEncode(post.Title);
            post.Content      = HtmlEncoder.HtmlEncode(post.Content);
            post.UserName     = UserManager.CurrentUserName;
            post.Deepth       = parentPost.Deepth + 1;
            post.ParentPostID = parentPost.PostID;
            post.PostDate     = DateTime.Now;
            post.PostIP       = postip;

            Boolean success = ForumPostRepository.Instance.InsertEntity(post) > 0;

            if (success && !String.Equals(parentPost.UserName, post.UserName))
            {
                if (ConfigurationManager.ReplyPostMailNotification)
                {
                    try
                    {
                        UserMailEntity mail = new UserMailEntity();
                        String         url  = ConfigurationManager.DomainUrl + ((link[0] == '/') ? link.Substring(1) : link);

                        mail.FromUserName = ConfigurationManager.SystemAccount;
                        mail.ToUserName   = parentPost.UserName;
                        mail.Title        = "Your post has new reply!";
                        mail.Content      =
                            String.Format("Your post \"{0}\" has new reply, <br/>", parentPost.Title) +
                            String.Format("Please visit <a href=\"{0}\" target=\"_blank\">{0}</a>", url);

                        UserMailManager.InternalSendUserMail(mail);
                    }
                    catch { }
                }
            }

            return(success);
        }