activity server

sections

  • graphql
    • Queries
    • Mutations
  • Application
    • Queries
      • GetClientTimeEntriesByMonth
    • Commands (mutation)

migrations

Apply the migrations to the database
dotnet ef database update --connection "<your connection string>"

Add migraion
dotnet ef migrations add InitialCreate

Remove latest migration instructions (cannot remove once applied)
dotnet ef migrations remove InitialCreate --force

ActivityContextFactory

using Microsoft.EntityFrameworkCore.Design; namespace Activity.Infrastructure; public class ActivityContextFactory: IDesignTimeDbContextFactory<ActivityContext> { public ActivityContext CreateDbContext(string[] args) { var optionsBuilder = new DbContextOptionsBuilder<ActivityContext>().UseSqlServer(); return new ActivityContext(optionsBuilder.Options); } }

csproj

<ItemGroup> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.9" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.9"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <PrivateAssets>all</PrivateAssets> </PackageReference> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.9" /> </ItemGroup>

connection string

"server=localhost,9301;database=skd;uid=sa;pwd=DevDevDude119#;MultipleActiveResultSets=True;Encrypt=false;TrustServerCertificate=False;Connection Timeout=30;"

entiteis

namespace Activity.Domain.Model; public abstract class BaseEntity { public Guid Id { get; set; } public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow; public DateTimeOffset? RemovedAt { get; set; } } public class Company : BaseEntity { public string Name { get; private set; } = null!; public string? Address { get; private set; } = null!; public string Email { get; private set; } = null!; public string Phone { get; private set; } = null!; public decimal VATPercent { get; private set; } public string? CurrencyCode { get; private set; } = null!; public string? PaymentTerms { get; private set; } = null!; public List<Invoice> Invoices { get; set; } = new(); public static int MAX_COMPANY_NAME_LEN = 100; public static int MAX_ADDRESS_LEN = 500; public static int MAX_EMAIL_LEN = 100; public static int MAX_PHONE_LEN = 20; public static int MAX_CURRENCY_CODE_LEN = 3; public static int MAX_PAYMENT_TERMS_LEN = 100; } public class Client : BaseEntity { public string CompanyName { get; set; } = null!; public string Address { get; set; } = null!; public string Email { get; set; } = null!; public string Phone { get; set; } = null!; public string PaymentTerms { get; set; } = null!; public List<Invoice> Invoices { get; set; } = new(); public List<TimeEntry> TimeEntries { get; set; } = new(); public List<Project> Projects { get; set; } = new(); public static int MAX_COMPANY_NAME_LEN = 100; public static int MAX_ADDRESS_LEN = 500; public static int MAX_EMAIL_LEN = 100; public static int MAX_PHONE_LEN = 20; } namespace Activity.Domain.Model; public class User: BaseEntity { public string Name { get; set; } = null!; public string Email { get; set; } = null!; public List<TimeEntry> TimeEntries { get; set; } = new(); public static int MAX_NAME_LEN = 100; public static int MAX_EMAIL_LEN = 100; } public class Invoice: BaseEntity { public int Year { get; set; } public int Number { get; set; } public DateTime InvoiceDate { get; set; } public DateTime DueDate { get; set; } public decimal Subtotal { get; set; } public decimal Tax { get; set; } public decimal Total { get; set; } public Guid ClientId { get; set; } public Client Client { get; set; } = null!; public Guid CompanyId { get; set; } public Company Company { get; set; } = null!; public List<InvoiceLineItem> LineItems { get; set; } = new(); } public class InvoiceLineItem: BaseEntity { public decimal Price { get; set; } public decimal Quantity { get; set; } public string Unit { get; set; }= null!; public decimal LineItemTotal { get; set; } public string Description { get; set; }= null!; public Guid InvoiceId { get; set; } public Invoice Invoice { get; set; }= null!; public List<TimeEntry> TimeEntries { get; set; } = new(); } public class Project: BaseEntity { public string Code { get; set; } = null!; public string Name { get; set; } = null!; public string Description { get; set; } = null!; public Guid ClientId { get; set; } public Client Client { get; set; } = null!; public List<TimeEntry> TimeEntries { get; set; } = new(); } public class Receipt : BaseEntity { public int Year { get; set; } public int Number { get; set; } public DateTime ReceiptDate { get; set; } public decimal Amount { get; set; } public decimal Tax { get; set; } public decimal Total { get; set; } public string Description { get; set; } = null!; public Invoice Invoice { get; set; } = null!; } namespace Activity.Domain.Model; public class TimeEntry : BaseEntity { public DateTimeOffset Start { get; set; } public DateTimeOffset? End { get; set; } public decimal Hours { get; set; } public string Description { get; set; } = null!; public int ClientId { get; set; } public Client Client { get; set; } = null!; public Guid DeveloperId { get; set; } public Developer Developer { get; set; } = null!; public Guid ProjectId { get; set; } public Project Project { get; set; } = null!; public InvoiceLineItem? InvoiceLineItem { get; set; } }

