Skip to content

Commit

Permalink
add csv reader
Browse files Browse the repository at this point in the history
  • Loading branch information
fabien-ss committed May 11, 2024
1 parent caf2f1d commit 1b055ab
Show file tree
Hide file tree
Showing 39 changed files with 773 additions and 610 deletions.
24 changes: 20 additions & 4 deletions AspnetCoreMvcFull.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,35 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
<PackageReference Include="Xunit.Microsoft.VisualStudio.TestTools.UnitTesting" Version="1.0.0-beta-1011" />
</ItemGroup>

<ItemGroup>
<Folder Include="wwwroot\uploads\" />
<Folder Include="Controllers\ModalController\" />
<Folder Include="Pages\" />
<Folder Include="wwwroot\uploads\documents\csv\" />
<Folder Include="wwwroot\uploads\images\" />
</ItemGroup>

<ItemGroup>
<_ContentIncludedByDefault Remove="Views\Chauffeur\Create.cshtml" />
<_ContentIncludedByDefault Remove="Views\Chauffeur\Delete.cshtml" />
<_ContentIncludedByDefault Remove="Views\Chauffeur\Details.cshtml" />
<_ContentIncludedByDefault Remove="Views\Chauffeur\Edit.cshtml" />
<_ContentIncludedByDefault Remove="Views\Chauffeur\Index.cshtml" />
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="Views\Csv\Form.cshtml" />
<AdditionalFiles Include="Views\Csv\Formulaire.cshtml" />
</ItemGroup>

</Project>
54 changes: 0 additions & 54 deletions Controllers/AppLayoutController/AuthController.cs

This file was deleted.

18 changes: 0 additions & 18 deletions Controllers/AppLayoutController/CsvController.cs

This file was deleted.

18 changes: 16 additions & 2 deletions Controllers/AppLayoutController/DashboardsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,31 @@ public class DashboardsController : Controller
{
public DashboardsController()
{
try
{
HttpContext.Session.GetString("user");
}
catch (Exception e)
{
ModelState.AddModelError("Login", "Log to see more");
RedirectToAction("LoginBasic", "Auth");

}
}

public IActionResult Index()
{
string user = HttpContext.Session.GetString("user");

Chauffeur chauffeur = JsonSerializer.Deserialize<Chauffeur>(user);
Utilisateur chauffeur = JsonSerializer.Deserialize<Utilisateur>(user);
Console.WriteLine("user "+ user);
Console.WriteLine("ALORS");
/*
*/
return View();
}

public IActionResult BigNotification()
{
return View();
}
}
74 changes: 74 additions & 0 deletions Controllers/AppLayoutController/auth/AuthController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System.Diagnostics;
using System.Security.Cryptography;
using System.Text.Json;
using AspnetCoreMvcFull.Context;
using AspnetCoreMvcFull.Entities;
using Microsoft.AspNetCore.Mvc;
using AspnetCoreMvcFull.Models;
using AspnetCoreMvcFull.Models.DTO;

namespace AspnetCoreMvcFull.Controllers;

public class AuthController : Controller, MethodController
{
private Tsakitsaky Tsakitsaky;
public AuthController(Tsakitsaky prom13)
{
this.Tsakitsaky = prom13;
}

public IActionResult ForgotPasswordBasic() => View();

[HttpGet]
public IActionResult LoginBasic()
{
return View();
}

[HttpGet]
public IActionResult RegisterBasic()
{
return View();
}
public IActionResult LoginBasic(LoginDto loginDto)
{
if (ModelState.IsValid)
{
try
{
Utilisateur user = (Utilisateur) loginDto.mapDtoToEntity();
user = user.getChauffeur(prom13: this.Tsakitsaky);
HttpContext.Session.SetString("user", value: JsonSerializer.Serialize(user));
return Redirect("Dashboards/Index");
}
catch (Exception e)
{
ModelState.AddModelError("Error", e.Message);
}
}
return View(loginDto);
}

public IActionResult RegisterBasic(RegisterDto registerDto)
{
if (ModelState.IsValid)
{
var user = registerDto.mapDtoToEntity();
TempData["user"] = user;
HttpContext.Session.SetString("user", JsonSerializer.Serialize(user));
return Redirect("Dashboards/Index");
}
return View(registerDto);
}

public IActionResult Logout()
{
HttpContext.Session.Clear();
return Redirect("/Auth/LoginBasic");
}

public IActionResult Form(object o)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace AspnetCoreMvcFull.Models.DTO;

public class LoginModel : Dto
public class LoginDto : Dto
{

private string _email;
Expand All @@ -29,7 +29,7 @@ public string Password

public object mapDtoToEntity()
{
Chauffeur chauffeur = new Chauffeur
Utilisateur chauffeur = new Utilisateur
{
Email = this.Email,
MotDePasse = this.Password
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace AspnetCoreMvcFull.Models.DTO;

public class RegisterModel: Dto
public class RegisterDto: Dto
{

[Required(ErrorMessage = "Le nom est obligatoire.")]
Expand Down
43 changes: 43 additions & 0 deletions Controllers/AppLayoutController/csv/CsvController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;

namespace AspnetCoreMvcFull.Controllers;

public class CsvController: Controller, MethodController
{
private readonly IWebHostEnvironment _hostEnvironment;
public CsvController(IWebHostEnvironment hostingEnvironment)
{
this._hostEnvironment = hostingEnvironment;
}

[HttpGet]
public IActionResult Index()
{
Console.WriteLine("ETP ");
return View();
}
[HttpPost
]
public IActionResult Index(CsvDto csvDto)
{
if (ModelState.IsValid)
{
csvDto.saveFile(_hostEnvironment.WebRootPath);
}
ViewBag.title = "Formulaire csv";
return View(csvDto);
}

public IActionResult Form(object o)
{
throw new NotImplementedException();
}

public IActionResult UploadFiles(List<IFormFile> files)
{

return null;
}
}
31 changes: 31 additions & 0 deletions Controllers/AppLayoutController/csv/CsvDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace AspnetCoreMvcFull.Controllers;

public class CsvDto
{
private IFormFile csv;
private string targetTable;

public IFormFile Csv
{
get => csv;
set => csv = value ?? throw new ArgumentNullException(nameof(value));
}

public string TargetTable
{
get => targetTable;
set => targetTable = value ?? throw new ArgumentNullException(nameof(value));
}

public void saveFile(string filePath)
{
if (this.Csv != null && this.Csv.Length > 0 && this.Csv.FileName.Contains(".csv"))
{
var path = Path.Combine(filePath, "uploads/documents/csv/", this.Csv.FileName);
using (var stream = System.IO.File.Create(path))
{
this.Csv.CopyTo(stream);
}
}
}
}
Loading

0 comments on commit 1b055ab

Please sign in to comment.