This commit is contained in:
David Štaleker
2025-07-18 05:33:16 +02:00
parent 401a367e5d
commit db0cc8d3de
14776 changed files with 9251484 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
@page
@model EveryThing.Pages.Files.CreateModel
<h4>File</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="File.IdCompanyFk" class="control-label"></label>
<select asp-for="File.IdCompanyFk" class ="form-control" asp-items="ViewBag.IdCompanyFk"></select>
</div>
<div class="form-group">
<label asp-for="File.FileType" class="control-label"></label>
<select asp-for="File.FileType" class="form-control"></select>
<span asp-validation-for="File.FileType" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File.IdReferenceFk" class="control-label"></label>
<input asp-for="File.IdReferenceFk" class="form-control" />
<span asp-validation-for="File.IdReferenceFk" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File.Guid" class="control-label"></label>
<input asp-for="File.Guid" class="form-control" />
<span asp-validation-for="File.Guid" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File.Extension" class="control-label"></label>
<input asp-for="File.Extension" class="form-control" />
<span asp-validation-for="File.Extension" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File.Salt" class="control-label"></label>
<input asp-for="File.Salt" class="form-control" />
<span asp-validation-for="File.Salt" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File.Iv" class="control-label"></label>
<input asp-for="File.Iv" class="form-control" />
<span asp-validation-for="File.Iv" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File.Title" class="control-label"></label>
<input asp-for="File.Title" class="form-control" />
<span asp-validation-for="File.Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File.DateOfUpload" class="control-label"></label>
<input asp-for="File.DateOfUpload" class="form-control" />
<span asp-validation-for="File.DateOfUpload" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File.Note" class="control-label"></label>
<input asp-for="File.Note" class="form-control" />
<span asp-validation-for="File.Note" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
</div>
</div>
<div>
<a asp-page="Index">Back to List</a>
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}

View File

@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using EveryThing.Data;
using EveryThing.Models;
namespace EveryThing.Pages.Files
{
public class CreateModel : PageModel
{
private readonly ApplicationDbContext _context;
public CreateModel(ApplicationDbContext context)
{
_context = context;
}
public IActionResult OnGet()
{
ViewData["IdCompanyFk"] = new SelectList(_context.CodeTableCompanies, "IdCompany", "Ceo");
return Page();
}
[BindProperty]
public new File File { get; set; }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see https://aka.ms/RazorPagesCRUD.
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
_context.Files.Add(File);
await _context.SaveChangesAsync();
return RedirectToPage("./Index");
}
}
}

View File

@@ -0,0 +1,76 @@
@page
@model EveryThing.Pages.Files.DeleteModel
<h3>Are you sure you want to delete this?</h3>
<div>
<h4>File</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.File.FileType)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.File.FileType)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.File.IdReferenceFk)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.File.IdReferenceFk)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.File.Guid)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.File.Guid)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.File.Extension)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.File.Extension)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.File.Salt)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.File.Salt)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.File.Iv)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.File.Iv)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.File.Title)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.File.Title)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.File.DateOfUpload)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.File.DateOfUpload)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.File.Note)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.File.Note)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.File.Company)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.File.Company.Ceo)
</dd>
</dl>
<form method="post">
<input type="hidden" asp-for="File.IdFile" />
<input type="submit" value="Delete" class="btn btn-danger" /> |
<a asp-page="./Index">Back to List</a>
</form>
</div>

View File

@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using EveryThing.Data;
using EveryThing.Models;
namespace EveryThing.Pages.Files
{
public class DeleteModel : PageModel
{
private readonly ApplicationDbContext _context;
public DeleteModel(ApplicationDbContext context)
{
_context = context;
}
[BindProperty]
public new File File { get; set; }
public async Task<IActionResult> OnGetAsync(int? id)
{
if (id == null)
{
return NotFound();
}
File = await _context.Files
.Include(f => f.Company).FirstOrDefaultAsync(m => m.IdFile == id);
if (File == null)
{
return NotFound();
}
return Page();
}
public async Task<IActionResult> OnPostAsync(int? id)
{
if (id == null)
{
return NotFound();
}
File = await _context.Files.FindAsync(id);
if (File != null)
{
_context.Files.Remove(File);
await _context.SaveChangesAsync();
}
return RedirectToPage("./Index");
}
}
}

View File

