public ActionResult PublicLibrarySearch(int?page, string term) { if (!page.HasValue) { page = 1; } ViewBag.SearchTerm = term; var size = 10; QueryStatistics stats; var exercises = RavenSession .Query <Exercise>("ByCategoriesAndNameSortByName") .Statistics(out stats) .Where(x => x.Name.StartsWith(term) && x.Master) .Skip((page.Value - 1) * size) .Take(size) .OfType <Exercise>() .ToList(); var paged = new StaticPagedList <Exercise>(exercises, page.Value, size, stats.TotalResults); return(View("PublicLibrary", paged)); }
public virtual ActionResult FuturePosts(string sectionTitle) { ViewBag.SectionTitle = sectionTitle; RavenQueryStatistics stats; var futurePosts = RavenSession.Query <Post>() .Statistics(out stats) .Where(x => x.PublishAt > DateTimeOffset.Now.AsMinutes() && x.IsDeleted == false) .Select(x => new Post { Title = x.Title, PublishAt = x.PublishAt }) .OrderBy(x => x.PublishAt) .Take(5) .ToList(); var lastPost = RavenSession.Query <Post>() .Where(x => x.IsDeleted == false) .OrderByDescending(x => x.PublishAt) .Select(x => new Post { PublishAt = x.PublishAt }) .FirstOrDefault(); return(View( new FuturePostsViewModel { LastPostDate = lastPost == null ? null : (DateTimeOffset?)lastPost.PublishAt, TotalCount = stats.TotalResults, Posts = futurePosts.MapTo <FuturePostViewModel>() })); }
public ActionResult Program(string id, string lang) { var plan = RavenSession.Query <Program>().FirstOrDefault(p => p.ShortUrl == id); if (plan == null) { return(HttpNotFound("Program not found")); } SaveView(plan); if (!string.IsNullOrWhiteSpace(lang)) { GoogleTranslate.TranslateExercise(plan, lang); } var clinic = RavenSession.Load <Clinic>("clinics/" + plan.ClinicId); var user = RavenSession.Load <User>("users/" + plan.UserId); var account = RavenSession.Load <Account>("accounts/" + plan.AccountId); var vm = new PublicProgramViewModel() { Program = plan, From = user, Clinic = clinic, Settings = account.Settings }; return(View(vm)); }
public async Task <UserChatSettings> Get(GetMySettings request) { var session = Request.ThrowIfUnauthorized(); var settingsId = session?.UserAuthId + "/settings"; var typeMessage = await RavenSession.Query <Settings>().FirstOrDefaultAsync(x => x.Id == settingsId); if (typeMessage != null) { var settings = Mapper.Map <UserChatSettings>(typeMessage); return(settings); } else { var settings = new Settings { SendingMessageByEnterKey = true, Id = settingsId }; await RavenSession.StoreAsync(settings); await RavenSession.SaveChangesAsync(); var settingsTypeMessage = Mapper.Map <UserChatSettings>(settings); return(settingsTypeMessage); } }
public virtual ActionResult PostsStatistics() { var statistics = RavenSession.Query <Posts_Statistics.ReduceResult, Posts_Statistics>() .FirstOrDefault() ?? new Posts_Statistics.ReduceResult(); return(View(statistics.MapTo <PostsStatisticsViewModel>())); }
public ActionResult Archive(int year, int?month, int?day) { RavenQueryStatistics stats; var postsQuery = RavenSession.Query <Post>() .Include(x => x.AuthorId) .Statistics(out stats) .WhereIsPublicPost() .Where(post => post.PublishAt.Year == year); if (month != null) { postsQuery = postsQuery.Where(post => post.PublishAt.Month == month.Value); } if (day != null) { postsQuery = postsQuery.Where(post => post.PublishAt.Day == day.Value); } var posts = postsQuery.OrderByDescending(post => post.PublishAt) .Paging(CurrentPage, DefaultPage, PageSize) .ToList(); return(ListView(stats.TotalResults, posts)); }
// // GET: /Posts/ public ActionResult List(int?page = 1, string tag = null) { int skip = Settings.Default.PostsPageSize * (page.Value - 1); RavenQueryStatistics stats; IQueryable <Post> posts; posts = RavenSession.Query <Post>() .Statistics(out stats) .Take(Settings.Default.PostsPageSize) .OrderByDescending(x => x.CreatedAt); if (!string.IsNullOrWhiteSpace(tag)) { posts = posts.Where(p => p.Tags.Any(t => t == tag)); } var viewModel = new PostsViewModel(posts.ToList(), page.Value, stats.TotalResults, tag); foreach (var post in viewModel.Posts) { post.Author = RavenSession.GetPostAuthor(post.Post); } return(View(viewModel)); }
public virtual ActionResult PostsSeries() { var series = RavenSession.Query <Posts_Series.Result, Posts_Series>() .Statistics(out var stats) .Where(x => x.Count > 1) .OrderByDescending(x => x.MaxDate) .Paging(CurrentPage, DefaultPage, PageSize) .ToList(); var vm = new SeriesPostsViewModel { PageSize = BlogConfig.PostsOnPage, CurrentPage = CurrentPage, PostsCount = stats.TotalResults, }; foreach (var result in series) { var svm = result.MapTo <SeriesInfo>(); foreach (var post in result.Posts) { svm.PostsInSeries.Add(post.MapTo <PostInSeries>()); } svm.PostsInSeries = svm .PostsInSeries .OrderByDescending(x => x.PublishAt) .ToList(); vm.SeriesInfo.Add(svm); } return(View(vm)); }
public ActionResult ToggleChallenge(string id, string currentUser, bool single, string boardName, int count) { if (HttpContext.User.Identity.Name != currentUser) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } var board = RavenSession .Query <Board>() .FirstOrDefault(x => x.UserName == currentUser && x.BoardName == boardName); if (board == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } var definition = RavenSession.Load <BoardDefinition>(board.BoardDefinitionId); if (definition == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } var activityName = definition.Cards.FirstOrDefault(x => x.Id == id)?.Text; UpdateCompletedCards(single, board, id, count, activityName); RavenSession.Store(board); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public ActionResult Index() { var programs = RavenSession.Query <Program>().Where(x => x.AccountId == LoggedInUser.AccountId).OrderByDescending(x => x.Created).ToList(); var users = RavenSession.Query <User>().Where(x => x.AccountId == LoggedInUser.AccountId).ToList(); return(View()); }
// // GET: /Meeting/ public ActionResult Index() { MeetingListViewModel meetings = new MeetingListViewModel(); meetings.Meetings = RavenSession.Query <Meeting>().OrderByDescending(x => x.MeetingDate).ToList(); return(View(meetings)); }
public ActionResult LogOnCallback(string returnUrl) { OpenIdRelyingParty openid = new OpenIdRelyingParty(); var response = openid.GetResponse(); if (response == null) { return(RedirectToAction("Error", new { returnUrl = returnUrl, error = "No authentication response" })); } if (response.Status != AuthenticationStatus.Authenticated) { return(RedirectToAction("Error", new { returnUrl = returnUrl, error = "Response status is not Authenticated" })); } var fetch = response.GetExtension <FetchResponse>(); if (fetch == null) { return(RedirectToAction("Error", new { returnUrl = returnUrl, error = "No fetch response" })); } string email = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email); if (string.IsNullOrWhiteSpace(email)) { return(RedirectToAction("Error", new { returnUrl = returnUrl, error = "Response Email is empty" })); } if (!email.EndsWith(EmailSuffix)) { return(RedirectToAction("Error", new { returnUrl = returnUrl, error = "Only emails ended with " + EmailSuffix + " are allowed" })); } var username = email.Substring(0, email.Length - EmailSuffix.Length); FormsAuthentication.SetAuthCookie(username, true); Session[SessionRolesKey] = new string[0]; var user = RavenSession.Query <User>().Where(u => u.UserName == username).FirstOrDefault(); log.Debug("User {0} found: {1}", username, user != null); if (user != null) { log.Dump(LogLevel.Debug, user, "RavenDB User"); Session[SessionRolesKey] = user.Roles ?? new string[0]; } if (!string.IsNullOrWhiteSpace(returnUrl) && Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Home")); } }
public override void Execute() { foreach (var e in _evaluators) { if (e.Action == EvaluatorAction.Add) { if (_employeeEvaluation.UserName != e.UserName) { var employee = RavenSession .Query <Employee, EmployeeByUserName_Search>() .Where(x => x.UserName == e.UserName) .FirstOrDefault(); if (employee != null) { var evId = _employeeEvaluation.Id ?? EmployeeEvaluation.GenerateEvaluationId(_employeeEvaluation.Period, _employeeEvaluation.UserName); ExecuteCommand(new GenerateCalificationCommand(_employeeEvaluation.Period, _employeeEvaluation.UserName, e.UserName, _employeeEvaluation.TemplateId, CalificationType.Evaluator, evId)); } else { throw new ApplicationException(string.Format("Error: Evaluador no valido: {0}.", e.UserName)); } } } else { var id = EvaluationCalification.GenerateCalificationId(_employeeEvaluation.Period, _employeeEvaluation.UserName, e.UserName); var calification = RavenSession.Load <EvaluationCalification>(id); if (calification != null) { RavenSession.Delete(calification); } } } }
public MemberProfileViewModel GetMemberProfile(string id) { var account = RavenSession.Query <Account>().FirstOrDefault(x => x.Id == id); var balance = _transactionService.GetBalance(account.Id); return(MemberProfileViewModel.FromAccount(account, balance)); }
public override SuggestedApplicantsResult[] Execute() { RavenQueryStatistics stats; var query = RavenSession .Query <Applicant_BySkills.Projection, Applicant_BySkills>(); if (RequiredTechnicalSkills != null) { foreach (var rts in RequiredTechnicalSkills) { query = query.Where(a => a.Searcheables.StartsWith(rts.Searcheable)); } } query = query .OrderByDescending(a => a.Total) .Statistics(out stats) .Customize(x => x.WaitForNonStaleResultsAsOfLastWrite()); var result = query.AsProjection <SuggestedApplicantsResult>().ToArray(); Stats = stats; return(result); }
public ActionResult Index(string tag) { var questions = RavenSession.Query <Question>(); var header = "Top Questions"; if (!string.IsNullOrWhiteSpace(tag)) { header = "Questions Tagged '" + tag + "'"; questions = questions.Where(x => x.Tags.Any(y => y.Equals(tag))); } else { questions = questions.OrderByDescending(x => x.CreatedOn); } var mostUsedTags = RavenSession.Query <QuestionTagsIndex.ReduceResult, QuestionTagsIndex>() .OrderByDescending(x => x.Count) .Take(20) .ToList(); var recentlyUsedTags = RavenSession.Query <QuestionTagsIndex.ReduceResult, QuestionTagsIndex>() .OrderByDescending(x => x.LastUsed) .Take(20) .ToList(); var viewModel = new HomeViewModel(User); viewModel.Questions = questions.Take(20).ToList();; viewModel.Header = header; viewModel.RecentlyUsedTags = recentlyUsedTags; viewModel.MostUsedTags = mostUsedTags; return(View(viewModel)); }
public ActionResult RedirectLegacyPost(int year, int month, int day, string slug) { // attempt to find a post with match slug in the given date, but will back off the exact date if we can't find it var post = RavenSession.Query <Post>() .WhereIsPublicPost() .FirstOrDefault(p => p.LegacySlug == slug && (p.PublishAt.Year == year && p.PublishAt.Month == month && p.PublishAt.Day == day)) ?? RavenSession.Query <Post>() .WhereIsPublicPost() .FirstOrDefault(p => p.LegacySlug == slug && p.PublishAt.Year == year && p.PublishAt.Month == month) ?? RavenSession.Query <Post>() .WhereIsPublicPost() .FirstOrDefault(p => p.LegacySlug == slug && p.PublishAt.Year == year) ?? RavenSession.Query <Post>() .WhereIsPublicPost() .FirstOrDefault(p => p.LegacySlug == slug); if (post == null) { return(HttpNotFound()); } var postReference = post.MapTo <PostReference>(); return(RedirectToActionPermanent("Details", "PostDetails", new { Id = postReference.DomainId, postReference.Slug })); }
private async Task <User> GetUserByLogin(string login) { var user = await RavenSession.Query <User>().Where(x => x.Login == login).Include(x => x.Id + SecretPostfix) .FirstOrDefaultAsync(); return(user); }
public virtual async Task <ActionResult> ExternalLoginCallback(string returnUrl) { Session["Dummy"] = "Dummy"; // OWIN External Login hack Uri returnUri; Uri.TryCreate(returnUrl, UriKind.Absolute, out returnUri); var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); if (loginInfo == null || returnUri == null) { return(returnUri != null ? (ActionResult)Redirect(returnUri.AbsoluteUri) : RedirectToRoute("homepage")); } var claimedIdentifier = loginInfo.Login.ProviderKey + "@" + loginInfo.Login.LoginProvider; var commenter = RavenSession.Query <Commenter>() .FirstOrDefault(c => c.OpenId == claimedIdentifier) ?? new Commenter { Key = Guid.NewGuid(), OpenId = claimedIdentifier, }; SetCommenterValuesFromResponse(loginInfo, commenter); CommenterUtil.SetCommenterCookie(Response, commenter.Key.MapTo <string>()); RavenSession.Store(commenter); return(Redirect(returnUri.AbsoluteUri)); }
public override List <HistoricalEvaluationDto> ExecuteWithResult() { IQueryable <EmployeeEvaluationHistory_Search.Projection> query = RavenSession .Query <EmployeeEvaluationHistory_Search.Projection, EmployeeEvaluationHistory_Search>() .Where(e => e.UserName == _userName); var employeesProjection = query.ToList() .Where(x => x.Period != null && 0 >= string.Compare(x.Period, _lastPeriod)) .OrderByDescending(x => x.Period) .ToList(); var mapper = new EmployeeEvaluationHelper(RavenSession, _userName); return(employeesProjection.Select(e => new HistoricalEvaluationDto() { AverageCalification = e.Califications, ResponsibleId = e.ResponsibleId, FullName = e.FullName, UserName = e.UserName, Period = e.Period, Evaluators = e.Evaluators != null ? e.Evaluators.ToList() : new List <string>(), State = EvaluationStateHelper.GetEvaluationState(e.AutoEvaluationDone, e.ResponsibleEvaluationDone, e.CompanyEvaluationDone, e.OpenToDevolution, e.Finished), Id = e.Id, }).ToList()); }
public ActionResult ResetPassword(PasswordResetViewModel postedModel) { var pr = RavenSession.Query <PasswordReset>().FirstOrDefault(x => x.Token == postedModel.Token); if (pr == null || pr.Generated > DateTime.Now.AddHours(2)) { return(View("Reset", new PasswordResetViewModel())); } if (postedModel.Password != postedModel.ConfirmPassword) { ModelState.AddModelError("NoMatch", "Passwords must match."); return(View("Reset", postedModel)); } var user = RavenSession.Load <User>("users/" + pr.UserId); if (user == null) { ModelState.AddModelError("NoUserMatch", "User account not found."); return(View("Reset", postedModel)); } var pw = Hash(postedModel.Password); user.Password = pw; RavenSession.Delete(pr); RavenSession.SaveChanges(); HighFive("Your password has been changed."); return(RedirectToAction("Login")); }
public ActionResult LogOn(LogOnModel model, string returnUrl) { try { if (ModelState.IsValid) { var owner = RavenSession.Query <Owner>().SingleOrDefault(x => x.UserName == model.UserName && x.Password == model.Password); if (owner != null) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Home", new { language = "en" })); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } } catch (WebException ex) { ModelState.AddModelError("", "Network error while connecting to the database"); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Index() { ViewBag.Message = "Welcome to ASP.NET MVC!"; var activeProjects = RavenSession.Query <Project>().Where(p => p.Status == Status.Active).ToList(); return(View("Index", activeProjects)); }
public override string Execute() { RavenQueryStatistics stats; var query = RavenSession .Query <SharedLinks_Entities.ReduceResult, SharedLinks_Entities>() .Statistics(out stats) .Where(x => x.ExpirationDate > DateTime.Now) .Where(x => x.SharedCode == SharedCode); if (EntityId != null) { query = query.Where(x => x.EntityId == EntityId); } var results = query .Select(x => x.EntityId) .Take(2) .ToArray(); if (results.Length == 1) { return(results[0]); } else { return(null); } }
public virtual ActionResult PostsSeries(string sectionTitle) { ViewBag.SectionTitle = sectionTitle; var series = RavenSession.Query <Posts_Series.Result, Posts_Series>() .Where(x => x.Count > 1) .OrderByDescending(x => x.MaxDate) .Take(5) .ToList(); var vm = series.Select(result => new RecentSeriesViewModel { SeriesId = result.SerieId, SeriesSlug = SlugConverter.TitleToSlug(result.Series), SeriesTitle = TitleConverter.ToSeriesTitle(result.Posts.First().Title), PostsCount = result.Count, PostInformation = result.Posts .OrderByDescending(post => post.PublishAt) .FirstOrDefault(post => post.PublishAt <= DateTimeOffset.Now) }) .Where(x => x.PostInformation != null) .ToList(); return(View(vm)); }
private SeriesInfo GetSeriesInfo(string title) { SeriesInfo seriesInfo = null; string seriesTitle = TitleConverter.ToSeriesTitle(title); if (!string.IsNullOrEmpty(seriesTitle)) { var series = RavenSession.Query <Posts_Series.Result, Posts_Series>() .Where(x => x.Series.StartsWith(seriesTitle) && x.Count > 1) .OrderByDescending(x => x.MaxDate) .FirstOrDefault(); if (series == null) { return(null); } var postsInSeries = GetPostsForCurrentSeries(series); seriesInfo = new SeriesInfo { SeriesId = series.SerieId, SeriesTitle = seriesTitle, PostsInSeries = postsInSeries }; } return(seriesInfo); }
public virtual ActionResult Rss(string tag, string token) { RavenQueryStatistics stats; var queryBehavior = SetQueryLimitsBasedOnToken(token, RavenSession.Query <Post>().Statistics(out stats)); var postsQuery = queryBehavior.PostsQuery; if (string.IsNullOrWhiteSpace(tag) == false) { postsQuery = postsQuery.Where(x => x.TagsAsSlugs.Any(postTag => postTag == tag)); } var posts = postsQuery.OrderByDescending(x => x.PublishAt) .Take(queryBehavior.Take) .ToList(); if (queryBehavior.AddExpiredNote) { posts.Insert(0, new Post { Title = "Feed token expired, you are no longer able to read future posts", Id = null, ContentType = DynamicContentType.Html, Body = "<p>This feed token has expired, and will no longer show any future posts.</p><p>You can still read current posts.</p>" }); } string responseETagHeader; if (CheckEtag(stats, out responseETagHeader)) { return(HttpNotModified()); } var rss = new XDocument( new XElement("rss", new XAttribute("version", "2.0"), new XElement("channel", new XElement("title", queryBehavior.Title), new XElement("link", Url.RelativeToAbsolute(Url.RouteUrl("homepage"))), new XElement("description", BlogConfig.MetaDescription ?? queryBehavior.Title), new XElement("copyright", String.Format("{0} (c) {1}", BlogConfig.Copyright, DateTime.Now.Year)), new XElement("ttl", "60"), from post in posts let postLink = GetPostLink(post) select new XElement("item", new XElement("title", Server.HtmlDecode(post.Title)), new XElement("description", post.CompiledContent(true)), new XElement("link", postLink), new XElement("guid", postLink), new XElement("pubDate", post.PublishAt.ToString("R")) ) ) ) ); return(Xml(rss, responseETagHeader)); }
public ViewResult List() { var protocols = RavenSession.Query <Protocol>(typeof(ProtocolsByOwnershipAndByName).Name) .Where(x => x.UserId == LoggedInUser.Id).OrderByDescending(x => x.Created).ToList(); return(View(protocols)); }
public ActionResult Library() { IEnumerable <Exercise> exercises; RavenQueryStatistics stats; if (this.ApplicationAdministrator) { exercises = RavenSession .Query <Exercise>(typeof(ByOwnableAndName).Name) .Statistics(out stats) .Where(x => x.Master) .OrderBy(x => x.Name).Take(15).ToList(); } else { exercises = RavenSession .Query <Exercise>(typeof(ByOwnableAndName).Name) .Statistics(out stats) .Where(x => x.ClinicId == Clinic.Id || x.AccountId == Account.Id) .OrderBy(x => x.Name).Take(15).ToList(); } return(Json(exercises, JsonRequestBehavior.AllowGet)); }
public ActionResult PublicLibrary(int?page) { ViewBag.SearchTerm = ""; ViewBag.GridName = "Exercise Library Management"; ViewBag.GridDescription = "All exercise details are customizable and unique to your clinic. Change names, categories, or even sort exercises into your " + "own custom lists. Our exercise library is flexible and will support whatever works for your business."; if (!page.HasValue) { page = 1; } var size = 10; QueryStatistics stats; var exercises = RavenSession .Query <Exercise>() .Statistics(out stats) //.Customize(x => x.WaitForNonStaleResults(TimeSpan.FromSeconds(5))) .Where(x => x.Master) .OrderBy(x => x.Name) .Skip((page.Value - 1) * size) .Take(size) .ToList(); var paged = new StaticPagedList <Exercise>(exercises, page.Value, size, stats.TotalResults); return(View(paged)); }