Esempio n. 1
0
        /// <summary>
        /// 创建投票
        /// </summary>
        /// <param name="content">投票内容</param>
        /// <param name="message">处理结果信息</param>
        /// <returns></returns>
        public QssResult QssCreateVote(string content, out string message)
        {
            // 获取当前登录用户
            QssResult result = DbSession.UserDal.QssGetUserByAccount(User.Identity.Name, out User user);

            if (result != QssResult.Success)
            {
                message = "获取当前用户失败!";
                return(QssResult.Error);
            }

            // 校验邮箱
            if (!user.QssCheckHaveEmail())
            {
                message = "未绑定邮箱!";
                return(QssResult.Fail);
            }

            // 每人每天只能添加3份投票
            if (user.LastAddVoteTime.AddDays(1) > DateTime.Now && user.AddVoteNum >= 3)
            {
                message = "添加投票失败,每人每天只能添加3份投票!";
                return(QssResult.Error);
            }

            // 获取投票内容
            JObject voteRoot = (JObject)JsonConvert.DeserializeObject(content);

            // 全局变量
            JObject voteGlobal = (JObject)voteRoot["Global"];

            // 创建投票
            result = QssCreateVoteGlobal(voteGlobal, user, out Vote vote, out message);
            if (result != QssResult.Success)
            {
                return(result);
            }

            // 创建选项
            JArray voteOption = (JArray)voteRoot["Option"];

            result = new VoteOptionService().QssCreateVoteOption(voteOption, user, vote, out message);
            if (result != QssResult.Success)
            {
                return(result);
            }

            // 保存投票内容
            result = QssCreateVoteContent(vote, out message);
            if (result != QssResult.Success)
            {
                return(result);
            }

            // 发送站内信和邮件
            return(new QssSendQvLetterEmail <Vote>(vote).Send(out message));
        }
Esempio n. 2
0
        /// <summary>
        /// 保存填写投票内容
        /// </summary>
        /// <param name="content">投票内容</param>
        /// <param name="message">处理后的结果信息</param>
        /// <returns></returns>
        public QssResult QssSaveVote(string content, out string message)
        {
            JObject voteRoot = (JObject)JsonConvert.DeserializeObject(content);
            int     voteId   = Convert.ToInt32(voteRoot["Id"]);

            // 查看填写问卷权限
            if (CheckWtAuth(voteId, out Vote vote, out message) != QssResult.Success)
            {
                return(QssResult.Fail);
            }

            // 投票状态
            if (vote.State != QssQuesAndVoteState.Write)
            {
                message = "投票已结束,不能填写!";
                return(QssResult.Fail);
            }

            // 获取当前用户
            QssResult result = DbSession.UserDal.QssGetUserByAccount(User.Identity.Name, out User user);

            if (result != QssResult.Success)
            {
                message = "获取当前用户失败!";
                QssLogHelper.Log("没有获取到当前用户", "在保存填写的问卷时,没有获取到当前用户", QssLogType.Warn);
                return(QssResult.Error);
            }

            // 校验权限
            if (vote.VoteWtOrganizes.Intersect(user.JoinOrganizes).Count() <= 0)
            {
                message = "权限不够";
                return(QssResult.Fail);
            }

            // 保存选项
            result = new VoteOptionService().QssSaveVoteWtLog((JArray)voteRoot["Option"], vote, out List <GetWtVoteOption> wtOptions, out message);
            if (result != QssResult.Success)
            {
                return(result);
            }

            // 保存结果
            result = QssSaveResult(vote, out message);
            if (result != QssResult.Success)
            {
                return(result);
            }

            // 保存填写记录
            return(new WtLogService().QssSaveVoteWtLog(vote, wtOptions.ToArray(), user, out message));
        }