/// <summary> /// Обработчик события выбора учебного предмета из списка /// </summary> private void SelectSubject() => controller.CreatePresenter <TestsPresenter, Subject>().Run ( _repository .Get() .First(subject => subject.Id == view.SelectedSubjectId) );
/// <summary> /// Обработчик выбора варианта ответа /// </summary> private void SelectAnswer() { if (!_selectedAnswers.Keys.Contains(view.SelectedAnswerId)) { if (_rightAnswersCount == 1) { _selectedAnswers.Clear(); } var selectedAnswer = _repository .Get() .First(answer => answer.Id == view.SelectedAnswerId); _selectedAnswers.Add(selectedAnswer.Id, selectedAnswer); } }
/// <summary> /// 是否微信已经认证过 /// </summary> /// <param name="code">用户code</param> /// <returns></returns> public WeixinAuthUserStatus IsWeiXinAuth(string code) { var weixinauthresult = new WeixinAuthUserStatus() { AuthStatus = false, UserId = null }; if (string.IsNullOrEmpty(code)) { return(weixinauthresult); } var weixinuserid = GetWeixinAuthUserId(code); if (string.IsNullOrEmpty(weixinuserid)) { return(weixinauthresult); } var user = ReadOnlyRepository.Get(e => e.WeiXinAuthId == weixinuserid); if (user == null) { return(weixinauthresult); } weixinauthresult.AuthStatus = true; weixinauthresult.UserId = user.UserBackendId; return(weixinauthresult); }
protected virtual TChild AddItem(Item child, IMap map, ReadOnlyRepository repository, IList list) { if (child.DescendsFromTemplate(map.TemplatePath)) { var entity = repository.Get <TChild>(child); list.Add(entity); return(entity); } return(default(TChild)); }
/// <summary> /// /// </summary> /// <param name="code"></param> /// <returns></returns> private ActionResult AreaDeleteChange(string code) { if (string.IsNullOrEmpty(code)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var deletemodel = ReadOnlyRepository.Get(e => e.Code == code); if (deletemodel == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Repository.Delete(e => e.Code == deletemodel.Code); var isprovince = deletemodel.CityLevel == "1"; var iscity = deletemodel.CityLevel == "2"; if (isprovince) { var cityscodes = AreaService.GetCitysByProvinceCode(deletemodel.Code).Select(e => e.Code).ToList(); if (cityscodes.Count == 0) { return(RedirectToAction("Index", new { Message = "已删除" })); } foreach (var citycode in cityscodes) { Repository.Delete(e => e.Code == citycode); var countryscode = AreaService.GetCountyByCityCode(citycode).Select(e => e.Code).ToList(); if (countryscode.Count > 0) { foreach (var countrycode in countryscode) { Repository.Delete(e => e.Code == countrycode); } } } } else if (iscity) { var countryscode = AreaService.GetCountyByCityCode(deletemodel.Code).Select(e => e.Code).ToList(); if (countryscode.Count == 0) { return(RedirectToAction("Index", new { Message = "已删除" })); } foreach (var countrycode in countryscode) { Repository.Delete(e => e.Code == countrycode); } } return(RedirectToAction("Index", new { Message = "已删除" })); }
protected override TChild AddItem(Item child, Aqueduct.SitecoreLib.DataAccess.IMap map, ReadOnlyRepository repository, IList list) { var entity = repository.Get(child.ID.Guid); if (entity is TChild) { list.Add(entity); return(entity as TChild); } return(default(TChild)); }
public static IEnumerable <D> Get(Expression <Func <S, bool> > where, ReadOnlyRepository <S> repo) { var items = repo.Get(where).ToList(); if (items.Any()) { var model = Mapper.Map <List <S>, List <D> >(items); return(model); } return(null); }
public object ResolveEntityPropertyValue(string rawValue, Type propertyType) { if (rawValue.IsNotEmpty()) { Match imageMatch = Regex.Match(rawValue, RegexPattern); if (imageMatch.Success && imageMatch.Groups["imageid"].Value.IsGuid()) { Guid imageId = new Guid(imageMatch.Groups["imageid"].Value); ReadOnlyRepository repository = new ReadOnlyRepository(); return(repository.Get <Image>(imageId)); } } return(null); }
public object ResolveEntityPropertyValue(string rawValue, Type propertyType) { if (rawValue.IsNotEmpty()) { Match imageMatch = Regex.Match(rawValue, RegexPattern); if (imageMatch.Success && imageMatch.Groups["imageid"].Value.IsGuid()) { Guid imageId = new Guid(imageMatch.Groups["imageid"].Value); ReadOnlyRepository repository = new ReadOnlyRepository(); return repository.Get<Image>(imageId); } } return null; }
public object ResolveEntityPropertyValue(string rawValue, Type propertyType) { var result = new File(); if (rawValue.IsNotEmpty()) { Match imageMatch = Regex.Match(rawValue, RegexPattern); if (imageMatch.Success && imageMatch.Groups["mediaid"].Value.IsGuid()) { Guid imageId = new Guid(imageMatch.Groups["mediaid"].Value); ReadOnlyRepository repository = new ReadOnlyRepository(); File image = repository.Get <File>(imageId); result = image ?? new File(); } } return(result); }
public object ResolveEntityPropertyValue(string rawValue, Type propertyType) { var result = new File(); if (rawValue.IsNotEmpty()) { Match imageMatch = Regex.Match(rawValue, RegexPattern); if (imageMatch.Success && imageMatch.Groups["mediaid"].Value.IsGuid()) { Guid imageId = new Guid(imageMatch.Groups["mediaid"].Value); ReadOnlyRepository repository = new ReadOnlyRepository(); File image = repository.Get<File>(imageId); result = image ?? new File(); } } return result; }
protected override void GetEntity(string id, IList list) { try { //Gets entity using an inferred map from the template name. var entity = m_repository.Get(new Guid(id)); if (entity is T) { list.Add(entity); } } catch (Exception ex) { AppLogger.LogError(string.Format("Error mapping item with ID {0} to type {1}", id, typeof(T)), ex); } }
/// <summary> /// Формирование случайной выборки вопросов выбранного теста, /// добавление представлений вопросов в представление навигации по вопросам теста, /// установка таймера отсчета оставшегося времени тестирования, /// показ представления /// </summary> /// <param name="test">Выбранный тест</param> public override void Run(Test test) { _presenters.Clear(); var views = new Collection <IQuestionView>(); var random = new Random(); var questions = _questionsRepository .Get(question => question.TestId == test.Id) .OrderBy(question => random.Next()) .Take(test.QuestionsCount); foreach (Question question in questions) { var presenter = controller.CreatePresenter <QuestionPresenter, Question>(); presenter.Run(question); views.Add(presenter.View); _presenters.Add(presenter); } view.ShowQuestionViews(views); if (test.Duration != null) { var remainingTime = test.Duration.Value; view.ShowRemainingTime(remainingTime); _timer = new Timer(state => { if ((remainingTime -= 1) > 0) { view.ShowRemainingTime(remainingTime); } else { FinishTest(); } }, null, 1000, 1000); } _testResult = new TestResult(); _testResult.SubjectName = _subjectsRepository .Get(subject => subject.Id == test.Id) .First() .Name; _testResult.TestName = test.Name; _testResult.StartDate = DateTime.Now; base.Run(test); }
public object Resolve(Item item) { Type genericParameterType = GetType().GetGenericArguments()[0]; return(CreateLazyList(genericParameterType, () => { var repository = new ReadOnlyRepository(); IMap map = MapFinder.FindMap(genericParameterType); IList list = CreateEmptyTypedList(genericParameterType); foreach (Item child in item.Children) { if (child.DescendsFromTemplate(map.TemplatePath)) { var entity = repository.Get <TChild>(child); list.Add(entity); } } return list; })); }
public async Task <ActionResult> WeixinLogin(string code, string state) { //if (string.IsNullOrEmpty(code)) //{ // return RedirectToAction("Login"); //} if (string.IsNullOrEmpty(state)) { state = "~/Manage/index"; } var weixinauthstatus = UserBackendService.IsWeiXinAuth(code); if (weixinauthstatus.AuthStatus) { var user = ReadOnlyRepository.Get(e => e.UserBackendId == weixinauthstatus.UserId.Value); if (user == null) { ViewBag.State = state; return(View()); } #region 重新登录(跳过账号和密码) var userbankend = await UserManager.FindByNameAsync(user.UserName); if (userbankend == null) { ViewBag.State = state; return(View()); } await SignInHelper.SignInAsync(userbankend, false, false); log4net.LogManager.GetLogger("RollingLog").Info(user.UserName + " Log in: 微信登录"); #endregion //地址要改 return(RedirectToLocal(state)); } ViewBag.IsWeixin = !string.IsNullOrEmpty(code); ViewBag.State = state; return(View()); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { //通过微信登录 var Isweixinlogin = model.IsWeiXinLogin == "1" && !string.IsNullOrEmpty(model.WeixinUser); ViewBag.IsWeiXinAuth = !string.IsNullOrEmpty(model.WeixinUser); returnUrl = !string.IsNullOrWhiteSpace(returnUrl) ? returnUrl : (string.IsNullOrEmpty(model.Stateurl) ? "~/Manage/index" : model.Stateurl); if (Isweixinlogin) { ViewBag.WeiXinUser = model.WeixinUser; ViewBag.WeiXinUrl = returnUrl; } if (!ModelState.IsValid) { return(View(model)); } #region 密码安全监测 var isDetectionOn = PasswordStrengthDetectionService.IsDetectionOn(); if (isDetectionOn) { var ismatch = PasswordStrengthDetectionService.IsMatch(model.Password.Trim()); if (ismatch) { Session["IsPasswordStronger"] = true; } else { Session["IsPasswordStronger"] = false; } } #endregion var result = await SignInHelper.PasswordSignIn(model.UserName, model.Password, model.RememberMe, shouldLockout : false); //var user = await UserManager.FindByNameAsync(model.UserName); //var roles = await UserManager.GetRolesAsync(user.Id); log4net.LogManager.GetLogger("RollingLog").Info(model.UserName + " Log in: " + result.ToString()); switch (result) { case MvcBackend.App_Start.SignInStatus.Success: Session["MyMenu"] = null; if (Isweixinlogin) { var user = ReadOnlyRepository.GetForUpdate(e => e.UserName == model.UserName.Trim()); //if (user == null) return Redirect(WeiXinAuthHtml.Replace("[url]", returnUrl)); if (string.IsNullOrEmpty(user.WeiXinAuthId)) { user.WeiXinAuthId = model.WeixinUser; Repository.Update(user); } else { var weixinuser = ReadOnlyRepository.Get(e => e.WeiXinAuthId == model.WeixinUser); if (weixinuser != null && weixinuser.UserName != model.UserName) { ModelState.AddModelError("", "微信企业号已经认证过。"); return(View(model)); } } } return(RedirectToLocal(returnUrl)); case MvcBackend.App_Start.SignInStatus.LockedOut: return(View("Lockout")); case MvcBackend.App_Start.SignInStatus.RequiresTwoFactorAuthentication: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl })); case MvcBackend.App_Start.SignInStatus.Failure: default: ModelState.AddModelError("", "登陆名或密码错误。"); return(View(model)); } }
/// <summary> /// 根据id获取 /// </summary> /// <param name="userid">用户id</param> /// <returns></returns> public UserBackendDbModel Get(int userid) { return(ReadOnlyRepository.Get(e => e.UserBackendId == userid)); }
/// <summary> /// Обработчик выбора теста из списка /// </summary> private void SelectTest() => controller.CreatePresenter <TestStartPresenter, Test>().Run ( _repository.Get(view.SelectedTestId) );
protected virtual void GetEntity(string id, IList list) { var entity = Repository.Get <T>(new Guid(id)); list.Add(entity); }