// In this method we will create default User roles and Admin user for login private void createRolesandUsers() { var context = new RaceAnalysisDbContext(); var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context)); var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); // creating first Admin Role and creating a default Admin User if (!roleManager.RoleExists("Admin")) { var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = "Admin"; roleManager.Create(role); //create a Admin super user who will maintain the website var user = new ApplicationUser(); user.UserName = "******"; user.Email = "*****@*****.**"; string userPWD = "@Tritone32963"; var chkUser = UserManager.Create(user, userPWD); //Add default User to Role Admin if (chkUser.Succeeded) { var result1 = UserManager.AddToRole(user.Id, "Admin"); } } }
public List <ShallowTriathlete> SearchAthletesByName(string name, string[] raceIds = null) { List <ShallowTriathlete> results; var search = FtsInterceptor.Fts(name.Trim().ToLower()); using (var db = new RaceAnalysisDbContext()) { var triathletes = db.Triathletes.Include("RequestContext.RaceId"); var shallow = triathletes.OrderBy(t => t.Name).Select(t => new ShallowTriathlete() { Name = t.Name, Id = t.TriathleteId, RaceId = t.RequestContext.RaceId }). Where(t => t.Name.Contains(search)).Take(30); if (raceIds != null) { shallow = shallow.Where(a => raceIds.Contains(a.RaceId)); } results = shallow.ToList(); } return(results.Distinct(new ShallowTriathleteComparer()).ToList()); }
public static void Seed(RaceAnalysisDbContext context) { /***** context.RacesAggregates.RemoveRange(context.RacesAggregates); //clear out existing rows foreach (Race race in context.Races) { race.IsAggregated = false; } context.SaveChanges(); *****/ return; //if (context.Triathletes.Count(i => i.TriathleteId > 1) == 0) { SeedRaces(context); SeedGenders(context); SeedAgeGroups(context); /*** only do for testing if absolutely necessary********** //SeedRequestContexts(context); //SeedTriathletes(context); ************************************/ SeedAppFeatures(context); SeedRaceConditionTag(context); SeedTags(context); } }//seed
}//seed private static void SeedTriathletes(RaceAnalysisDbContext context) { if (context.Triathletes.Count(i => i.TriathleteId > 1) == 0) { var athletes = new List<Triathlete> { new Triathlete { RequestContextId= context.RequestContext.First().RequestContextId, Link="", Name="Scott", Country="USA", DivRank=1, GenderRank=1, OverallRank=1, Swim= new TimeSpan(1,30,0), Bike= new TimeSpan(4,30,0), Run= new TimeSpan(3,30,0), Finish= new TimeSpan(1,30,0), Points = 100 } }; athletes.ForEach(t => context.Triathletes.AddOrUpdate(t)); context.SaveChanges(); } }
public List <ShallowRace> SearchRacesByName(string name) { List <ShallowRace> results; var search = FtsInterceptor.Fts(name.Trim().ToLower()); List <Race> foundRaces; using (var db = new RaceAnalysisDbContext()) { foundRaces = db.Races. Where(r => r.LongDisplayName.Contains(search)) .OrderBy(r => r.LongDisplayName).ToList(); // var results = shallow.Select(r => new ShallowRace() // { Name = r.RaceCategoryName, Id = r.ShortName }); } return(foundRaces.Select(r => new ShallowRace() { Name = r.RaceCategoryName, Id = r.ShortName }) .Distinct(new ShallowRaceComparer()).ToList()); // if (!shallowRaces.Contains(race, new ShallowRaceComparer())) // shallowRaces.Add(race); }
private static void SeedRaces(RaceAnalysisDbContext context) { context.Races.RemoveRange(context.Races); //clear out existing rows context.SaveChanges(); var races = new List<Race> { new Race { RaceId="IMLOU2015", BaseURL="http://www.ironman.com/triathlon/events/americas/ironman/louisville/results.aspx", DisplayName="IMLOU 2015", RaceDate = new DateTime(2015,10,11), ShortName="louisville", Distance = "140.6", Conditions = new RaceConditions { } //Conditions = new RaceConditions {SwimLayout="Wetsuit Legal",BikeLayout="Rolling Hills",RunLayout="Flat" } }, new Race { RaceId="IMLOU2016", BaseURL= "http://www.ironman.com/triathlon/events/americas/ironman/louisville/results.aspx", DisplayName ="IMLOU 2016", RaceDate = new DateTime(2016,10,9), ShortName="louisville", Distance = "140.6", Conditions = new RaceConditions { } }, new Race { RaceId="IMFL2015", BaseURL="http://www.ironman.com/triathlon/events/americas/ironman/florida/results.aspx", DisplayName="IMFL 2015", RaceDate = new DateTime(2015,11,7), ShortName="florida", Distance = "140.6", Conditions = new RaceConditions { } } }; races.ForEach(t => context.Races.AddOrUpdate(t)); context.SaveChanges(); }
private static void PopulateCache(string raceId) { using (var db = new RaceAnalysisDbContext()) { var raceService = new RaceService(db); var athletes = raceService.GetAthletes( new BasicRaceCriteria { SelectedRaceIds = new string[] { raceId }, SelectedAgeGroupIds = AgeGroup.Expand(new int[] { 0 }), SelectedGenderIds = Gender.Expand(new int[] { 0 }) } ); } }
protected override void Seed(RaceAnalysisDbContext context) { RaceAnalysis.Data.RaceAnalysisDbInitializer.Seed(context); // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g. // // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" }, // new Person { FullName = "Brice Lambson" }, // new Person { FullName = "Rowan Miller" } // ); // }
private static int GetTriathletes(string raceId, int[] ageGroupIds, int[] genderIds) { using (var db = new RaceAnalysisDbContext()) { var raceService = new RaceService(db); var athletes = raceService.GetAthletes( new BasicRaceCriteria { SelectedRaceIds = new string[] { raceId }, SelectedAgeGroupIds = ageGroupIds, SelectedGenderIds = genderIds }, false /*do not use cache*/ ); return(athletes.Count()); } }
private static void SeedRequestContexts(RaceAnalysisDbContext context) { context.RequestContext.RemoveRange(context.RequestContext); context.SaveChanges(); var contextkeys = new List<RequestContext> { new RequestContext { RaceId= context.Races.Single(i => i.DisplayName == "IM Louisville 10-11-2015").RaceId, GenderId=context.Genders.Single(i => i.DisplayName == "Male").GenderId, AgeGroupId= context.AgeGroups.Single(i => i.DisplayName == "50-54").AgeGroupId } }; contextkeys .ForEach(t => context.RequestContext.AddOrUpdate(t)); context.SaveChanges(); }
private static void SeedGenders(RaceAnalysisDbContext context) { context.Genders.RemoveRange(context.Genders); context.SaveChanges(); var genders = new List<Gender> { new Gender { GenderId=1, DisplayName="Male", Value="M" }, new Gender { GenderId=2, DisplayName="Female", Value = "F" } }; genders.ForEach(t => context.Genders.AddOrUpdate(t)); context.SaveChanges(); }
public IronmanClient(RaceAnalysisDbContext db) : base() { _DBContext = db; }
private static void SeedAgeGroups(RaceAnalysisDbContext context) { context.AgeGroups.RemoveRange(context.AgeGroups); context.SaveChanges(); var agegroups = new List<AgeGroup> { new AgeGroup { DisplayName= "Pro", Value="Pro" }, new AgeGroup { DisplayName= "18-24", Value="18-24" }, new AgeGroup { DisplayName= "25-29", Value="25-29" }, new AgeGroup { DisplayName= "30-34", Value="30-34" }, new AgeGroup { DisplayName= "40-44", Value="40-44" }, new AgeGroup { DisplayName= "45-49", Value="45-49" }, new AgeGroup { DisplayName= "50-54", Value="50-54" }, new AgeGroup { DisplayName= "55-59", Value="55-59" }, new AgeGroup { DisplayName= "60-64", Value="60-64" }, new AgeGroup { DisplayName= "65-69", Value="65-69" }, new AgeGroup { DisplayName= "70-74", Value="70-74" }, new AgeGroup { DisplayName= "75-79", Value="75-79" }, new AgeGroup { DisplayName= "80-84", Value="80-84" }, new AgeGroup { DisplayName= "85-89", Value="85-89" }, new AgeGroup { DisplayName= "90 Plus", Value="90+Plus" }, new AgeGroup { DisplayName= "PC", Value="PC" }, }; agegroups.ForEach(t => context.AgeGroups.AddOrUpdate(t)); context.SaveChanges(); }
public ElasticSearchFacade(RaceAnalysisDbContext dbCtx) { _DBContext = dbCtx; }
private static void SeedAppFeatures(RaceAnalysisDbContext context) { context.AppFeatures.RemoveRange(context.AppFeatures); context.SaveChanges(); var features = new List<AppFeature> { ////////////////////////////////////////////////////////// //Admin ////////////////////////////////////////////////////////// new AppFeature { Category = FeatureCategories.Admin, Name = "Add Race Data", Description = "Allow admin to add race and populate cache", Status = FeatureStatus.Done }, new AppFeature { Category = FeatureCategories.Admin, Name = "Registration", Description = "Allow users to register", Status = FeatureStatus.Done }, new AppFeature { Category = FeatureCategories.Admin, Name = "Login", Description = "Allow users to login", Status = FeatureStatus.Done }, //////////////////////////////////////////////////////////// // Content Contribution //////////////////////////////////////////////////////////// new AppFeature { Category = FeatureCategories.ContentContrib, Name = "Content Contribution", Description = "Allow users to signup for content contribution", Status = FeatureStatus.NotStarted }, new AppFeature { Category = FeatureCategories.ContentContrib, Name = "Add Race Conditions", Description = "Allow users to add race conditions ", Status = FeatureStatus.NotStarted }, new AppFeature { Category = FeatureCategories.ContentContrib, Name = "Add Race Analysis", Description = "Allow users to add race analysis ", Status = FeatureStatus.NotStarted }, ////////////////////////////////////////////////// //Flex Tool ////////////////////////////////////////////////// new AppFeature { Category=FeatureCategories.FlexTool, Name = "Filter", Description = "Allow user to filter results based on Age Group, Gender, Duration of Splits", Status = FeatureStatus.Done }, new AppFeature { Category=FeatureCategories.FlexTool, Name = "Details", Description = "Allow user to view detailed result stats for a race", Status = FeatureStatus.Done }, new AppFeature { Category=FeatureCategories.FlexTool, Name = "Compare Races", Description = "Allow user to compare race result stats", Status = FeatureStatus.Done }, new AppFeature { Category = FeatureCategories.FlexTool, Name = "Compare Athletes", Description = "Allow user to select athletes and view comparison", Status = FeatureStatus.Testing }, new AppFeature { Category = FeatureCategories.FlexTool, Name = "Link Stats to Athletes", Description = "Allow user to select stats and view the athletes in that context", Status = FeatureStatus.NotStarted }, new AppFeature { Category = FeatureCategories.FlexTool, Name = "Race Conditions", Description = "Expand race conditions", Status = FeatureStatus.InProgress }, //////////////////////////////////////////////////////////////////// //hypotheticals //////////////////////////////////////////////////////////////////// new AppFeature { Category = FeatureCategories.Hypotheticals, Name = "Est Finish Time", Description = "Estimate range a user would finish base on their information", Status =FeatureStatus.Done }, ////////////////////////////////////////////////////////////////// //search //////////////////////////////////////////////////////////////////// new AppFeature { Category = FeatureCategories.Search, Name = "Search for races based on conditions", Description = "Search for races based on user's input : hilly,flat,cold, etc", Status =FeatureStatus.NotStarted }, ////////////////////////////////////////////////////////////////// //performance //////////////////////////////////////////////////////////////////// new AppFeature { Category = FeatureCategories.Performance, Name = "Improve Performance", Description = "Improve Performance by adding a caching layer", Status =FeatureStatus.NotStarted }, }; features.ForEach(t => context.AppFeatures.AddOrUpdate(t)); context.SaveChanges(); }
private static void SeedTags(RaceAnalysisDbContext context) { context.Tags.RemoveRange(context.Tags); context.SaveChanges(); }
public CacheController(ICacheService cacheService, RaceAnalysisDbContext db) { _Cache = cacheService; _DbContext = db; }
public RaceService(RaceAnalysisDbContext db) { _DBContext = db; }
private static void RegisterRaceAdminGrid() { MVCGridDefinitionTable.Add("RaceAdminGrid", new MVCGridBuilder <Race>() .WithAuthorizationType(AuthorizationType.AllowAnonymous) .AddColumns(cols => { cols.Add("RaceName").WithSorting(true).WithValueExpression(p => p.LongDisplayName); cols.Add("RaceId").WithSorting(true).WithValueExpression(p => p.RaceId); cols.Add("RaceDate").WithSorting(true).WithValueExpression(p => p.RaceDate.ToShortDateString()); cols.Add("Edit").WithHtmlEncoding(false) .WithSorting(false) .WithHeaderText(" ") .WithValueExpression((p, c) => c.UrlHelper.Action("Edit", "Races", new { id = p.RaceId })) .WithValueTemplate("<a href='{Value}' class='btn btn-primary' role='button'>Edit</a>"); cols.Add("Copy").WithHtmlEncoding(false) .WithSorting(false) .WithHeaderText(" ") .WithValueExpression((p, c) => c.UrlHelper.Action("Copy", "Races", new { id = p.RaceId })) .WithValueTemplate("<a href='{Value}' class='btn btn-primary' role='button'>Copy</a>"); cols.Add("Populate").WithHtmlEncoding(false) .WithSorting(false) .WithHeaderText(" ") .WithValueExpression((p, c) => c.UrlHelper.Action("CacheFill", "Races", new { id = p.RaceId })) .WithValueTemplate("<a href='{Value}' class='btn btn-primary' role='button'>Populate</a>"); cols.Add("ValidateMessage").WithHtmlEncoding(false).WithSorting(true) .WithValueExpression((p, c) => c.UrlHelper.Action("Validate", "Races", new { id = p.RaceId })) .WithValueTemplate( "<a href='{Value}' class='btn {Model.ValidateMessage}' role='button'>{Model.ValidateMessage}</a>"); cols.Add("IsAggregated").WithHtmlEncoding(false).WithSorting(true) .WithValueExpression((p, c) => c.UrlHelper.Action("Aggregate", "Races", new { id = p.RaceId })) .WithValueTemplate( "<a href='{Value}' class='btn {Model.IsAggregated}' role='button'>{Model.IsAggregated}</a>"); cols.Add("Distance").WithVisibility(false) .WithFiltering(true) .WithHeaderText("Distance") .WithValueExpression(p => p.Distance); }) .WithAdditionalQueryOptionNames("Search") .WithAdditionalSetting("RenderLoadingDiv", false) .WithFiltering(true) .WithSorting(true, "RaceName", SortDirection.Asc) .WithPaging(true, itemsPerPage, true, pageMax) .WithRetrieveDataMethod((context) => { var options = context.QueryOptions; string distance = String.IsNullOrEmpty(options.GetFilterString("Distance")) ? "140.6" : options.GetFilterString("Distance"); string globalSearch = options.GetAdditionalQueryOptionString("Search"); var result = new QueryResult <Race>(); using (var db = new RaceAnalysisDbContext()) { var query = db.Races.Where(p => p.Distance == distance); if (!String.IsNullOrEmpty(globalSearch)) { query = query.Where(p => p.LongDisplayName.Contains(globalSearch)); } result.TotalRecords = query.Count(); if (!String.IsNullOrWhiteSpace(options.SortColumnName)) { switch (options.SortColumnName.ToLower()) { case "racename": query = options.SortDirection == SortDirection.Asc ? query.OrderBy(p => p.LongDisplayName) : query.OrderByDescending(p => p.LongDisplayName); break; case "raceid": query = options.SortDirection == SortDirection.Asc ? query.OrderBy(p => p.RaceId) : query.OrderByDescending(p => p.RaceId); break; case "racedate": query = options.SortDirection == SortDirection.Asc ? query.OrderBy(p => p.RaceDate) : query.OrderByDescending(p => p.RaceDate); break; case "validatemessage": query = options.SortDirection == SortDirection.Asc ? query.OrderBy(p => p.ValidateMessage) : query.OrderByDescending(p => p.ValidateMessage); break; case "isaggregated": query = options.SortDirection == SortDirection.Asc ? query.OrderBy(p => p.IsAggregated) : query.OrderByDescending(p => p.IsAggregated); break; } } if (options.GetLimitOffset().HasValue) { query = query.Skip(options.GetLimitOffset().Value).Take(options.GetLimitRowcount().Value); } result.Items = query.ToList(); } return(result); }) ); }
}//RegisterGrids private static void RegisterRaceAggregateGrid() { MVCGridDefinitionTable.Add("RaceAggregateGrid", new MVCGridBuilder <RaceAggregate>() .WithAuthorizationType(AuthorizationType.AllowAnonymous) .AddColumns(cols => { cols.Add("RaceName").WithSorting(true).WithValueExpression(p => p.Race.LongDisplayName); cols.Add("Segment").WithSorting(true).WithValueExpression(p => p.Segment).WithFiltering(true); cols.Add("Count").WithSorting(true).WithValueExpression(p => p.AthleteCount.ToString()); cols.Add("SwimMedian").WithSorting(true).WithHeaderText("Swim Median") .WithValueExpression(p => p.SwimMedian.ToString()); cols.Add("BikeMedian").WithSorting(true).WithHeaderText("Bike Median") .WithValueExpression(p => p.BikeMedian.ToString()); cols.Add("RunMedian").WithSorting(true).WithHeaderText("Run Median") .WithValueExpression(p => p.RunMedian.ToString()); cols.Add("FinishMedian").WithSorting(true).WithHeaderText("Finish Median") .WithValueExpression(p => p.FinishMedian.ToString()); cols.Add("SwimFastest").WithSorting(true).WithHeaderText("Swim Fastest") .WithValueExpression(p => p.SwimFastest.ToString()); cols.Add("BikeFastest").WithSorting(true).WithHeaderText("Bike Fastest") .WithValueExpression(p => p.BikeFastest.ToString()); cols.Add("RunFastest").WithSorting(true).WithHeaderText("Run Fastest") .WithValueExpression(p => p.RunFastest.ToString()); cols.Add("FinishFastest").WithSorting(true).WithHeaderText("Finish Fastest") .WithValueExpression(p => p.FinishFastest.ToString()); cols.Add("DNFCount").WithSorting(true).WithHeaderText("DNF Count") .WithValueExpression(p => p.DNFCount.ToString()); cols.Add("Distance").WithVisibility(false) .WithFiltering(true) .WithHeaderText("Distance") .WithValueExpression(p => p.Race.Distance); }) .WithAdditionalQueryOptionNames("Search") .WithAdditionalSetting("RenderLoadingDiv", false) .WithFiltering(true) .WithSorting(true, "FinishMedian", SortDirection.Asc) .WithPaging(true, itemsPerPage, true, pageMax) .WithRetrieveDataMethod((context) => { var options = context.QueryOptions; string distance = String.IsNullOrEmpty(options.GetFilterString("Distance")) ? "140.6" : options.GetFilterString("Distance"); string segment = String.IsNullOrEmpty(options.GetFilterString("Segment")) ? "all" : options.GetFilterString("Segment"); string globalSearch = options.GetAdditionalQueryOptionString("Search"); var result = new QueryResult <RaceAggregate>(); using (var db = new RaceAnalysisDbContext()) { var query = db.RacesAggregates.Include("Race").Where(p => p.Race.Distance == distance); query = query.Where(p => p.Segment.Equals(segment)); if (!String.IsNullOrEmpty(globalSearch)) { query = query.Where(p => p.Race.LongDisplayName.Contains(globalSearch)); } result.TotalRecords = query.Count(); if (!String.IsNullOrWhiteSpace(options.SortColumnName)) { switch (options.SortColumnName.ToLower()) { case "racename": query = options.SortDirection == SortDirection.Asc ? query.OrderBy(p => p.Race.LongDisplayName) : query.OrderByDescending(p => p.Race.LongDisplayName); break; case "count": query = options.SortDirection == SortDirection.Asc ? query.OrderBy(p => p.AthleteCount) : query.OrderByDescending(p => p.AthleteCount); break; case "segment": query = options.SortDirection == SortDirection.Asc ? query.OrderBy(p => p.Segment) : query.OrderByDescending(p => p.Segment); break; case "swimfastest": query = options.SortDirection == SortDirection.Asc ? query.OrderBy(p => p.SwimFastest) : query.OrderByDescending(p => p.SwimFastest); break; case "bikefastest": query = options.SortDirection == SortDirection.Asc ? query.OrderBy(p => p.BikeFastest) : query.OrderByDescending(p => p.BikeFastest); break; case "runfastest": query = options.SortDirection == SortDirection.Asc ? query.OrderBy(p => p.RunFastest) : query.OrderByDescending(p => p.RunFastest); break; case "finishfastest": query = options.SortDirection == SortDirection.Asc ? query.OrderBy(p => p.FinishFastest) : query.OrderByDescending(p => p.FinishFastest); break; case "swimmedian": query = options.SortDirection == SortDirection.Asc ? query.OrderBy(p => p.SwimMedian) : query.OrderByDescending(p => p.SwimMedian); break; case "bikemedian": query = options.SortDirection == SortDirection.Asc ? query.OrderBy(p => p.BikeMedian) : query.OrderByDescending(p => p.BikeMedian); break; case "runmedian": query = options.SortDirection == SortDirection.Asc ? query.OrderBy(p => p.RunMedian) : query.OrderByDescending(p => p.RunMedian); break; case "finishmedian": query = options.SortDirection == SortDirection.Asc ? query.OrderBy(p => p.FinishMedian) : query.OrderByDescending(p => p.FinishMedian); break; case "dnfcount": query = options.SortDirection == SortDirection.Asc ? query.OrderBy(p => p.DNFCount) : query.OrderByDescending(p => p.DNFCount); break; } } if (options.GetLimitOffset().HasValue) { query = query.Skip(options.GetLimitOffset().Value).Take(options.GetLimitRowcount().Value); } result.Items = query.ToList(); } return(result); }) ); }
public IronmanClientDoubleTable(RaceAnalysisDbContext db) : base(db) { }
private static void SeedRaceConditionTag(RaceAnalysisDbContext context) { context.RaceConditionTags.RemoveRange(context.RaceConditionTags); context.SaveChanges(); }