Beispiel #1
0
        /// <summary>
        /// 创建问卷题目选项
        /// </summary>
        /// <param name="options">题目选项列表</param>
        /// <param name="user">当前用户</param>
        /// <param name="subjectId">题目Id</param>
        /// <param name="message">处理结果信息</param>
        /// <returns></returns>
        public QssResult QssCreateQuesOption(JArray options, User user, QuesSubject subject, out string message)
        {
            // 创建题目选项
            foreach (JObject option in options)
            {
                var quesOption = new QuesOption()
                {
                    Content     = (string)option["Content"],
                    QuesSubject = subject
                };

                DbSession.QuesOptionDal.Add(quesOption);
            }

            // 保存题目选项
            try
            {
                DbSession.SaveChanges();

                // 保存成功
                message = "创建题目选项成功!";
                return(QssResult.Success);
            }
            catch (Exception exception)
            {
                // 保存失败
                message = "保存题目选项失败! 失败原因:" + exception.Message;
                QssLogHelper.Log("保存题目选项失败", $"保存题目 {subject.Content} 的选项失败!", QssLogType.Info);
                return(QssResult.Fail);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 获得学校组织
        /// 结果对学校组织公开,默认该结果公开
        /// </summary>
        /// <returns>查找结果</returns>
        public QssResult QssGetSchool(out Organize _school)
        {
            // 四川农业大学
            var school = Db.Organizes.Where(p => p.Name == QssEnvironment.SchoolName);

            if (!school.Any())
            {
                // 暂时没有该组织
                _school = null;
                return(QssResult.Fail);
            }
            else if (school.Count() > 1)
            {
                // 出现同名组织
                // 系统出现严重错误
                QssLogHelper.Log("出现重名组织", "组织:四川农业大学 的个数为" + school.Count(), QssLogType.Error);
                _school = null;
                return(QssResult.Error);
            }
            else
            {
                // 返回学校
                _school = school.FirstOrDefault();
                return(QssResult.Success);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 删除过期用户 在定时任务中调用
        /// </summary>
        public void DeleteExpireUser()
        {
            // 过期用户
            var expUsers = CurrentDal.GetEntities(p => p.Grade + p.LoSch < DateTime.Now.Year);

            if (expUsers.Count() == 0)
            {
                return;
            }

            // 相关填写记录
            var userIds = expUsers.Select(x => x.Id);
            var wtLogs  = DbSession.WtLogDal.GetEntities(p => userIds.Contains(p.User.Id));

            try
            {
                DbSession.WtLogDal.DeleteRange(wtLogs);
                DbSession.SaveChanges();
            }
            catch (Exception exception) { QssLogHelper.Log("批量删除填写记录失败", "在批量删除过期用户时,批量删除填写记录失败! 原因:" + exception.Message, QssLogType.Error, exception); }

            try
            {
                CurrentDal.DeleteRange(expUsers);
                DbSession.SaveChanges();
            }
            catch (Exception exception) { QssLogHelper.Log("批量删除过期用户失败", "在批量删除过期用户时,批量删除用户失败! 原因:" + exception.Message, QssLogType.Error, exception); }
        }
Beispiel #4
0
        /// <summary>
        /// 创建投票选项
        /// </summary>
        /// <param name="voteOption">投票选项</param>
        /// <param name="user">当前用户</param>
        /// <param name="vote">当前投票</param>
        /// <param name="message">处理结果信息</param>
        /// <returns></returns>
        public QssResult QssCreateVoteOption(JArray options, User user, Vote vote, out string message)
        {
            List <VoteOption> entities = new List <VoteOption>();

            foreach (JObject item in options)
            {
                entities.Add(new VoteOption()
                {
                    Content = (string)item["Content"], Vote = vote
                });
            }

            try
            {
                CurrentDal.AddRange(entities);
                DbSession.SaveChanges();

                message = "保存投票选项成功!";
                return(QssResult.Success);
            }
            catch (Exception exception)
            {
                message = "保存投票选项失败!";
                QssLogHelper.Log("保存投票选项失败", $"在保存投票: {vote.Title} 时失败! 原因:{exception.Message}", QssLogType.Error, exception, $"{user.Account}({user.Name})");
                throw;
            }
        }
Beispiel #5
0
        /// <summary>
        /// 保存投票记录
        /// </summary>
        /// <param name="vote">当前投票</param>
        /// <param name="wtVoteOption">投票记录</param>
        /// <param name="user">当前用户</param>
        /// <param name="message">处理结果信息</param>
        /// <returns></returns>
        public QssResult QssSaveVoteWtLog(Vote vote, GetWtVoteOption[] wtVoteOption, User user, out string message)
        {
            // 填写记录
            var wtlog = new WtLog()
            {
                QuesVoteId = vote.Id,
                Type       = QssWtLogType.Vote,
                Content    = JsonConvert.SerializeObject(new GetWtVoteModel {
                    Answers = wtVoteOption
                }),
                User   = user,
                WtTime = DateTime.Now
            };

            // 参与人数统计
            vote.JoinNum++;

            try
            {
                DbSession.VoteDal.Update(vote);
                DbSession.WtLogDal.Add(wtlog);
                DbSession.SaveChanges();

                message = "保存填写记录成功!";
                return(QssResult.Success);
            }
            catch (Exception exception)
            {
                message = "保存填写记录失败! 原因" + exception.Message;
                QssLogHelper.Log("保存填写记录失败", "在保存填写记录到记录表中时失败,原因:" + exception.Message, QssLogType.Error, exception);
                return(QssResult.Fail);
            }
        }
Beispiel #6
0
        /// <summary>
        /// 根据账号获取用户
        /// </summary>
        /// <returns>处理结果</returns>
        protected QssResult QssGetUserByAccount(string account, out User _user)
        {
            // 获取用户
            //var user = Db.Users.Include("Role").Include("JoinOrganizes").Where(p => p.Account == account);
            var user = Db.Users.Where(p => p.Account == account);

            // 用户不存在
            if (!user.Any())
            {
                _user = null;
                return(QssResult.Fail);
            }
            // 一个账号多次注册
            if (user.Count() > 1)
            {
                // 获取共用该账号的所有Id
                string strUser = "";
                foreach (var u in user)
                {
                    strUser += u.Id + ",";
                }
                // 记录错误
                QssLogHelper.Log("账号被多次注册", "账号:" + account + "被多次注册! Id[" + strUser.TrimEnd(',') + "].", QssLogType.Error);
                _user = null;
                return(QssResult.Error);
            }

            _user = user.FirstOrDefault();
            return(QssResult.Success);
        }
Beispiel #7
0
        /// <summary>
        /// 注册邮箱
        /// </summary>
        /// <param name="toEmail">接收者邮件</param>
        /// <param name="activateUrl">激活邮件地址</param>
        /// <param name="_result">处理结果</param>
        /// <returns></returns>
        public QssResult QssRegisterEmail(string toEmail, string activateUrl, string code, out string _result)
        {
            var result = QssGetUserByAccount(HttpContext.Current.User.Identity.Name, out User user);

            if (result != QssResult.Success)
            {
                _result = "出现错误!请重试,多次出现该错误请联系管理员.";
                return(QssResult.Fail);
            }
            string body = $"请点击<a href='{activateUrl}'> 此处 </a>来激活你的邮箱,该链接30分钟内有效. 若是链接不能跳转, 请将以下链接复制到浏览器地址栏进行跳转:<br />{activateUrl}";

            if (QssEmailHelper.SendMail(toEmail, "四川农业大学问卷调查与投票系统激活邮件", user.Name, body))
            {
                try
                {
                    // 保存邮箱和激活码
                    user.Email        = toEmail;
                    user.ACode        = code;
                    user.CodeFailTime = DateTime.Now.AddMinutes(30);
                    Update(user);
                    // 提示并跳转
                    _result = "激活邮件已发送,请查收邮件进行邮箱确认!链接30分钟内有效.";
                    return(QssResult.Success);
                }
                catch (Exception exception)
                {
                    // 保存失败
                    QssLogHelper.Log("保存邮箱失败", $"保存用户: {user.Name}({user.Account}) 的邮箱: {toEmail} 失败!失败原因:{exception.Message}", QssLogType.Error, exception);
                    _result = "保存邮箱失败!请重试.";
                    return(QssResult.Fail);
                }
            }
            _result = "发送激活邮件失败!请重试.";
            return(QssResult.Fail);
        }
Beispiel #8
0
        /// <summary>
        /// 获取用户
        /// </summary>
        /// <returns>处理结果</returns>
        public QssResult QssGetUserByEmail(string email, out User _user)
        {
            // 获得用户
            var user = Db.Users.Where(p => p.Email == email);

            Db.Questions.Where(p => Db.Users.Where(u => u.Id == p.Auditor.Id || u.Id == p.Creator.Id).Any());

            // 用户不存在
            if (!user.Any())
            {
                // 记录错误
                QssLogHelper.Log("找不到用户", "用户" + HttpContext.Current.User.Identity.Name + "已登录,却没有在数据库中找到该用户,可能是该用户修改了邮箱,但是并未注销登录!", QssLogType.Error);
                _user = null;
                return(QssResult.Fail);
            }

            // 有多个用户共用一个邮箱
            if (user.Count() > 1)
            {
                // 获取共用该邮箱的所有用户
                string strUser = "";
                foreach (var u in user)
                {
                    strUser += $"{u.Account}({u.Name}),";
                }
                // 记录错误
                QssLogHelper.Log("多个用户共用一个邮箱", "邮箱:" + HttpContext.Current.User.Identity.Name + "被多个用户[" + strUser.TrimEnd(',') + "]所共用!", QssLogType.Error);
                _user = null;
                return(QssResult.Error);
            }

            _user = user.FirstOrDefault();
            return(QssResult.Success);
        }
Beispiel #9
0
        /// <summary>
        /// 超级管理员登录
        /// </summary>
        /// <param name="account"></param>
        /// <param name="passWord"></param>
        /// <param name="_result"></param>
        /// <returns></returns>
        private QssResult AdministratorLogin(string password, out string _result)
        {
            var result = WebConfigService.GetAdministrator(out AdministratorModel admin);

            if (result == QssResult.Fail)
            {
                // 账号不存在
                _result = "账号或密码错误!";
                return(QssResult.Fail);
            }
            if (result == QssResult.Error)
            {
                _result = "系统出现严重错误,请查看系统日志记录!";
                return(QssResult.Error);
            }

            // 正确获取到一个账号且密码正确
            if (admin.Password == QssMD5Helper.QssGetMd5(admin.Account, password))
            {
                // 处理登录请求
                LoginHandle(QssEnvironment.AdministratorAccount, QssRoleType.Administrator.ToString());

                QssLogHelper.Log("登录成功", "管理员登录成功!", QssLogType.Info);
                // 跳转到管理员页面
                _result = "/Users/ManageSysNews";
                return(QssResult.Success);
            }

            // 密码错误
            QssLogHelper.Log("管理员密码错误", "用户以管理员的方式登录,账号正确,但是密码错误! 错误密码为:" + password, QssLogType.Warn);
            _result = "账号或密码错误!";
            return(QssResult.Fail);
        }
Beispiel #10
0
        /// <summary>
        /// 根据角色名获取角色
        /// </summary>
        /// <param name="name">角色名</param>
        /// <param name="role">返回的角色</param>
        /// <returns>处理结果</returns>
        public QssResult QssGetRoleByName(string name, out Role role)
        {
            var model = DbSession.RoleDal.GetEntities(p => p.Name == name);

            // 没有
            if (!model.Any())
            {
                role = null;
                QssLogHelper.Log("获取角色失败", "在获取角色: User 时发生错误!没有获取到该角色.", QssLogType.Error);
                return(QssResult.Fail);
            }
            // 有多个
            if (model.Count() > 1)
            {
                role = null;
                string roleList = "";
                foreach (var item in model)
                {
                    roleList += item.Id + ",";
                }
                QssLogHelper.Log("获取到多个同名角色", "在获取角色: " + name + " 时发生错误!获取到多个同名角色,角色ID[" + roleList.TrimEnd(',') + "]",
                                 QssLogType.Error);
                return(QssResult.Error);
            }

            // 正常获得一个
            role = model.FirstOrDefault();
            return(QssResult.Success);
        }
Beispiel #11
0
 /// <summary>
 /// 更新用户信息
 /// </summary>
 /// <param name="model">用户资料</param>
 /// <returns></returns>
 public QssResult QssUpdateUserInfo(QssSicauLoginHelper login, UserType type, out User user)
 {
     // 判断学生还是教师
     if (type == UserType.S)
     {
         string[] _stuInfo = login.GetStuInfo();
         if (_stuInfo.Length == 0)
         {
             QssLogHelper.Log("获取学生信息失败", "学生登录时,通过模拟登录教务网获取学生信息,但是并没有获取成功!", QssLogType.Info);
             user = null;
             return(QssResult.Fail);
         }
         var stuInfo = new UserInfoHandle(_stuInfo);
         return(QssUpdateUserInfo(stuInfo, out user));
     }
     else
     {
         string[] _thInfo = login.GetThInfo();
         if (_thInfo.Length == 0)
         {
             QssLogHelper.Log("获取教师信息失败", "教师登录时,通过模拟登录教务网获取教师信息,但是并没有获取成功!", QssLogType.Info);
             user = null;
             return(QssResult.Fail);
         }
         var thInfo = new UserInfoHandle(_thInfo);
         return(QssUpdateUserInfo(thInfo, out user));
     }
 }
Beispiel #12
0
        /// <summary>
        /// 保存投票内容
        /// </summary>
        /// <param name="quesId">投票Id</param>
        /// <param name="message">处理结果信息</param>
        /// <returns></returns>
        private QssResult QssCreateVoteContent(Vote vote, out string message)
        {
            // 存放转换过的选项
            var options = new List <GetVoteOption>();

            // 获取所有选项
            foreach (var option in vote.VoteOptions)
            {
                options.Add(new GetVoteOption {
                    Id = option.Id, Content = option.Content
                });
            }

            // 投票内容
            GetVoteModel voteModel = new GetVoteModel
            {
                // 全局信息
                Global = new GetVoteGlobal
                {
                    BeginTime        = vote.BeginTime,
                    BelongTo         = vote.BelongTo,
                    EndTime          = vote.EndTime,
                    Id               = vote.Id,
                    Introduct        = vote.Introduct,
                    IsBelongOrganize = vote.IsBelongOrganize,
                    Title            = vote.Title,
                    Num              = options.Count(),
                    MaxNum           = vote.MaxNum,
                    Type             = vote.Type.ToString(),
                    Publisher        = vote.Publisher
                },
                // 选项
                Options = options.OrderByDescending(p => p.Id).ToArray()
            };

            // 序列化
            vote.Content = JsonConvert.SerializeObject(voteModel);

            // 保存
            try
            {
                CurrentDal.Update(vote);
                DbSession.SaveChanges();

                // 保存成功
                message = "保存投票内容成功!";
                return(QssResult.Success);
            }
            catch (Exception exception)
            {
                // 保存失败
                message = $"保存投票内容失败!原因:{exception.Message}";
                QssLogHelper.Log("保存投票内容失败", $"在创建投票成功之后,保存投票内容失败! 原因:{exception.Message}", QssLogType.Error);
                return(QssResult.Fail);
            }
        }
Beispiel #13
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            ViewBag.ReturnUrl = returnUrl;
            if (ModelState.IsValid)
            {
                // 若是超级管理员
                // 因为超级管理员的账号不是教务网账号,是单独设置的,所以需要单独处理
                if (model.Account == QssEnvironment.AdministratorAccount)
                {
                    QssResult result = AdministratorLogin(model.Password, out string _result);
                    if (result != QssResult.Success)
                    {
                        ModelState.AddModelError("", _result);
                        return(View());
                    }
                    return(Redirect(_result));
                }

                // 模拟登陆确认用户合法
                var login    = new QssSicauLoginHelper();
                var userType = model.Account.Length >= 8 ? UserType.S : UserType.T;
                try
                {
                    if (login.Login(model.Account, model.Password, userType))
                    {
                        // 账号密码正确
                        // 开始更新用户信息
                        var result = UserService.QssUpdateUserInfo(login, userType, out User user);
                        if (result != QssResult.Success)
                        {
                            QssLogHelper.Log("更新用户信息失败", "用户登录时,更新用户信息失败!用户:" + model.Account, QssLogType.Error, $"{model.Account}({user.Name})");
                            ModelState.AddModelError("", "更新用户信息失败!请重试.");
                            return(View(model));
                        }

                        // 更新用户信息成功
                        // 开始处理登录请求
                        LoginHandle(user.Account, user.Role.Name + "|" + user.Name + "|" + user.Id);
                        QssLogHelper.Log("登录成功", "登录成功!", QssLogType.Info, $"{model.Account}({user.Name})");
                        // 跳转到AutoDealOrg进行自动加入或退出组织处理
                        return(RedirectToAction("AutoDealOrg", "Account", new { returnUrl = returnUrl }));
                    }
                }
                catch (Exception exception)
                {
                    ModelState.AddModelError("", "登录教务网失败!" + exception.Message);
                    QssLogHelper.Log("更新用户信息失败", "用户登录教务网失败!用户:" + model.Account, QssLogType.Error, exception);
                    return(View(model));
                }

                // 账号密码错误
                ModelState.AddModelError("", "登录失败,账号密码错误!或是教务网未评教,请评教后请重试.");
                return(View(model));
            }
            return(View(model));
        }
Beispiel #14
0
        /// <summary>
        /// 初始化系统
        /// </summary>
        /// <returns>结果</returns>
        public string DefaultSystem()
        {
            if (DbSession.RoleDal.GetEntities(p => true).Any())
            {
                // 已经初始化
                return("初始化系统成功!");
            }

            // 初始化角色
            var list = new List <Role>
            {
                new Role {
                    Name = QssRoleType.Administrator.ToString()
                },
                new Role {
                    Name = QssRoleType.SysAdmin.ToString()
                },
                new Role {
                    Name = QssRoleType.Admin.ToString()
                },
                new Role {
                    Name = QssRoleType.User.ToString()
                }
            };

            DbSession.RoleDal.AddRange(list);

            // 初始化网站配置
            string email     = "*****@*****.**";
            var    webConfig = new WebConfig()
            {
                // 初始化超级管理员
                Account  = QssEnvironment.AdministratorAccount,
                Email    = email,
                Password = QssMD5Helper.QssGetMd5(QssEnvironment.AdministratorAccount, "123456"),
                Tel      = "18227592876"
            };

            DbSession.WebConfigDal.Add(webConfig);

            try
            {
                // 保存配置
                DbSession.SaveChanges();
                // 成功
                QssLogHelper.Log("初始化系统成功", "初始化系统成功!", QssLogType.Info);
                return($"初始化系统成功!<br />超级管理员账号:{QssEnvironment.AdministratorAccount}<br />密码:123456 <br/>邮箱:{email}<br />电话:18227592876<br/>请登录之后尽快修改密码、邮箱和电话.");
            }
            catch (Exception ex)
            {
                // 保存失败
                QssLogHelper.Log("初始化系统失败", "初始化系统失败,失败原因: " + ex.Message, QssLogType.Fatal);
                return("初始化系统失败,失败原因: " + ex.Message);
            }
        }
        /// <summary>
        /// 获取问卷/投票
        /// </summary>
        /// <param name="qvid">问卷/投票Id</param>
        /// <returns></returns>
        public string QssGetContent(int qvid)
        {
            var qv = GetEntity(qvid);

            if (qv == null)
            {
                QssLogHelper.Log($"获取{qvText}失败", $"找不到Id:{qvid} 的{qvText}!", QssLogType.Info);
                return("{}");
            }

            return(qv.Content);
        }
Beispiel #16
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));
        }