Folder structure

CreateCompnay
UpdateCompany

CreateClient
UpdateClient

CreateClientProject
UpdateClientProject
RemoveClientProject
RestoreCleintProject

CreateUser
UpdateUser

CreateTimeEntry
UpdateTimeEntry
RemoveTimeEntry
RestoreTimeEntry

CreateInvoice
CreateReceipt

- Domain
  - Models
    - Company.cs
    - Client.cs
    - Project.cs
    - TimeEntry.cs
    - User.cs
    - Invoice.cs
    - InvoiceLineItem.cs
    - Receipt.cs
- Infrastructure
  - ActivityDbContext.cs
  - Configuration
    - CompanyConfiguration.cs
    - ProjectConfiguration.cs
    - ClientConfiguration.cs
    - UserConfiguration.cs
    - TimeEntryConfiguration.cs
    - InvoiceConfiguration.cs
    - IncoiceLineItemConfiguration.cs
    - ReceiptConfiguration.cs
  - ActivityDbContextFactory.cs
- Application
  - Result
    - Result.cs
    - Error.cs
  - Mutations
    - CreateCompany
      - CreateCompany.cs
      - CreateCompanyInput.cs
      - CreateCompanyPayload.cs
      - CreateCompanyValidator.cs
    - UpdateCompany
      - UpdateCompany.cs
      - UpdateCompanyInput.cs
      - UpdateCompanyPayload.cs
      - UpdateCompanyValidator.cs
    - RemoveCompany
    - RestoreCompany
    - CreateClient
      - CreateClient.cs
      - CreateClientInput.cs
      - CreateClientPayload.cs
    - UpdateClient
    - CreateClientProject
    - UpdateClientProject
    - RemoveClientProject
    - RestoreClietntProject
    - CreateUser
    - UpdateUser
    - CreateTimeEntry
    - UpdateTimeEntry
    - RemoveTimeEntry
    - RestoreTimeEntry
    - CreateInvoice
    - CreateReceipt 
  - Queries
    - Client
      - ClientDetailQuery.cs
      - ClientDetailQueryInput.cs
      - ClientDetailQueryPayload.cs
      - ClientTimeEntriesForMonthQuery.cs
      - ClientTimeEntriesForMonthQueryInput.cs
      - ClientTimeEntriesForMonthQueryPaylaod.cs
    - User
      - UserTimeEntriesFormMonth
      - UserTimeEntriesForMonthInput
      - UserTimeEntriesForMonthPayload
    - Project
      - ProjectTimeEntriesForMonth
      - ProjectTimeEntriesForMonthInput
      - ProjectTimeEntriesForMonthPayload
- Api
  - Program.cs
  - Resolvers
    - Mutation
      - Muation.cs
      - CompanyMutation.cs
      - ClientMutation.cs
      - InvoiceMutation.cs
      - ReceiptMutation.cs
    - Query
      - Query.cs
      - ClientQuery.cs
      - UserQuery.cs
      - ProjectQuery.cs
    - Subscriptions
  - Configuration
    - DependencyInjection.cs
    - Appsettings.cs