public async Task <IActionResult> Register_Teacher(RegisterTeacherViewmodel viewmodel)
        {
            if (!ModelState.IsValid)
            {
                throw new ValidatorException();
            }
            if (!_SmsCodeValidatorService.Validate(viewmodel.Mobile, viewmodel.Code))
            {
                throw new ValidatorException("验证码不正确");
            }
            var teacher = await _Context.Teachers.AddAsync(new Models.Teacher {
                Introduce = viewmodel.Introduce,
                Mobile    = viewmodel.Mobile,
                Name      = viewmodel.Name,
                Password  = MD5Builder.Builder32Hash(viewmodel.Password),
                Picture   = viewmodel.Picture
            });

            int result = await _Context.SaveChangesAsync();

            if (result == 0)
            {
                throw new ValidatorException("该教师账号已存在");
            }
            return(Json(teacher.Entity));
        }
        public async Task <IActionResult> Register_Student(RegisterStudentViewmodel viewmodel)
        {
            if (!ModelState.IsValid)
            {
                throw new ValidatorException();
            }
            if (!_SmsCodeValidatorService.Validate(viewmodel.Mobile, viewmodel.Code))
            {
                throw new ValidatorException("验证码不正确");
            }
            var student = await _Context.Students.AddAsync(new Models.Student()
            {
                Mobile   = viewmodel.Mobile,
                NickName = viewmodel.NickName,
                Password = MD5Builder.Builder32Hash(viewmodel.Password),
                Picture  = viewmodel.Picture
            });

            int result = await _Context.SaveChangesAsync();

            if (result == 0)
            {
                throw new ValidatorException("用户已存在,无法注册");
            }
            return(Json(student.Entity));
        }
        public async Task <IActionResult> Student_Update([FromBody] StudentUpdateViewModel viewModel)
        {
            var student = await _Context.Students.FirstOrDefaultAsync(v => v.ID == UserID);

            if (student == null)
            {
                throw new ValidatorException("不存在该用户");
            }

            StudentUpdateIntegrationEvent @event = null;

            if (viewModel.Password != null)
            {
                student.Password = MD5Builder.Builder32Hash(viewModel.Password);
            }
            if (viewModel.Picture != null)
            {
                student.Picture = viewModel.Picture;
            }
            if (viewModel.NickName != null)
            {
                student.NickName = viewModel.NickName;
                @event           = new StudentUpdateIntegrationEvent(UserID, viewModel.NickName);
            }

            using (var trans = _Context.Database.BeginTransaction(_CapPublisher, autoCommit: true))
            {
                if (@event != null)
                {
                    await _CapPublisher.PublishAsync("ELearn.UserCenter.StudentUpdate", @event);
                }
            }

            return(Json(true));
        }
        public async Task <IActionResult> Teacher_LoginByPassword(LoginByPasswordViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                throw new ValidatorException();
            }
            var teacher = await _Context.Teachers.AsNoTracking().Where(vn => vn.Mobile == viewModel.Mobile).FirstOrDefaultAsync();

            if (teacher == null)
            {
                throw new ValidatorException("不存在该用户");
            }
            if (teacher.Password != MD5Builder.Builder32Hash(viewModel.Password))
            {
                throw new ValidatorException("登陆密码不正确");
            }
            return(Json(teacher));
        }
    private static void CreateAssetList(string assetBundleFullPath)
    {
        EditorUtility.DisplayProgressBar("CreateAssetsList", "progress: ", 0);
        //读取所有文件,并创建md5文件
        HotUpdateAssetsList hotUpdateAssetsList = new HotUpdateAssetsList();
        DirectoryInfo       directoryInfo       = new DirectoryInfo(assetBundleFullPath);

        FileInfo[] allAsset = directoryInfo.GetFiles();
        for (int i = 0; i < allAsset.Length; i++)
        {
            EditorUtility.DisplayProgressBar("CreateAssetsList", "progress: ", 1f * i / allAsset.Length);
            FileInfo fileInfo          = allAsset[i];
            string   fullName          = fileInfo.FullName.Replace("\\", "/");
            string   rootDirectoryPath = assetBundleFullPath.Replace("\\", "/");
            string   assetName         = fullName.Substring(rootDirectoryPath.Length + 1);
            if (assetName == assetListName)
            {
                continue;
            }
            if (assetName.Split('.').Length > 0)
            {
                assetName = assetName.Split('.')[0];
            }
            //StreamReader fileStream = fileInfo.OpenText();
            //string fileStr = fileStream.ReadToEnd();
            //fileStream.Close();
            string             md5 = MD5Builder.BuildMD5(fileInfo.FullName);
            HotUpdateAssetItem hotUpdateAssetItem = new HotUpdateAssetItem(assetName, md5);
            hotUpdateAssetsList.assetList.Add(hotUpdateAssetItem);
        }
        EditorUtility.ClearProgressBar();
        EditorUtility.DisplayProgressBar("Write \"CreateAssetsList to file\" ", "progress: ", 0);
        string assetListJsonStr = JsonUtility.ToJson(hotUpdateAssetsList);
        string assetListPath    = Path.Combine(assetBundleFullPath, assetListName);

        File.WriteAllText(assetListPath, assetListJsonStr);
        EditorUtility.ClearProgressBar();
    }
    public override bool IsAssetRight()
    {
        string assetMD5 = MD5Builder.BuildMD5(asset);

        return(string.Compare(assetMD5, this.md5) == 0);
    }