Beispiel #17
0
        /// <summary>
        /// 发送站内信和邮件
        /// </summary>
        /// <param name="message">处理结果信息</param>
        /// <returns></returns>
        public QssResult Send(out string message)
        {
            // 获取信息
            if (GetMessage() != QssResult.Success)
            {
                message = this.message;
                return(QssResult.Fail);
            }

            // 发送邮件
            List <EmailModel> emailList = new List <EmailModel>();

            foreach (var item in receives)
            {
                emailList.Add(new EmailModel {
                    ToEmail = item.Email, ToName = item.Name, Subject = title, BodyInfo = content
                });
            }
            if (currentQvCreator != null)
            {
                emailList.Add(new EmailModel {
                    ToEmail = currentQvCreator.Email, ToName = currentQvCreator.Name, Subject = creatorTitle, BodyInfo = creatorContent
                });
            }
            QssEmailHelper.EnqueueEamil(emailList);

            // 发送站内信
            try
            {
                if (currentQvCreator != null)
                {
                    DbSession.LetterDal.Add(new Letter {
                        Title = creatorTitle, Content = creatorContent, CreateTime = DateTime.Now, Receive = new List <User> {
                            currentQvCreator
                        }
                    });
                }
                DbSession.LetterDal.Add(new Letter {
                    Title = title, Content = content, CreateTime = DateTime.Now, Receive = receives
                });
                DbSession.SaveChanges();
                // 发送成功
                message = $"{qvText} {currentQv.Title} 状态更改成功!";
                return(QssResult.Success);
            }
            catch (Exception exception)
            {
                message = "发送站内信失败!";
                QssLogHelper.Log("发送站内信失败", $"更改{qvText} {currentQv.Title} 状态后,发送站内信失败!失败原因:{exception}", QssLogType.Error);
                return(QssResult.Fail);
            }
        }
        /// <summary>
        /// 获取创建者
        /// </summary>
        /// <returns></returns>
        private QssResult GetCreator()
        {
            // 获取创建者
            var creator = currentOrg.Admin;

            if (creator == null)
            {
                message = "获取组织创建者失败!";
                QssLogHelper.Log("获取组织创建者失败", $"在更改组织{currentOrg.Id} 状态时,获取组织创建者失败!", QssLogType.Error);
                return(QssResult.Fail);
            }
            receives.Add(creator);

            return(QssResult.Success);
        }
