Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace DocumentProcessor.davetn657.Data.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Contacts",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false),
PhoneNumber = table.Column<string>(type: "TEXT", nullable: false),
Email = table.Column<string>(type: "TEXT", nullable: false),
Category = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Contacts", x => x.Id);
});
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Contacts");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// <auto-generated />
using DocumentProcessor.davetn657.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

#nullable disable

namespace DocumentProcessor.davetn657.Data.Migrations
{
[DbContext(typeof(PhonebookContext))]
partial class PhonebookContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "10.0.5");

modelBuilder.Entity("DocumentProcessor.davetn657.Data.Models.PhonebookProperties", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");

b.Property<string>("Category")
.IsRequired()
.HasColumnType("TEXT");

b.Property<string>("Email")
.IsRequired()
.HasColumnType("TEXT");

b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");

b.Property<string>("PhoneNumber")
.IsRequired()
.HasColumnType("TEXT");

b.HasKey("Id");

b.ToTable("Contacts");
});
#pragma warning restore 612, 618
}
}
}
10 changes: 10 additions & 0 deletions DocumentProcessor.davetn657/Data/Models/PhonebookProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace DocumentProcessor.davetn657.Data.Models;

public class PhonebookProperties
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string PhoneNumber { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Category { get; set; } = string.Empty;
}
24 changes: 24 additions & 0 deletions DocumentProcessor.davetn657/Data/PhonebookContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using DocumentProcessor.davetn657.Data.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;

namespace DocumentProcessor.davetn657.Data;

public class PhonebookContext : DbContext
{
public DbSet<PhonebookProperties> Contacts { get; set; }
private string DbPath { get; set; }

public PhonebookContext()
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();

DbPath = builder.GetConnectionString("DefaultConnection");
}

protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite(DbPath);
}
Binary file not shown.
30 changes: 30 additions & 0 deletions DocumentProcessor.davetn657/DocumentProcessor.davetn657.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IronPdf" Version="2026.4.1" />
<PackageReference Include="IronXL.Excel" Version="2026.4.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Spectre.Console" Version="0.54.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="DocFiles\" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions DocumentProcessor.davetn657/DocumentProcessor.davetn657.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Solution>
<Project Path="DocumentProcessor.davetn657.csproj" />
</Solution>
Binary file added DocumentProcessor.davetn657/Phonebook.db
Binary file not shown.
30 changes: 30 additions & 0 deletions DocumentProcessor.davetn657/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using DocumentProcessor.davetn657.Data;
using DocumentProcessor.davetn657.Services;
using DocumentProcessor.davetn657.Views;
using IronSoftware.Abstractions.Pdf;
using Microsoft.Extensions.DependencyInjection;

namespace DocumentProcessor.davetn657;

internal class Program
{
static void Main(string[] args)
{
var services = new ServiceCollection()
.AddDbContext<PhonebookContext>()
.AddScoped<IFileReaderService, FileReaderService>()
.AddScoped<IExtensibleRenderer, ChromePdfRenderer>()
.AddScoped<IExportDataService, ExportDataService>()
.AddScoped<IDataSeederService, DataSeederService>()
.AddScoped<UserInterface>()
.BuildServiceProvider();

using var scope = services.CreateScope();

var dataSeeder = scope.ServiceProvider.GetRequiredService<IDataSeederService>();
dataSeeder.SeedIfEmpty();

var ui = scope.ServiceProvider.GetRequiredService<UserInterface>();
ui.Start();
}
}
8 changes: 8 additions & 0 deletions DocumentProcessor.davetn657/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"DocumentProcessor.davetn657": {
"commandName": "Project",
"workingDirectory": "C:\\Users\\davei\\Documents\\.Coding\\.C#Academy\\.Backup\\DocumentProcessor.davetn657\\DocumentProcessor.davetn657"
}
}
}
21 changes: 21 additions & 0 deletions DocumentProcessor.davetn657/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Document Processor Application

## Overview

Console based application that processes data from xlsx or csv file to import into a database or export database data to xlsx, csv, or pdf form.

## Requirements

- Needs to be able to seed data from xlsx or csv files into the database
- If no data is in database needs to auto seed data
- Export data to a pdf
- Handles errors
- Option to import/export data


## Technologies

- C#
- Sqlite
- IronXL
- IronPdf
31 changes: 31 additions & 0 deletions DocumentProcessor.davetn657/Services/DataSeederService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using DocumentProcessor.davetn657.Data;

namespace DocumentProcessor.davetn657.Services;

public interface IDataSeederService
{
public void SeedIfEmpty();
}

public class DataSeederService : IDataSeederService
{
private readonly PhonebookContext _dbContext;
private readonly IFileReaderService _fileReader;
public DataSeederService(PhonebookContext dbContext, IFileReaderService fileReader)
{
_dbContext = dbContext;
_fileReader = fileReader;
}

public void SeedIfEmpty()
{

if (!_dbContext.Contacts.Any())
{
var path = Path.Combine(Directory.GetCurrentDirectory(), "DocFiles");
var contacts = _fileReader.FormatFile(path, "SeedData.xlsx");
_dbContext.Contacts.AddRange(contacts);
_dbContext.SaveChanges();
}
}
}
Loading