@@ -0,0 +1,73 @@
@page
@model EveryThing.Pages.Files.DetailsModel
<div>
<h4>File</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.File.FileType)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.File.FileType)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.File.IdReferenceFk)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.File.IdReferenceFk)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.File.Guid)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.File.Guid)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.File.Extension)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.File.Extension)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.File.Salt)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.File.Salt)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.File.Iv)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.File.Iv)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.File.Title)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.File.Title)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.File.DateOfUpload)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.File.DateOfUpload)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.File.Note)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.File.Note)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.File.Company)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.File.Company.Ceo)
</dd>
</dl>
</div>
<div>
<a asp-page="./Edit" asp-route-id="@Model.File.IdFile">Edit</a> |
<a asp-page="./Index">Back to List</a>
</div>

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using EveryThing.Data;
using EveryThing.Models;
namespace EveryThing.Pages.Files
{
public class DetailsModel : PageModel
{
private readonly ApplicationDbContext _context;
public DetailsModel(ApplicationDbContext context)
{
_context = context;
}
public new File File { get; set; }
public async Task<IActionResult> OnGetAsync(int? id)
{
if (id == null)
{
return NotFound();
}
File = await _context.Files
.Include(f => f.Company).FirstOrDefaultAsync(m => m.IdFile == id);
if (File == null)
{
return NotFound();
}
return Page();
}
}
}

View File

@@ -0,0 +1,74 @@
@page
@model EveryThing.Pages.Files.EditModel
<h4>File</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="File.IdFile" />
<div class="form-group">
<label asp-for="File.IdCompanyFk" class="control-label"></label>
<select asp-for="File.IdCompanyFk" class="form-control" asp-items="ViewBag.IdCompanyFk"></select>
<span asp-validation-for="File.IdCompanyFk" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File.FileType" class="control-label"></label>
<select asp-for="File.FileType" class="form-control"></select>
<span asp-validation-for="File.FileType" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File.IdReferenceFk" class="control-label"></label>
<input asp-for="File.IdReferenceFk" class="form-control" />
<span asp-validation-for="File.IdReferenceFk" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File.Guid" class="control-label"></label>
<input asp-for="File.Guid" class="form-control" />
<span asp-validation-for="File.Guid" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File.Extension" class="control-label"></label>
<input asp-for="File.Extension" class="form-control" />
<span asp-validation-for="File.Extension" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File.Salt" class="control-label"></label>
<input asp-for="File.Salt" class="form-control" />
<span asp-validation-for="File.Salt" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File.Iv" class="control-label"></label>
<input asp-for="File.Iv" class="form-control" />
<span asp-validation-for="File.Iv" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File.Title" class="control-label"></label>
<input asp-for="File.Title" class="form-control" />
<span asp-validation-for="File.Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File.DateOfUpload" class="control-label"></label>
<input asp-for="File.DateOfUpload" class="form-control" />
<span asp-validation-for="File.DateOfUpload" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File.Note" class="control-label"></label>
<input asp-for="File.Note" class="form-control" />
<span asp-validation-for="File.Note" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Save" class="btn btn-primary" />
</div>
</form>
</div>
</div>
<div>
<a asp-page="./Index">Back to List</a>
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}

View File

@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using EveryThing.Data;
using EveryThing.Models;
namespace EveryThing.Pages.Files
{
public class EditModel : PageModel
{
private readonly ApplicationDbContext _context;
public EditModel(ApplicationDbContext context)
{
_context = context;
}
[BindProperty]
public new File File { get; set; }
public async Task<IActionResult> OnGetAsync(int? id)
{
if (id == null)
{
return NotFound();
}
File = await _context.Files
.Include(f => f.Company).FirstOrDefaultAsync(m => m.IdFile == id);
if (File == null)
{
return NotFound();
}
ViewData["IdCompanyFk"] = new SelectList(_context.CodeTableCompanies, "IdCompany", "Ceo");
return Page();
}
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see https://aka.ms/RazorPagesCRUD.
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
_context.Attach(File).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!FileExists(File.IdFile))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToPage("./Index");
}
private bool FileExists(int id)
{
return _context.Files.Any(e => e.IdFile == id);
}
}
}

View File