Beispiel #19
0
 /// <summary>
 /// 提交删除问卷
 /// </summary>
 /// <param name="text">提示文本信息</param>
 /// <param name="message">处理结果信息</param>
 /// <returns></returns>
 private QssResult QssSaveDeleteQues(string text, out string message)
 {
     try
     {
         DbSession.SaveChanges();
         message = "";
         return(QssResult.Success);
     }
     catch (Exception exception)
     {
         message = $"删除{text}失败!原因:" + exception.Message;
         QssLogHelper.Log($"删除{text}失败", $"删除{text}时,保存上下文失败!", QssLogType.Error);
         return(QssResult.Fail);
     }
 }
Beispiel #20
0
        /// <summary>
        /// 保存问卷填写记录
        /// </summary>
        /// <param name="question">当前填写的问卷</param>
        /// <param name="wtQuesSubjects">问卷的答案和内容</param>
        /// <param name="message">处理结果信息</param>
        /// <returns></returns>
        public QssResult QssSaveQuesWtLog(Question question, GetWtQuesSubject[] wtQuesSubjects, User user, out string message)
        {
            // 填写记录
            var wtQues = new GetWtQuesModel
            {
                Global = new GetQuesGlobal
                {
                    Id               = question.Id,
                    Title            = question.Title,
                    IsBelongOrganize = question.IsBelongOrganize,
                    BelongTo         = question.BelongTo,
                    Num              = wtQuesSubjects.Count(),
                    BeginTime        = question.BeginTime,
                    EndTime          = question.EndTime,
                    Introduct        = question.Introduct,
                    Publisher        = question.Publisher
                },
                Subjects = wtQuesSubjects
            };

            var wtlog = new WtLog()
            {
                QuesVoteId = question.Id,
                Type       = QssWtLogType.Question,
                Content    = JsonConvert.SerializeObject(wtQues),
                User       = user,
                WtTime     = DateTime.Now
            };

            // 参与人数统计
            question.JoinNum++;

            try
            {
                DbSession.QuestionDal.Update(question);
                DbSession.WtLogDal.Add(wtlog);
                DbSession.SaveChanges();

                message = "保存填写记录成功!";
                return(QssResult.Success);
            }
            catch (Exception exception)
            {
                message = "保存填写记录失败! 原因" + exception.Message;
                QssLogHelper.Log("保存填写记录失败", "在保存填写记录到记录表中时失败,原因:" + exception.Message, QssLogType.Error, exception);
                return(QssResult.Fail);
            }
        }
