Esempio n. 1
0
        public static IEnumerable<Route> Import(string filename, ClimbrContext context)
        {
            var excel = new ExcelQueryFactory(filename);
            var sheetRoutes = excel.Worksheet<SheetRoute>()
                .Where(r => r.Grade != "#REF!" && r.Grade != null)
                .ToList();

            for (int i = 1; i < sheetRoutes.Count; i++)
            {
                if (sheetRoutes[i].Line == null || sheetRoutes[i].Line == "#REF!")
                {
                    sheetRoutes[i].Line = sheetRoutes[i - 1].Line;
                }
            }

            var routes = sheetRoutes.Select(
                sr => new Route
                {
                    Color = context.Colors.Single(c => c.Name.Equals(sr.Colour, StringComparison.InvariantCultureIgnoreCase)),
                    Grade = context.Grades.Single(g => g.Name.Equals(sr.Grade, StringComparison.InvariantCultureIgnoreCase)),
                    Name = sr.Line
                })
                .ToList();

            return routes;
        }
Esempio n. 2
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            Database.SetInitializer<ClimbrContext>(new Migrations.MyDbInitialiser());
            using (var context = new ClimbrContext())
            {
                context.Database.Initialize(false);
            }

            if (!WebSecurity.Initialized)
            {
                WebSecurity.InitializeDatabaseConnection(
                    "DefaultConnection",
                    "Users",
                    "Id",
                    "UserName",
                    autoCreateTables: false);
            }

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            BundleMobileConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();
        }
Esempio n. 3
0
        public void TestMethod1()
        {
            using (var context = new ClimbrContext())
            {
                var routes = AwesomeImporter.Import("Resources\\AwesomeTickList.xlsx", context);

                var admin = context.Users.Single(u => u.UserName == "admin").Id;
                var location = context.Locations.First().Id;
                var lead = context.ClimbTypes.Single(ct => ct.Name == "Lead").Id;

                foreach (var route in routes)
                {
                    route.AddedById = admin;
                    route.LocationId =location;
                    route.DefaultClimbTypeId = lead;
                    context.Routes.Add(route);
                }

                context.SaveChanges();
            }
        }
Esempio n. 4
0
 //
 // GET: /Climb/
 public ClimbController(ClimbrContext context)
     : base(context)
 {
 }
Esempio n. 5
0
 public HomeController(ClimbrContext context)
     : base(context)
 {
 }
Esempio n. 6
0
 //
 // GET: /Route/
 public RouteController(ClimbrContext context)
     : base(context)
 {
 }
Esempio n. 7
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (ClimbrContext db = new ClimbrContext())
                {
                    User user = db.Users.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.Users.Add(new User { UserName = model.UserName });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return RedirectToLocal(returnUrl);
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
Esempio n. 8
0
 //
 // GET: /Location/
 public LocationController(ClimbrContext context)
     : base(context)
 {
 }
Esempio n. 9
0
 //
 // GET: /Grade/
 public GradeController(ClimbrContext context)
     : base(context)
 {
 }
Esempio n. 10
0
 public ClimbrController(ClimbrContext context)
 {
     db = context;
 }