public void AdministartorTest()
        {
            SchoolAdministrator sc = new SchoolAdministrator()
            {
                AdministratorAccount          = "1316279031",
                AdministratorPassword         = "******",
                CreateAdminitratorDetialDatas = new CreateAdminitratorDetialData()
                {
                    AdministratorAuthority = "课目管理",
                    CreatedTime            = DateTime.Now,
                    Email        = "*****@*****.**",
                    IsFreeze     = false,
                    Message      = "嗯嗯",
                    ValidateCode = "4312"
                }
            };
            ISchoolAdministratorDal dal = new SchoolAdministratorDal("EFDAL");
            var  num = dal.AddEntity(sc);
            bool bor = false;

            if (num > 0)
            {
                bor = true;
                Console.WriteLine("成功");
            }
            Assert.AreEqual(bor, true);
        }
Beispiel #2
0
        public void EfUpdate()
        {
            ISchoolAdministratorDal dal = new SchoolAdministratorDal("EFDAL");
            StudentDb stu    = new StudentDb();
            var       entity = stu.SchoolAdministrators.FirstOrDefault(x => x.AdministratorAccount == "1316279031");
            //entity.AdministratorPassword = "******";
            //entity.CreateAdminitratorDetialDatas.CreatedTime = DateTime.Now.AddDays(5);
            //entity.CreateAdminitratorDetialDatas.Email = "*****@*****.**";
            //entity.CreateAdminitratorDetialDatas.IsFreeze = true;
            bool isbool            = false;
            SchoolAdministrator sc = new SchoolAdministrator()
            {
                AdministratorAccount          = "1316279031",
                AdministratorPassword         = "******",
                CreateAdminitratorDetialDatas = new CreateAdminitratorDetialData()
                {
                    AdministratorAuthority = "校长",
                    CreatedTime            = DateTime.Now.Date,
                    Email    = "*****@*****.**",
                    IsFreeze = false,
                    Message  = "Heelo"
                }
            };

            Console.WriteLine(entity.AdministratorAccount);
            //isbool=dal.Update(entity);
            stu.Entry(entity).CurrentValues.SetValues(sc);
            isbool = stu.SaveChanges() > 0;
            Assert.AreEqual(isbool, true);
        }
        public ActionResult AdministartorsRegisterDetials(CreateAdminitratorDetialData cre)
        {
            var or = Session["admin"] is SchoolAdministrator;
            SchoolAdministrator schoolAdministrator = null;

            if (or == false)
            {
                ModelState.AddModelError("RegisterError", "出现了意外的错误");
                return(View("AdministartorsRegister"));
            }
            schoolAdministrator = Session["admin"] as SchoolAdministrator;
            bool resiterIS = true;

            try
            {
                re.RegisterBll(schoolAdministrator, cre, dal);
                //用户注册后发送一个带QueryString的URL给校长
                var rightUrl = Url.Action("SeendValidateCode");
                var LeftUrl  = Request.Url.GetLeftPart(UriPartial.Authority) + rightUrl;
                try
                {
                    var entity = dal.GetEntity(schoolAdministrator.AdministratorAccount);
                    LeftUrl = LeftUrl + "?account=" + entity.AdministratorAccount + "&email=" + entity.CreateAdminitratorDetialDatas.Email;
                    ICreateEmail createEmail = new CreateEnail();
                    bool         Ok          = createEmail.SeendEmail(LeftUrl, entity.CreateAdminitratorDetialDatas.Email, entity.CreateAdminitratorDetialDatas.Message, entity.AdministratorAccount, entity.CreateAdminitratorDetialDatas.AdministratorAuthority);
                    if (!Ok)
                    {
                        throw new ArgumentException("邮件发送失败");
                    }
                }
                catch (Exception e)
                {
                    ErrorDatabase error = new ErrorDatabase()
                    {
                        DateTime     = DateTime.Now,
                        ErrorMessage = e.StackTrace.ToString()
                    };
                    errorDal.AddEntity(error);
                    resiterIS = false;
                    ModelState.AddModelError("RegisterError", "验证功能暂时失败请您后续登陆网站发送验证");
                }
            }
            catch (Exception e)
            {
                ErrorDatabase error = new ErrorDatabase()
                {
                    DateTime     = DateTime.Now,
                    ErrorMessage = e.StackTrace.ToString()
                };
                errorDal.AddEntity(error);
                resiterIS = false;
                ModelState.AddModelError("RegisterError", "您输入的邮箱已被占用");
            }
            if (resiterIS)
            {
                return(Content("完成"));
            }
            return(View("AdministartorsRegister"));
        }
        /// <summary>
        /// 如果返回True表示数据库中已存在该用户
        /// </summary>
        /// <param name="schoolAdministrator">用户提交的注册账户信息</param>
        /// <param name="dal">访问层</param>
        /// <returns></returns>
        public bool DatabaseHasEntity(SchoolAdministrator schoolAdministrator, ISchoolAdministratorDal dal)
        {
            var entitys = dal.GetEntityForExpress(x => x.AdministratorAccount == schoolAdministrator.AdministratorAccount);

            if (!(entitys.Count() <= 0))
            {
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// 完善管理员注册的系统信息,并将权限冻结
        /// </summary>
        /// <param name="school">SchoolAdministrator</param>
        /// <param name="cre">CreateAdminitratorDetialData</param>
        /// <param name="dal">ISchoolAdministratorDal</param>
        /// <returns>true/false</returns>
        public bool RegisterBll(SchoolAdministrator school, CreateAdminitratorDetialData cre, ISchoolAdministratorDal dal)
        {
            school.AdministratorPassword = CreateSha256Passsword(school.AdministratorPassword);
            cre.CreatedTime = DateTime.Now;
            cre.IsFreeze    = true;//IsFreeze:是否冻结
            school.CreateAdminitratorDetialDatas = cre;
            var num = dal.AddEntity(school);

            return(num > 0);
        }
        public ActionResult AdministartorsRegister(SchoolAdministrator schoolAdministrator)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("RegisterError", "请检查您的登录信息");
                return(View());
            }

            if (re.DatabaseHasEntity(schoolAdministrator, dal))
            {
                ModelState.AddModelError("RegisterError", "该账户已被占用");
                return(View());
            }
            else
            {
                Session["admin"] = schoolAdministrator;
            }
            return(View("AdministartorsRegisterDetials"));
        }