Beispiel #21
0
        /// <summary>
        /// 添加系统管理员
        /// </summary>
        /// <param name="account">管理员账号</param>
        /// <param name="message">处理结果信息</param>
        /// <returns></returns>
        public QssResult QssAddSysAdmin(string account, out string message)
        {
            // 检查邮箱和电话
            var result = DbSession.UserDal.QssGetUserByAccount(account, out User user);

            if (result != QssResult.Success || (string.IsNullOrWhiteSpace(user.Email) || string.IsNullOrWhiteSpace(user.Tel) || user.ACode != ""))
            {
                message =
                    result != QssResult.Success ? "获取该用户失败!" :
                    string.IsNullOrWhiteSpace(user.Email) ? "该用户未绑定邮箱!" :
                    string.IsNullOrWhiteSpace(user.Tel) ? "该用户未填写电话!" :
                    "该用户未激活邮箱!";
                return(QssResult.Fail);
            }

            var roles = DbSession.RoleDal.GetEntities(p => p.Name == QssRoleType.SysAdmin.ToString());

            if (!roles.Any())
            {
                message = "获取角色失败!";
                QssLogHelper.Log("获取角色失败", "在添加系统管理员时,获取系统管理员角色失败!", QssLogType.Error);
                return(QssResult.Fail);
            }
            if (roles.Count() > 1)
            {
                message = "获取角色失败!";
                QssLogHelper.Log("获取角色错误", "在添加系统管理员时,获取到多个系统管理员角色!", QssLogType.Error);
                return(QssResult.Fail);
            }

            // 添加
            try
            {
                user.Role = roles.FirstOrDefault();
                DbSession.UserDal.Update(user);
                DbSession.SaveChanges();

                message = "添加成功!";
                return(QssResult.Success);
            }
            catch (Exception exception)
            {
                message = "添加失败!" + exception.Message;
                QssLogHelper.Log("添加系统管理员失败", "添加系统管理员,在保存更改用户角色时出错!原因:" + exception.Message, QssLogType.Error, exception);
                return(QssResult.Fail);
            }
        }