@@ -0,0 +1,84 @@
@page
@model EveryThing.Pages.Files.IndexModel
<p>
<a asp-page="Create">Create New</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.File[0].FileType)
</th>
<th>
@Html.DisplayNameFor(model => model.File[0].IdReferenceFk)
</th>
<th>
@Html.DisplayNameFor(model => model.File[0].Guid)
</th>
<th>
@Html.DisplayNameFor(model => model.File[0].Extension)
</th>
<th>
@Html.DisplayNameFor(model => model.File[0].Salt)
</th>
<th>
@Html.DisplayNameFor(model => model.File[0].Iv)
</th>
<th>
@Html.DisplayNameFor(model => model.File[0].Title)
</th>
<th>
@Html.DisplayNameFor(model => model.File[0].DateOfUpload)
</th>
<th>
@Html.DisplayNameFor(model => model.File[0].Note)
</th>
<th>
@Html.DisplayNameFor(model => model.File[0].Company)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.File) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.FileType)
</td>
<td>
@Html.DisplayFor(modelItem => item.IdReferenceFk)
</td>
<td>
@Html.DisplayFor(modelItem => item.Guid)
</td>
<td>
@Html.DisplayFor(modelItem => item.Extension)
</td>
<td>
@Html.DisplayFor(modelItem => item.Salt)
</td>
<td>
@Html.DisplayFor(modelItem => item.Iv)
</td>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateOfUpload)
</td>
<td>
@Html.DisplayFor(modelItem => item.Note)
</td>
<td>
@Html.DisplayFor(modelItem => item.Company.Ceo)
</td>
<td>
<a asp-page="./Edit" asp-route-id="@item.IdFile">Edit</a> |
<a asp-page="./Details" asp-route-id="@item.IdFile">Details</a> |
<a asp-page="./Delete" asp-route-id="@item.IdFile">Delete</a>
</td>
</tr>
}
</tbody>
</table>

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using EveryThing.Data;
using EveryThing.Models;
namespace EveryThing.Pages.Files
{
public class IndexModel : PageModel
{
private readonly ApplicationDbContext _context;
public IndexModel(ApplicationDbContext context)
{
_context = context;
}
public new IList<File> File { get;set; }
public async Task OnGetAsync()
{
File = await _context.Files.Include(f => f.Company).ToListAsync();
}
}
}

View File

@@ -0,0 +1,51 @@
@page
@using EveryThing.Models.Project
@model EveryThing.Pages.Files.UploadModel
@{
ViewData["Title"] = "Prilaganje datotek";
Layout = "~/Pages/Layouts/_Layout.cshtml";
}
<form method="post" enctype="multipart/form-data">
<h4 class="d-flex justify-content-between align-items-center w-100 font-weight-bold py-1 mb-4">
<span>
<span class="text-muted font-weight-light">Datoteke /</span> Prilaganje
</span>
</h4>
<div class="row">
<div class="col-6">
<div class="card">
<h6 class="card-header">
Podatki pozicije
</h6>
<div class="card-body">
<input type="hidden" asp-for="IdReferenceFk" name="idReferenceFk" />
<input type="hidden" asp-for="FileTypeInt" name="fileTypeInt" />
<input type="hidden" asp-for="Referer" name="referer" />
<div class="row">
<div class="col-12">
<div class="form-group">
<input type="file" name="postedFiles" multiple/>
</div>
</div>
</div>
</div>
<div class="card-footer py-3 text-right">
<input type="submit" class="btn btn-primary" value="Naloži" asp-page-handler="Upload" />
<a href="@Model.Referer" class="btn btn-default">Prekliči</a>
</div>
</div>
</div>
</div>
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
</form>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}

View File