Beispiel #7
0
        public ActionResult XzViews()
        {
            var adminObj  = Session["AdministratorObject"] as AdministratorObject;
            var account   = adminObj.Account;
            var authority = adminObj.Authority;

            if (authority != "学籍管理")
            {
                return(new HttpStatusCodeResult(404, "您没有权限查看此页面"));
            }
            IGetEntity get                     = new GetEntity();
            ISchoolAdministratorDal sc         = new SchoolAdministratorDal(ConfigurationManager.AppSettings["assembly"]);
            SchoolAdministrator     adminTable = new SchoolAdministrator();
            var jsonData = get.GetEntitys(x => true, sc).ToList();
            //将对象序列化为JSON格式
            var json = CreateJson(jsonData);

            return(Json(json, JsonRequestBehavior.AllowGet));
        }
        public bool CreateValidateSeendToEmail(SchoolAdministrator account, string email, IRegisterValidateCodeDal dal, ISchoolAdministratorDal scdal)
        {
            bool   CreateGuidIsTrue = true;
            string guid             = "";

            //创建验证码并发送使用全球唯一标识符
            try
            {
                guid = Guid.NewGuid().ToString();
                account.ValidateCodes = new RegisterAdministartorValidateCode()
                {
                    ValidateCode = guid
                };
                scdal.Update(account);
            }
            catch (Exception e)
            {
                IErrorDatabaseDal errorDal = new ErrorDatabaseDal(ConfigurationManager.AppSettings["assembly"]);
                ErrorDatabase     error    = new ErrorDatabase()
                {
                    DateTime     = DateTime.Now,
                    ErrorMessage = e.StackTrace.ToString()
                };
                errorDal.AddEntity(error);
                CreateGuidIsTrue = false;
            }

            if (CreateGuidIsTrue)
            {
                ICreateEmail cre     = new CreateEnail();
                var          seendOk = cre.SeendEmail(account.AdministratorAccount, email, guid);
                if (!seendOk)
                {
                    CreateGuidIsTrue = false;
                }
            }
            return(CreateGuidIsTrue);
        }
        public bool ValidateAccount(SchoolAdministrator administrator, ISchoolAdministratorDal dal)
        {
            bool IsLog         = true;
            bool createdSha256 = true;

            try
            {
                var entity = dal.GetEntity(administrator.AdministratorAccount);
                ICreateSha256Passwrod sha256 = new AdministratorRegisterBll();
                try
                {
                    var sha256Password = sha256.CreateSha256Passsword(administrator.AdministratorPassword);
                    if (sha256Password != entity.AdministratorPassword)
                    {
                        IsLog = false;
                    }
                }
                catch (Exception e)
                {
                    throw  new ArgumentException("sha256创建失败");
                    createdSha256 = false;
                }
            }
            catch (Exception e)
            {
                if (createdSha256)
                {
                    throw new NullReferenceException("不存在该账户");
                }
                else
                {
                    throw new ArgumentException(e.Message);
                }
            }
            return(IsLog);
        }