Beispiel #22
0
        /// <summary>
        /// 保存问卷题目选项
        /// </summary>
        /// <param name="options">题目选项列表</param>
        /// <param name="message">处理结果信息</param>
        /// <returns></returns>
        public QssResult QssSaveQuesOption(JArray options, QuesSubject quesSubject, out List <GetWtQuesOption> wtOptions, out string message)
        {
            // 存放选项列表和选项的临时变量
            var getWtOptions = new List <GetWtQuesOption>();

            // 保存变量
            foreach (JObject option in options)
            {
                int optionId   = Convert.ToInt32(option["Id"]);
                var quesOption = quesSubject.QuesOptions.FirstOrDefault(o => o.Id == optionId);
                if (quesOption == null)
                {
                    wtOptions = null;
                    message   = "获取选项失败!";
                    QssLogHelper.Log("获取选项失败", "在保存填写记录时,获取题目选项失败!", QssLogType.Error);
                    return(QssResult.Fail);
                }

                quesOption.Num++;
                DbSession.QuesOptionDal.Update(quesOption);
                getWtOptions.Add(new GetWtQuesOption()
                {
                    Id = quesOption.Id
                });
            }

            // 保存
            try
            {
                DbSession.SaveChanges();

                // 保存成功
                wtOptions = getWtOptions;
                message   = "保存问卷结果成功!";
                return(QssResult.Success);
            }
            catch (Exception exception)
            {
                // 保存失败
                wtOptions = null;
                message   = "保存问卷结果失败! 失败原因:" + exception;
                QssLogHelper.Log("保存问卷结果失败", "在填写记录时,保存问卷结果失败!", QssLogType.Error, exception);
                return(QssResult.Fail);
            }
        }
