Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, CalmContext calmContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            if (Configuration.GetValue("UseHttpsRedirection", defaultValue: true) is true)
            {
                app.UseHttpsRedirection();
            }

            app.UseRouting();

            app.UseCors(CorsPolicyName);

            app.UseAuthorization();

            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v0/swagger.json", "My API V1");
            });

            calmContext.Database.Migrate();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Exemplo n.º 2
0
        private void OpenContext()
        {
            connection = new System.Data.SQLite.SQLiteConnection("Data Source=:memory:");

            connection.Open();

            var temp = new CalmContext(
                new DbContextOptionsBuilder <CalmContext>()
                .UseSqlite(connection)
                .Options);

            temp.Database.Migrate();
            Seeder.Seed(temp);
            temp.SaveChanges();

            temp.Dispose();
        }
Exemplo n.º 3
0
        public static void Seed(CalmContext context)
        {
            context.Links.RemoveRange(context.Links);
            context.Admins.RemoveRange(context.Admins);
            context.Users.RemoveRange(context.Users);
            context.Gatherings.RemoveRange(context.Gatherings);
            context.Citys.RemoveRange(context.Citys);
            context.SaveChanges();

            Func <string, int> CityId = x =>
            {
                return((from item in context.Citys.ToList()
                        where item.city.Contains(x)
                        select item.Id).FirstOrDefault());
            };
            Func <string, int> UserId = x =>
            {
                return((from item in context.Users.ToList()
                        where item.FName.Contains(x)
                        select item.Id).FirstOrDefault());
            };
            Func <string, string, string, string, bool, string, string, Gathering> gather =
                (title, details, occurance, map, isEvent, u1, u2) =>
                new Gathering()
            {
                Title          = title,
                details        = details,
                occurrenceData = occurance,
                organizerId    = context.Admins.FirstOrDefault().user.Id,
                MapDataId      = CityId(map),
                isEvent        = isEvent,
                links          = new List <Link>
                {
                    new Link {
                        userId = UserId(u1)
                    },
                    new Link {
                        userId = UserId(u2)
                    }
                }
            };

            context.Citys.AddRange(
                new Mapdata()
            {
                city = "Houston, TX"
            },
                new Mapdata()
            {
                city = "Dallas, TX"
            },
                new Mapdata()
            {
                city = "Nashville, TN"
            },
                new Mapdata()
            {
                city = "Minneapolis, MN"
            },
                new Mapdata()
            {
                city = "Kansas City, MI"
            },
                new Mapdata()
            {
                city = "New York, NY"
            },
                new Mapdata()
            {
                city = "Los Angeles, CA"
            },
                new Mapdata()
            {
                city = "Chicago, IL"
            },
                new Mapdata()
            {
                city = "Seattle, WA"
            },
                new Mapdata()
            {
                city = "Atlanta, GA"
            },
                new Mapdata()
            {
                city = "Orlando, FL"
            },
                new Mapdata()
            {
                city = "Washington DC,"
            },
                new Mapdata()
            {
                city = "New Orleans, LA"
            },
                new Mapdata()
            {
                city = "Denver, CO"
            },
                new Mapdata()
            {
                city = "San Francisco, CA"
            },
                new Mapdata()
            {
                city = "Detroit, MI"
            },
                new Mapdata()
            {
                city = "Online"
            });

            context.SaveChanges();

            context.Admins.AddRange(new AdminInfo()
            {
                SuperAdmin = true,
                user       = new User()
                {
                    FName = "admin", LName = "user", Username = "******", Password = "******", MapDataId = CityId("Houston")
                }
            });

            context.Users.AddRange(
                new User()
            {
                FName = "Samuel", LName = "Philander", Username = "******", Password = "******", MapDataId = CityId("Dallas")
            },
                new User()
            {
                FName = "Andrew", LName = "Jackson", Username = "******", Password = "******", MapDataId = CityId("Houston")
            },
                new User()
            {
                FName = "Ulysses", LName = "Grant", Username = "******", Password = "******", MapDataId = CityId("Dallas")
            },
                new User()
            {
                FName = "Rutherford", LName = "Hayes", Username = "******", Password = "******", MapDataId = CityId("Houston")
            },
                new User()
            {
                FName = "James", LName = "Garfield", Username = "******", Password = "******", MapDataId = CityId("Houston")
            },
                new User()
            {
                FName = "Chester", LName = "Aurthur", Username = "******", Password = "******", MapDataId = CityId("Dallas")
            },
                new User()
            {
                FName = "Grover", LName = "Cleveland", Username = "******", Password = "******", MapDataId = CityId("Dallas")
            },
                new User()
            {
                FName = "Benjamin", LName = "Harrison", Username = "******", Password = "******", MapDataId = CityId("Dallas")
            },
                new User()
            {
                FName = "Theadore", LName = "Roosevelt", Username = "******", Password = "******", MapDataId = CityId("Houston")
            },
                new User()
            {
                FName = "William", LName = "McKinley", Username = "******", Password = "******", MapDataId = CityId("Houston")
            });

            context.SaveChanges();

            context.Gatherings.AddRange(
                gather(
                    "Marvin’s Room: with guest Drake",
                    "Location: TBA",
                    "June 12th",
                    "Houston",
                    true,
                    "Samuel",
                    "Andrew"),
                gather(
                    "Love and Happiness: with guest Kevin Love",
                    "",
                    "June 12th",
                    "Online",
                    true,
                    "Ulysses",
                    "Samuel"),
                gather(
                    "Struggles of Balance: guest Demi Lovato",
                    "",
                    "August 1st",
                    "Online",
                    true,
                    "Ulysses",
                    "Andrew"),
                gather(
                    "Generalized Anxiety",
                    "",
                    "Monday - Friday",
                    "Dallas",
                    false,
                    "Samuel",
                    "Rutherford"),
                gather(
                    "Post Traumatic Anxiety Disorder",
                    "",
                    "Monday - Friday",
                    "Dallas",
                    false,
                    "Grover",
                    "Chester"),
                gather(
                    "Social Anxiety",
                    "",
                    "Monday - Friday",
                    "Online",
                    false,
                    "James",
                    "Ulysses"),
                gather(
                    "Panic Disorder",
                    "",
                    "Monday - Friday",
                    "Dallas",
                    false,
                    "Samuel",
                    "James"),
                gather(
                    "Obsessive Compulsive Disorder",
                    "",
                    "Monday - Friday",
                    "Online",
                    false,
                    "Theadore",
                    "William"),
                gather(
                    "Specific phobias",
                    "",
                    "Monday - Friday",
                    "Dallas",
                    false,
                    "Samuel",
                    "Benjamin"));

            context.SaveChanges();
        }
Exemplo n.º 4
0
        public ActionResult SeedData([FromServices] CalmContext context)
        {
            Seeder.Seed(context);

            return(Ok());
        }