Skip to content

Commit

Permalink
Projektdateien hinzufügen.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahim324 committed Jan 17, 2022
1 parent 2102c03 commit dcaeff3
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 0 deletions.
25 changes: 25 additions & 0 deletions LeadsApi.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LeadsApi", "LeadsApi\LeadsApi.csproj", "{9BB832F5-7A14-4515-AC8C-2C5BAD1AF880}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9BB832F5-7A14-4515-AC8C-2C5BAD1AF880}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9BB832F5-7A14-4515-AC8C-2C5BAD1AF880}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9BB832F5-7A14-4515-AC8C-2C5BAD1AF880}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9BB832F5-7A14-4515-AC8C-2C5BAD1AF880}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2B1393CD-190F-4143-AEA3-F0C282C62761}
EndGlobalSection
EndGlobal
13 changes: 13 additions & 0 deletions LeadsApi/EFCoreModels/Lead.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;

namespace LeadsApi.EFCoreModels
{
public partial class Lead
{
public int? Id { get; set; }
public string? Name { get; set; }
public string? ZipCode { get; set; }
public double? ConversionProb { get; set; }
}
}
45 changes: 45 additions & 0 deletions LeadsApi/EFCoreModels/LeadsDatabaseContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace LeadsApi.EFCoreModels
{
public partial class LeadsDatabaseContext : DbContext
{
public LeadsDatabaseContext()
{
}

public LeadsDatabaseContext(DbContextOptions<LeadsDatabaseContext> options)
: base(options)
{
}

public virtual DbSet<Lead> Leads { get; set; } = null!;

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlite("Name=ConnectionStrings:LeadsDatabaseContext");
}
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Lead>(entity =>
{
entity.HasNoKey();

entity.ToTable("Lead");

entity.Property(e => e.Id).HasColumnType("Integer");
});

OnModelCreatingPartial(modelBuilder);
}

partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
}
23 changes: 23 additions & 0 deletions LeadsApi/LeadsApi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
Binary file added LeadsApi/LeadsDatabase.db
Binary file not shown.
23 changes: 23 additions & 0 deletions LeadsApi/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.EntityFrameworkCore;
using LeadsApi.EFCoreModels;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<LeadsDatabaseContext>(opt =>
opt.UseSqlite("Filename=LeadsDatabase.db"));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();

var app = builder.Build();

app.MapGet("/", () => "Welcome to the Leads-API!");

app.MapGet("/leads", async (LeadsDatabaseContext dbContext) =>
await dbContext.Leads.Select(lead => lead).ToListAsync());

app.MapGet("/leads/{name}", async (string name, LeadsDatabaseContext dbContext) =>
await dbContext.Leads
.Where(lead => lead.Name.Contains(name))
.Select(lead => lead)
.ToListAsync());


app.Run();
31 changes: 31 additions & 0 deletions LeadsApi/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:24141",
"sslPort": 0
}
},
"profiles": {
"LeadsApi": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "",
"applicationUrl": "http://localhost:5107",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
8 changes: 8 additions & 0 deletions LeadsApi/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
15 changes: 15 additions & 0 deletions LeadsApi/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"LeadsDatabaseContext": "Data Source=LeadsDatabase.db"
// How to use in CLI for dotnet ef:
// dotnet ef dbcontext scaffold Name=ConnectionStrings:LeadsDatabaseContext
// -o EFCoreModels Microsoft.EntityFrameworkCore.Sqlite --no-build
},
"AllowedHosts": "*"
}
64 changes: 64 additions & 0 deletions LeadsApi/create_leads_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env python3

"""
Autor: Halil Ibrahim Özcan
Beschreibung:
Erstellt eine neue SQLite-Datenbank und füllt diese
mit Test-Daten
"""

import sqlite3
import random


Id = [i for i in range(10)]

names = ['Mayra Ewing',
'Emery Roach',
'Ryan Galloway',
'Jamir Oneill',
'Carl Bailey',
'Ashlynn Scott',
'Ryland Yoder',
'Lucian Barajas',
'Dania Lopez',
'Wesley Key']

zip_codes = ["30223",
"22003",
"92111",
"99504",
"14580",
"10956",
"10512",
"08817",
"20815",
"23059"]

random_probs = [round(random.uniform(0, 1), 2) for i in range(10)]

zipped_data = list(zip(Id, names, zip_codes, random_probs))

def main():
try:
connection = sqlite3.connect("LeadsDatabase.db")
create_db_sql = '''CREATE TABLE IF NOT EXISTS
Lead (Id Integer,
Name TEXT,
ZipCode TEXT,
ConversionProb REAL);'''
connection.execute(create_db_sql)
insert_data_sql = "INSERT INTO Lead VALUES(?, ?, ?, ?)"
connection.executemany(insert_data_sql, zipped_data)

except ConnectionError as e:
print(e)

finally:
if connection:
connection.commit()
connection.close()


if __name__ == '__main__':
main()

0 comments on commit dcaeff3

Please sign in to comment.