Beispiel #23
0
        /// <summary>
        /// 获取组织管理员
        /// </summary>
        /// <param name="type">管理员类型</param>
        /// <returns></returns>
        private QssResult GetOrgAdmin(GetOrgAdminType type)
        {
            List <Organize> orgList = new List <Organize>();

            if (type == GetOrgAdminType.orgAdmin)
            {
                var org = DbSession.OrganizeDal.GetEntities(p => p.Id == currentQv.BelongTo, "Admin").FirstOrDefault();
                if (org != null)
                {
                    orgList.Add(org);
                }
            }
            else
            {
                // 获取可填写组织和可查看组织
                if (type == GetOrgAdminType.rdOrgAdmin)
                {
                    orgList.AddRange(currentQv is Question ? DbSession.QuestionDal.GetRdOrg(currentQv as Question) : DbSession.VoteDal.GetRdOrg(currentQv as Vote));
                }
                else
                {
                    orgList.AddRange(currentQv is Question ? DbSession.QuestionDal.GetWtOrg(currentQv as Question) : DbSession.VoteDal.GetWtOrg(currentQv as Vote));
                }
            }

            if (!orgList.Any())
            {
                message = "获取组织失败!";
                QssLogHelper.Log("获取组织失败", $"在发送站内信和邮件时,获取组织失败!{qvText}:{currentQv.Id} ", QssLogType.Error);
                return(QssResult.Fail);
            }

            var orgAIds  = orgList.Select(x => x.Admin.Id);
            var orgAdmin = DbSession.UserDal.GetEntities(p => orgAIds.Contains(p.Id));

            if (!orgAdmin.Any())
            {
                message = "获取组织管理员失败!";
                QssLogHelper.Log("获取组织管理员失败", $"在发送站内信和邮件时,获取组织成功,但是获取组织管理员却失败了!{qvText}:{currentQv.Id} ", QssLogType.Error);
                return(QssResult.Fail);
            }
            receives.AddRange(orgAdmin);
            return(QssResult.Success);
        }