@@ -0,0 +1,214 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using EveryThing.Data;
using EveryThing.Models;
using EveryThing.Models.Project;
using Microsoft.AspNetCore.Http;
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using DocumentFormat.OpenXml.Spreadsheet;
using Microsoft.VisualBasic.FileIO;
using EveryThing.Models.CodeTable;
using Microsoft.EntityFrameworkCore;
namespace EveryThing.Pages.Files
{
[Authorize(Roles = "Administrator,ProjecThingUser")]
public class UploadModel : PageModel
{
private readonly IWebHostEnvironment _hostingEnvironment;
private readonly ApplicationDbContext _context;
private readonly UserManager<IdentityApplicationUser> _userManager;
private readonly SignInManager<IdentityApplicationUser> _loginManager;
private readonly RoleManager<IdentityApplicationRole> _roleManager;
public UploadModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager, SignInManager<IdentityApplicationUser> loginManager, RoleManager<IdentityApplicationRole> roleManager, IWebHostEnvironment environment)
{
_context = context;
_userManager = userManager;
_loginManager = loginManager;
_roleManager = roleManager;
_hostingEnvironment = environment;
}
[BindProperty]
public IFormFile File { get; set; }
[BindProperty]
public int IdReferenceFk { get; set; }
[BindProperty]
public int FileTypeInt { get; set; }
public string Referer { get; set; }
public IActionResult OnGet(int idReferenceFk, FileType fileType)
{
if (idReferenceFk <= 0 || (int)fileType < 0)
return NotFound();
IdReferenceFk = idReferenceFk;
FileTypeInt = (int)fileType;
Referer = Request.Headers["Referer"].ToString();
return Page();
}
public async Task<IActionResult> OnPostUpload(int idReferenceFk, int fileTypeInt, List<IFormFile> postedFiles, string referer)
{
if (postedFiles is not { Count: > 0 })
{
return NotFound();
}
var user = _userManager.GetUserAsync(User).Result;
var fileType = (FileType)fileTypeInt;
var path = GetFolder(user.IdCompanyFk, fileType);// Path.Combine(_hostingEnvironment.WebRootPath, "Uploads", "Files", user.IdCompanyFk.ToString(), fileTypeInt.ToString());
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
foreach (var formFile in postedFiles)
{
var guid = Guid.NewGuid().ToString().Replace("-", "_");
var extension = Path.GetExtension(formFile.FileName);
var fileName = guid + extension;
await using var stream = new FileStream(Path.Combine(path, fileName), FileMode.Create);
await formFile.CopyToAsync(stream);
var newFile = new Models.File
{
IdCompanyFk = user.IdCompanyFk,
IdReferenceFk = idReferenceFk,
Title = formFile.FileName,
Extension = extension,
Guid = guid,
Salt = "",
Iv = "",
DateOfUpload = DateTime.Now,
FileType = fileType
};
_context.Files.Add(newFile);
await _context.SaveChangesAsync();
}
if (!string.IsNullOrEmpty(referer))
{
return Redirect(referer);
}
switch (fileType)
{
case FileType.ProjectPart:
return RedirectToPage("/Projects/Edit", new { id = _context.ProjectParts.FirstOrDefault(x => x.IdProjectPart == idReferenceFk)!.IdProjectFk});
case FileType.Project:
return RedirectToPage("/Projects/Edit", new { id = idReferenceFk });
case FileType.CodeTableItem:
return RedirectToPage("/CodeTableItems/Index");
default:
return RedirectToPage("/Index");
}
}
private string GetFolder(int idCompany, FileType fileType)
{
//return Path.Combine(_hostingEnvironment.WebRootPath, "Uploads", "Files", idCompany.ToString(), ((int)fileType).ToString());
return Path.Combine(_hostingEnvironment.WebRootPath, "Uploads", "Files", ((int)fileType).ToString());
}
public FileResult OnGetDownloadFile(int idFile, int idReferenceFk, int fileTypeInt)
{
var user = _userManager.GetUserAsync(User).Result;
var fileType = (FileType)fileTypeInt;
var file = _context.Files
.FirstOrDefault(x => x.IdCompanyFk == user.IdCompanyFk
&& x.IdReferenceFk == idReferenceFk
&& x.IdFile == idFile);
if (file == null)
return null;
var path = Path.Combine(GetFolder(user.IdCompanyFk, fileType), file.Guid + file.Extension);
var bytes = System.IO.File.ReadAllBytes(path);
return File(bytes, "application/octet-stream", file.Title);
}
public IActionResult OnDeleteFile(int idFile)
{
var user = _userManager.GetUserAsync(User).Result;
var file = _context.Files
.Where(x => x.IdCompanyFk == user.IdCompanyFk)
.FirstOrDefault(x => x.IdFile == idFile);
if (file == null)
{
return new JsonResult(new { idFile, error = $"File with id {idFile} not exists!", successful = false });
}
var path = Path.Combine(GetFolder(user.IdCompanyFk, file.FileType), file.Guid + file.Extension);
if (System.IO.File.Exists(path))
{
System.IO.File.Delete(path);
}
//else
//{
// return new JsonResult(new { idFile, error = "File path not exists!", successful = false });
//}
if (System.IO.File.Exists(path))
{
return new JsonResult(new { idFile, error = "File was not deleted from disk!", successful = false });
}
_context.Files.Remove(file);
_context.SaveChanges();
return new JsonResult(new { idFile, error = "", successful = true});
}
public IActionResult OnGetFile(int idFile)
{
var user = _userManager.GetUserAsync(User).Result;
var successful = true;
var error = "";
var inUse = false;
var file = _context.Files
.Where(x => x.IdCompanyFk == user.IdCompanyFk)
.FirstOrDefault(x => x.IdFile == idFile);
if (file == null)
{
successful = false;
error = $"File with ID: {idFile} not found";
}
else
{
//TODO prever in use
inUse = false;
}
return new JsonResult(new { file, error, successful, inUse });
}
}
}