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
1 change: 1 addition & 0 deletions .github/workflows/dotnet-desktop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

25 changes: 25 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: BookStore Build Pipline
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: windows-2022
steps:
- name: Check out
uses: actions/checkout@v2
- name: Setup .Net
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.0.204
include-prerelease: true
- name: Restore
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,4 @@ FodyWeavers.xsd
/src/BookStore.Presentation/MVC/wwwroot/BookPhoto
/src/BookStore.Presentation/MVC/wwwroot/Books
/src/BookStore.Presentation/MVC/wwwroot/UserProfileImage
/ConsoleApp1
24 changes: 19 additions & 5 deletions BookStore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ VisualStudioVersion = 17.8.34316.72
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E63592A0-27C4-4444-BD76-903F182458F1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookStore.Domain", "src\BookStore.Domain\BookStore.Domain.csproj", "{6E8888F1-9B76-421E-ACEF-A499B3D04927}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookStore.Domain", "src\BookStore.Domain\BookStore.Domain.csproj", "{6E8888F1-9B76-421E-ACEF-A499B3D04927}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookStore.Application", "src\BookStore.Application\BookStore.Application.csproj", "{D22C7023-F7E3-468C-AEA1-37B97C680D15}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookStore.Application", "src\BookStore.Application\BookStore.Application.csproj", "{D22C7023-F7E3-468C-AEA1-37B97C680D15}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookStore.Infrastructure", "src\BookStore.Infrastructure\BookStore.Infrastructure.csproj", "{B6A4EF17-870B-4BF7-AAAE-FDC55E5831ED}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookStore.Infrastructure", "src\BookStore.Infrastructure\BookStore.Infrastructure.csproj", "{B6A4EF17-870B-4BF7-AAAE-FDC55E5831ED}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BookStore.Presentation", "BookStore.Presentation", "{3F32713F-015A-4919-93CA-E1A5B34B4863}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "src\BookStore.Presentation\API\API.csproj", "{A71B8C92-ACA9-40D5-B277-E4CA6D2E195D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API", "src\BookStore.Presentation\API\API.csproj", "{A71B8C92-ACA9-40D5-B277-E4CA6D2E195D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MVC", "src\BookStore.Presentation\MVC\MVC.csproj", "{34FD9F69-7D8B-4762-BFF3-11DE5C98CFE9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVC", "src\BookStore.Presentation\MVC\MVC.csproj", "{34FD9F69-7D8B-4762-BFF3-11DE5C98CFE9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{216E730C-ACC0-4053-A332-713E53440962}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookStore.Infrastructure.Build", "src\BookStore.Infrastructure.Build\BookStore.Infrastructure.Build.csproj", "{785D78EE-F055-46F3-A7DD-6F8F488DDF1E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -43,6 +47,14 @@ Global
{34FD9F69-7D8B-4762-BFF3-11DE5C98CFE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{34FD9F69-7D8B-4762-BFF3-11DE5C98CFE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{34FD9F69-7D8B-4762-BFF3-11DE5C98CFE9}.Release|Any CPU.Build.0 = Release|Any CPU
{216E730C-ACC0-4053-A332-713E53440962}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{216E730C-ACC0-4053-A332-713E53440962}.Debug|Any CPU.Build.0 = Debug|Any CPU
{216E730C-ACC0-4053-A332-713E53440962}.Release|Any CPU.ActiveCfg = Release|Any CPU
{216E730C-ACC0-4053-A332-713E53440962}.Release|Any CPU.Build.0 = Release|Any CPU
{785D78EE-F055-46F3-A7DD-6F8F488DDF1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{785D78EE-F055-46F3-A7DD-6F8F488DDF1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{785D78EE-F055-46F3-A7DD-6F8F488DDF1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{785D78EE-F055-46F3-A7DD-6F8F488DDF1E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -54,6 +66,8 @@ Global
{3F32713F-015A-4919-93CA-E1A5B34B4863} = {E63592A0-27C4-4444-BD76-903F182458F1}
{A71B8C92-ACA9-40D5-B277-E4CA6D2E195D} = {3F32713F-015A-4919-93CA-E1A5B34B4863}
{34FD9F69-7D8B-4762-BFF3-11DE5C98CFE9} = {3F32713F-015A-4919-93CA-E1A5B34B4863}
{216E730C-ACC0-4053-A332-713E53440962} = {E63592A0-27C4-4444-BD76-903F182458F1}
{785D78EE-F055-46F3-A7DD-6F8F488DDF1E} = {E63592A0-27C4-4444-BD76-903F182458F1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8C5D27F3-0D32-4A29-AE50-8C54EE56B386}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Mapster;
using MediatR;
using Microsoft.AspNetCore.Hosting;
using System.IO;

namespace BookStore.Application.useCases.Authors.Commands
{
Expand All @@ -24,18 +25,30 @@ public async Task<Author> Handle(CreateAuthorCommand command, CancellationToken
string fileName = "";
try
{
var newFilePath = "";
fileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
filePath = Path.Combine(_webHostEnvironment.WebRootPath, "AuthorsProfileImage", fileName);

using (var stream = new FileStream(filePath, FileMode.Create))

if (!Directory.Exists(newFilePath))
{
await file.CopyToAsync(stream);
for (int i = 0; i < filePath.Split("\\").Length; i++)
{
if (i + 1 != filePath.Split("\\").Length)
newFilePath += filePath.Split("\\")[i] + "\\";
}

Directory.CreateDirectory(newFilePath);
}
}
catch (Exception ex)

using (var stream = new FileStream(filePath, FileMode.Create))
await file.CopyToAsync(stream);

} catch (Exception ex)
{
await Console.Out.WriteLineAsync($"Error: {ex.Message}");
}

var author = command.Adapt<Author>();
author.PhotoPath = "/AuthorsProfileImage/" + fileName;
var res = await _context.Authors.AddAsync(author);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,36 @@ public async Task<Book> Handle(CreateBookCommand request, CancellationToken canc

try
{
var newFilePath = "";

fileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
filePath = Path.Combine(_webHostEnvironment.WebRootPath, "Books", fileName);

PhotofileName = Guid.NewGuid().ToString() + Path.GetExtension(PhotoFile.FileName);
PhotofilePath = Path.Combine(_webHostEnvironment.WebRootPath, "BookPhoto", PhotofileName);

if (!Directory.Exists(filePath))
{
for (int i = 0; i < filePath.Split("\\").Length; i++)
{
if (i + 1 != filePath.Split("\\").Length)
newFilePath += filePath.Split("\\")[i] + "\\";
}

Directory.CreateDirectory(newFilePath);
}

if (!Directory.Exists(PhotofilePath))
{
newFilePath = "";
for (int i = 0; i < PhotofilePath.Split("\\").Length; i++)
{
if (i + 1 != PhotofilePath.Split("\\").Length)
newFilePath += PhotofilePath.Split("\\")[i] + "\\";
}

Directory.CreateDirectory(newFilePath);
}

using (var stream = new FileStream(filePath, FileMode.Create))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<PackageReference Include="ADotNet" Version="3.0.2" />
</ItemGroup>

</Project>
84 changes: 84 additions & 0 deletions src/BookStore.Infrastructure.Build/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using ADotNet.Clients;
using ADotNet.Models.Pipelines.GithubPipelines.DotNets;
using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks;
using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks.SetupDotNetTaskV1s;

var githubPipline = new GithubPipeline
{
Name = "BookStore Build Pipline",
OnEvents = new Events
{
PullRequest = new PullRequestEvent
{
Branches = new string[] { "main" }
},

Push = new PushEvent
{
Branches = new string[] { "main" }
},

},

Jobs = new Dictionary<string, Job>
{
{
"build",
new Job
{
RunsOn = BuildMachines.Windows2022,

Steps = new List<GithubTask>
{
new CheckoutTaskV2
{
Name = "Check out"
},

new SetupDotNetTaskV1
{
Name = "Setup .Net",

TargetDotNetVersion = new TargetDotNetVersion
{
DotNetVersion = "8.0.204",
IncludePrerelease = true
}
},

new RestoreTask
{
Name = "Restore"
},

new DotNetBuildTask
{
Name = "Build"
},

new TestTask
{
Name = "Test"
}
}
}
}
}
};

var client = new ADotNetClient();


string buildScriptPath = "../../../../../.github/workflows/dotnet.yml";
string directoryPath = Path.GetDirectoryName(buildScriptPath)!;

if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}

client.SerializeAndWriteToFile
(
adoPipeline: githubPipline,
path: buildScriptPath
);
6 changes: 0 additions & 6 deletions src/BookStore.Presentation/MVC/MVC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,4 @@
<ProjectReference Include="..\..\BookStore.Infrastructure\BookStore.Infrastructure.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="wwwroot\AuthorsProfileImage\" />
<Folder Include="wwwroot\BookPhoto\" />
<Folder Include="wwwroot\UserProfileImage\" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/BookStore.Presentation/MVC/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5197",
"launchBrowser": false,
"applicationUrl": "http://localhost:5189",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
3 changes: 2 additions & 1 deletion src/BookStore.Presentation/MVC/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"BotToken": "7040566448:AAGuJLoJsg8xqAAW4yWGPkZDR6PIxBlU0ns",
"ConnectionStrings": {
"SQLServer": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=BookStore.MVC.DB;",
"Postgres": "Host=localhost;Port=5432;Username=postgres;Password=sardor0618!;Database=BookStoree.DB"
"Postgres": "Host=localhost;Port=5432;Username=postgres;Password=coder;Database=BookStore.Db"
},
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
Expand All @@ -26,5 +26,6 @@
}
}
]

}
}