Beispiel #24
0
        /// <summary>
        /// 删除系统管理员
        /// </summary>
        /// <param name="uid">管理员Id</param>
        /// <param name="message">处理结果信息</param>
        /// <returns></returns>
        public QssResult QssDelSysAdmin(int uid, out string message)
        {
            var user = CurrentDal.GetEntity(uid);

            if (user == null)
            {
                message = "获取该用户失败!";
                return(QssResult.Fail);
            }

            var isOrgAdmin = user.JoinOrganizes.Where(p => p.Admin.Id == user.Id).Any();
            var roleName   = (isOrgAdmin ? QssRoleType.Admin.ToString() : QssRoleType.User.ToString());

            var roles = DbSession.RoleDal.GetEntities(p => p.Name == roleName);

            if (!roles.Any())
            {
                message = "获取角色失败!";
                QssLogHelper.Log("获取角色失败", $"在添加系统管理员时,获取{(isOrgAdmin ? "组织管理员" : "普通用户")}角色失败!", QssLogType.Error);
                return(QssResult.Fail);
            }
            if (roles.Count() > 1)
            {
                message = "获取角色失败!";
                QssLogHelper.Log("获取角色错误", $"在添加系统管理员时,获取到多个{(isOrgAdmin ? "组织管理员" : "普通用户")}角色!", QssLogType.Error);
                return(QssResult.Fail);
            }

            try
            {
                user.Role = roles.FirstOrDefault();
                DbSession.UserDal.Update(user);
                DbSession.SaveChanges();

                message = "删除成功!";
                return(QssResult.Success);
            }
            catch (Exception exception)
            {
                QssLogHelper.Log("删除系统管理员失败", "在保存用户角色变更时失败!原因:" + exception.Message, QssLogType.Error, exception);
                message = "删除失败!";
                return(QssResult.Fail);
            }
        }
Beispiel #25
0
        /// <summary>
        /// 保存投票填写记录
        /// </summary>
        /// <param name="options">投票选项</param>
        /// <param name="vote">当前投票</param>
        /// <param name="wtOptions">填写记录</param>
        /// <param name="message"></param>
        /// <returns></returns>
        public QssResult QssSaveVoteWtLog(JArray options, Vote vote, out List <GetWtVoteOption> wtOptions, out string message)
        {
            // 答案选项
            wtOptions = options.Select(x => new GetWtVoteOption {
                Id = Convert.ToInt32(x["Id"])
            }).ToList();

            // 校验数量
            if (vote.MaxNum < wtOptions.Count())
            {
                message   = "投票个数超过了指定的个数!";
                wtOptions = null;
                return(QssResult.Fail);
            }

            // 保存
            foreach (var item in wtOptions)
            {
                var option = vote.VoteOptions.FirstOrDefault(v => v.Id == item.Id);
                if (option == null)
                {
                    wtOptions = null;
                    message   = "获取选项失败!";
                    QssLogHelper.Log("获取选项失败", "在保存填写记录时,获取投票选项失败!", QssLogType.Error);
                    return(QssResult.Fail);
                }
                option.Num++;
                CurrentDal.Update(option);
            }

            try
            {
                DbSession.SaveChanges();

                message = "保存填写记录成功!";
                return(QssResult.Success);
            }
            catch (Exception exception)
            {
                message = "保存填写记录失败!";
                QssLogHelper.Log("保存投票选项失败", "在保存填写记录时,保存投票选项记录失败!", QssLogType.Error, exception);
                return(QssResult.Fail);
            }
        }
Beispiel #26
0
        /// <summary>
        /// 公告详情页面
        /// </summary>
        /// <param name="id">公告Id</param>
        /// <returns></returns>
        public ActionResult SysNewDetail(int id)
        {
            var model = SysNewsService.GetEntity(id);

            if (model == null)
            {
                // 没有该公告
                QssLogHelper.Log("找不到公告", "请求显示公告: [" + id + "],却找不到该公告!", QssLogType.Error);
                return(RedirectToAction("ErrorHandle", new { id = 400 }));
            }

            // 上一篇
            ViewBag.SysNewsFront = SysNewsService.GetFrontSysNews(id);
            // 下一篇
            ViewBag.SysNewsNext = SysNewsService.GetNextSysNews(id);

            // 返回详情
            return(View(model));
        }
Beispiel #27
0
        /// <summary>
        /// 添加公告
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="content">内容</param>
        /// <param name="message">处理信息</param>
        /// <returns></returns>
        public QssResult CreateSysNews(string title, string content, out string message)
        {
            try
            {
                DbSession.SysNewsDal.Add(new SysNews {
                    Title = title, Content = content, CreateTime = DateTime.Now
                });
                DbSession.SaveChanges();

                message = "添加成功!";
                return(QssResult.Success);
            }
            catch (Exception exception)
            {
                QssLogHelper.Log("添加公告失败", "添加系统公告失败!原因:" + exception.Message, QssLogType.Error, exception);
                message = "添加失败!";
                return(QssResult.Fail);
            }
        }
Beispiel #28
0
        /// <summary>
        /// 保存投票结果
        /// </summary>
        /// <param name="vote">当前投票</param>
        /// <param name="message">处理结果信息</param>
        /// <returns></returns>
        private QssResult QssSaveResult(Vote vote, out string message)
        {
            var options = vote.VoteOptions.Select(p => new GetResultVoteOption {
                Id = p.Id, Content = p.Content, Num = p.Num
            }).OrderByDescending(p => p.Id);

            var voteResult = new GetResultVoteModel
            {
                Global = new GetVoteGlobal
                {
                    BeginTime        = vote.BeginTime,
                    BelongTo         = vote.BelongTo,
                    EndTime          = vote.EndTime,
                    Id               = vote.Id,
                    Introduct        = vote.Introduct,
                    IsBelongOrganize = vote.IsBelongOrganize,
                    MaxNum           = vote.MaxNum,
                    Num              = options.Count(),
                    Title            = vote.Title,
                    Type             = vote.Type.ToString(),
                    Publisher        = vote.Publisher
                },
                Options = options.ToArray()
            };

            vote.Result = JsonConvert.SerializeObject(voteResult);;

            try
            {
                CurrentDal.Update(vote);
                DbSession.SaveChanges();

                message = "保存投票结果成功!";
                return(QssResult.Success);
            }
            catch (Exception exception)
            {
                QssLogHelper.Log("保存投票结果失败", "保存投票结果失败! 原因:" + exception.Message, QssLogType.Error, exception);
                message = "保存投票结果成功!";
                return(QssResult.Success);
            }
        }
Beispiel #29
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="oldPasswd">旧密码</param>
        /// <param name="passwd">新密码</param>
        /// <returns></returns>
        public QssResult ChangePassword(string oldPasswd, string passwd, out string _result)
        {
            QssResult result = GetAdministrator(out AdministratorModel admin);

            // 获取成功
            if (result == QssResult.Success)
            {
                // 旧密码正确
                if (admin.Password == QssMD5Helper.QssGetMd5(admin.Account, oldPasswd))
                {
                    try
                    {
                        var config = DbSession.WebConfigDal.GetEntities(p => true).FirstOrDefault();
                        config.Password = QssMD5Helper.QssGetMd5(admin.Account, passwd);
                        DbSession.WebConfigDal.Update(config);
                        // 保存新密码
                        DbSession.SaveChanges();

                        // 修改密码成功
                        _result = "修改密码成功!";
                        return(QssResult.Success);
                    }
                    catch (Exception exception)
                    {
                        // 保存失败
                        QssLogHelper.Log("修改密码错误", "超级管理员在修改密码时保存新密码出现错误!错误原因: " + exception.Message, QssLogType.Error, exception);
                        _result = "修改密码失败!请重试.";
                        return(QssResult.Fail);
                    }
                }

                // 旧密码错误
                QssLogHelper.Log("管理员密码错误", "超级管理员在修改密码,但是旧密出现错误! ", QssLogType.Warn);
                _result = "旧密码错误!登录已被注销.";
                return(QssResult.Error);
            }

            // 没有正确获取到管理员
            _result = "系统出现严重错误!请查看日志.";
            return(QssResult.Error);
        }
Beispiel #30
0
        /// <summary>
        /// 标记已读
        /// </summary>
        /// <param name="id">站内信Id</param>
        /// <param name="message">处理结果信息</param>
        /// <returns></returns>
        public QssResult QssMarkLetter(QssMarkLetterType type, int id, out string message)
        {
            var letter = DbSession.LetterDal.GetEntities(p => p.Id == id, type == QssMarkLetterType.Read ? "IsRead" : "IsDelete").FirstOrDefault();

            if (letter == null)
            {
                message = "获取该站内信失败!";
                return(QssResult.Fail);
            }

            if (CurrentUser == null)
            {
                message = "获取当前用户失败!";
                return(QssResult.Fail);
            }

            try
            {
                if (type == QssMarkLetterType.Read)
                {
                    letter.IsRead.Add(CurrentUser);
                }
                else
                {
                    letter.IsDelete.Add(CurrentUser);
                }
                DbSession.LetterDal.Update(letter);
                DbSession.SaveChanges();

                message = "标记成功!";
                return(QssResult.Success);
            }
            catch (Exception exception)
            {
                QssLogHelper.Log("标记站内信失败", $"将站内信:{letter.Title} 标记为{(type == QssMarkLetterType.Read ? "已读" : "已删除")}时失败! 原因:{exception.Message}", QssLogType.Error, exception);
                message = "标记失败!";
                return(QssResult.Success);
            }
        }