Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
9efff4d2d0 |
@ -2,8 +2,8 @@
|
|||||||
{
|
{
|
||||||
public class AuthenticationSettings
|
public class AuthenticationSettings
|
||||||
{
|
{
|
||||||
public string JwtSecKey { get; set; }
|
public string JwtSecKey { get; set; }
|
||||||
public int JwtExpireDays { get; set; }
|
public int JwtExpireDays { get; set; }
|
||||||
public string JwtIssuer { get; set; }
|
public string JwtIssuer { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,4 @@
|
|||||||
/*
|
using System;
|
||||||
* This file is part of FirmTracker - Server.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -37,13 +20,11 @@ namespace FirmTracker_Server.Controllers
|
|||||||
{
|
{
|
||||||
private readonly IExpenseRepository _expenseRepository;
|
private readonly IExpenseRepository _expenseRepository;
|
||||||
private readonly ITransactionRepository _transactionRepository;
|
private readonly ITransactionRepository _transactionRepository;
|
||||||
private readonly IProductRepository _productRepository;
|
|
||||||
|
|
||||||
public PdfController(IExpenseRepository expenseRepository, ITransactionRepository transactionRepository, IProductRepository productRepository)
|
public PdfController(IExpenseRepository expenseRepository, ITransactionRepository transactionRepository)
|
||||||
{
|
{
|
||||||
_expenseRepository = expenseRepository;
|
_expenseRepository = expenseRepository;
|
||||||
_transactionRepository = transactionRepository;
|
_transactionRepository = transactionRepository;
|
||||||
_productRepository = productRepository;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("download")]
|
[HttpGet("download")]
|
||||||
@ -131,9 +112,8 @@ namespace FirmTracker_Server.Controllers
|
|||||||
// Main header
|
// Main header
|
||||||
page.Header()
|
page.Header()
|
||||||
.Text("Raport transakcji")
|
.Text("Raport transakcji")
|
||||||
.FontSize(22)
|
.FontSize(20)
|
||||||
.SemiBold()
|
.SemiBold()
|
||||||
.FontColor(Colors.Blue.Medium)
|
|
||||||
.AlignCenter();
|
.AlignCenter();
|
||||||
|
|
||||||
// Summary section
|
// Summary section
|
||||||
@ -142,18 +122,16 @@ namespace FirmTracker_Server.Controllers
|
|||||||
column.Spacing(10);
|
column.Spacing(10);
|
||||||
|
|
||||||
column.Item().Text($"Transakcje od ({startDate:yyyy-MM-dd} do {endDate:yyyy-MM-dd})")
|
column.Item().Text($"Transakcje od ({startDate:yyyy-MM-dd} do {endDate:yyyy-MM-dd})")
|
||||||
.FontSize(16)
|
.FontSize(16).Underline();
|
||||||
.Underline()
|
|
||||||
.FontColor(Colors.Grey.Medium);
|
|
||||||
|
|
||||||
// Add table header
|
// Add table header
|
||||||
column.Item().Row(row =>
|
column.Item().Row(row =>
|
||||||
{
|
{
|
||||||
row.RelativeItem().Text("Data").SemiBold().FontColor(Colors.Blue.Darken1);
|
row.RelativeItem().Text("Data").SemiBold();
|
||||||
row.RelativeItem().Text("Typ płatności").SemiBold().FontColor(Colors.Blue.Darken1);
|
row.RelativeItem().Text("Typ płatności").SemiBold();
|
||||||
row.RelativeItem().Text("Kwota razem").SemiBold().FontColor(Colors.Blue.Darken1);
|
row.RelativeItem().Text("Kwota razem").SemiBold();
|
||||||
row.RelativeItem().Text("Rabat").SemiBold().FontColor(Colors.Blue.Darken1);
|
row.RelativeItem().Text("Rabat").SemiBold();
|
||||||
row.RelativeItem().Text("Opis").SemiBold().FontColor(Colors.Blue.Darken1);
|
row.RelativeItem().Text("Opis").SemiBold();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Populate table rows with transaction data
|
// Populate table rows with transaction data
|
||||||
@ -175,15 +153,13 @@ namespace FirmTracker_Server.Controllers
|
|||||||
|
|
||||||
if (products.Any())
|
if (products.Any())
|
||||||
{
|
{
|
||||||
column.Item().Text("Produkty:").SemiBold().FontColor(Colors.Blue.Medium);
|
column.Item().Text("Produkty:").SemiBold();
|
||||||
foreach (var product in products)
|
foreach (var product in products)
|
||||||
{
|
{
|
||||||
var productQuery = _productRepository.GetProduct(product.Id);
|
|
||||||
column.Item().Row(productRow =>
|
column.Item().Row(productRow =>
|
||||||
{
|
{
|
||||||
productRow.RelativeItem().Text($"Nazwa produktu: {productQuery.Name}");
|
productRow.RelativeItem().Text($"Nazwa produktu: {product.ProductName}");
|
||||||
productRow.RelativeItem().Text($"Ilość: {product.Quantity}");
|
productRow.RelativeItem().Text($"Ilość: {product.Quantity}");
|
||||||
productRow.RelativeItem().Text($"Cena 1 szt. bez rabatu: {productQuery.Price.ToString("F2")}");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,8 +171,8 @@ namespace FirmTracker_Server.Controllers
|
|||||||
.AlignCenter()
|
.AlignCenter()
|
||||||
.Text(text =>
|
.Text(text =>
|
||||||
{
|
{
|
||||||
text.Span("Wygenerowano przez automat FT: ").FontColor(Colors.Grey.Medium);
|
text.Span("Wygenerowano przez automat FT: ");
|
||||||
text.Span(DateTime.Now.ToString("yyyy-MM-dd")).SemiBold().FontColor(Colors.Grey.Medium);
|
text.Span(DateTime.Now.ToString("yyyy-MM-dd")).SemiBold();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}).GeneratePdf(ms);
|
}).GeneratePdf(ms);
|
||||||
@ -224,9 +200,8 @@ namespace FirmTracker_Server.Controllers
|
|||||||
// Main header
|
// Main header
|
||||||
page.Header()
|
page.Header()
|
||||||
.Text("Raport wydatków")
|
.Text("Raport wydatków")
|
||||||
.FontSize(22)
|
.FontSize(20)
|
||||||
.SemiBold()
|
.SemiBold()
|
||||||
.FontColor(Colors.Green.Medium)
|
|
||||||
.AlignCenter();
|
.AlignCenter();
|
||||||
|
|
||||||
// Summary section
|
// Summary section
|
||||||
@ -236,20 +211,18 @@ namespace FirmTracker_Server.Controllers
|
|||||||
|
|
||||||
column.Item().Row(row =>
|
column.Item().Row(row =>
|
||||||
{
|
{
|
||||||
row.RelativeItem().Text($"Łączne wydatki: {totalExpenses:C}").FontSize(14).Bold().FontColor(Colors.Green.Darken1);
|
row.RelativeItem().Text($"Łączne wydatki: {totalExpenses:C}").FontSize(14).Bold();
|
||||||
row.RelativeItem().Text($"Średnie wydatki dzienne: {averageExpense:C}").FontSize(14).Bold().FontColor(Colors.Green.Darken1);
|
row.RelativeItem().Text($"Średnie wydatki dzienne: {averageExpense:C}").FontSize(14).Bold();
|
||||||
});
|
});
|
||||||
|
|
||||||
column.Item().Text($"Szczegóły wydatków od ({startDate:yyyy-MM-dd} do {endDate:yyyy-MM-dd})")
|
column.Item().Text($"Szczegóły wydatków od ({startDate:yyyy-MM-dd} do {endDate:yyyy-MM-dd})")
|
||||||
.FontSize(16)
|
.FontSize(16).Underline();
|
||||||
.Underline()
|
|
||||||
.FontColor(Colors.Grey.Medium);
|
|
||||||
|
|
||||||
column.Item().Row(row =>
|
column.Item().Row(row =>
|
||||||
{
|
{
|
||||||
row.RelativeItem().Text("Data").SemiBold().FontColor(Colors.Green.Darken1);
|
row.RelativeItem().Text("Data").SemiBold();
|
||||||
row.RelativeItem().Text("Kwota").SemiBold().FontColor(Colors.Green.Darken1);
|
row.RelativeItem().Text("Kwota").SemiBold();
|
||||||
row.RelativeItem().Text("Opis").SemiBold().FontColor(Colors.Green.Darken1);
|
row.RelativeItem().Text("Opis").SemiBold();
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach (var expense in expenses)
|
foreach (var expense in expenses)
|
||||||
@ -263,13 +236,12 @@ namespace FirmTracker_Server.Controllers
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Footer with generation date
|
|
||||||
page.Footer()
|
page.Footer()
|
||||||
.AlignCenter()
|
.AlignCenter()
|
||||||
.Text(text =>
|
.Text(text =>
|
||||||
{
|
{
|
||||||
text.Span("Wygenerowano przez automat FT: ").FontColor(Colors.Grey.Medium);
|
text.Span("Wygenerowano przez automat FT: ");
|
||||||
text.Span(DateTime.Now.ToString("yyyy-MM-dd")).SemiBold().FontColor(Colors.Grey.Medium);
|
text.Span(DateTime.Now.ToString("yyyy-MM-dd")).SemiBold();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}).GeneratePdf(ms);
|
}).GeneratePdf(ms);
|
||||||
@ -277,7 +249,5 @@ namespace FirmTracker_Server.Controllers
|
|||||||
return ms.ToArray();
|
return ms.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ namespace FirmTracker_Server.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
[ProducesResponseType(200)] // Created
|
[ProducesResponseType(200)] // Created
|
||||||
[ProducesResponseType(400)] // Bad Request
|
[ProducesResponseType(400)] // Bad Request
|
||||||
[Authorize(Roles = Roles.Admin + "," + Roles.User)]
|
[Authorize(Roles = Roles.Admin)]
|
||||||
public IActionResult CreateProduct([FromBody] Product product)
|
public IActionResult CreateProduct([FromBody] Product product)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -63,11 +63,6 @@ namespace FirmTracker_Server.Controllers
|
|||||||
{
|
{
|
||||||
throw new InvalidOperationException("Produkt nie może posiadać ujemnej ceny.");
|
throw new InvalidOperationException("Produkt nie może posiadać ujemnej ceny.");
|
||||||
}
|
}
|
||||||
var productByName = _productCrud.GetProductByName(product.Name);
|
|
||||||
if (productByName != null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Produkt o podanej nazwie już istnieje.");
|
|
||||||
}
|
|
||||||
|
|
||||||
_productCrud.AddProduct(product);
|
_productCrud.AddProduct(product);
|
||||||
return CreatedAtAction("GetProduct", new { id = product.Id }, product);
|
return CreatedAtAction("GetProduct", new { id = product.Id }, product);
|
||||||
@ -153,7 +148,7 @@ namespace FirmTracker_Server.Controllers
|
|||||||
[HttpDelete("{id}")]
|
[HttpDelete("{id}")]
|
||||||
[ProducesResponseType(200)] // Created
|
[ProducesResponseType(200)] // Created
|
||||||
[ProducesResponseType(400)] // Bad Request
|
[ProducesResponseType(400)] // Bad Request
|
||||||
[Authorize(Roles = Roles.Admin + "," + Roles.User)]
|
[Authorize(Roles = Roles.Admin)]
|
||||||
public IActionResult DeleteProduct(int id)
|
public IActionResult DeleteProduct(int id)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -1,20 +1,4 @@
|
|||||||
/*
|
using FirmTracker_Server.Models;
|
||||||
* This file is part of FirmTracker - Server.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
using FirmTracker_Server.Models;
|
|
||||||
using FirmTracker_Server.Services;
|
using FirmTracker_Server.Services;
|
||||||
using FirmTracker_Server;
|
using FirmTracker_Server;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
@ -22,9 +6,6 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using FirmTracker_Server.Entities;
|
using FirmTracker_Server.Entities;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace FirmTracker_Server.Controllers
|
namespace FirmTracker_Server.Controllers
|
||||||
{
|
{
|
||||||
[Route("api/user")]
|
[Route("api/user")]
|
||||||
@ -81,51 +62,6 @@ namespace FirmTracker_Server.Controllers
|
|||||||
|
|
||||||
return Ok(emails);
|
return Ok(emails);
|
||||||
}
|
}
|
||||||
[HttpPost("ChangeUserPassword")]
|
|
||||||
[Authorize(Roles = Roles.Admin)]
|
|
||||||
public ActionResult ChangeUserPassword([FromBody] ChangeUserPasswordDto dto)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var result = UserService.ChangeUserPassword(dto);
|
|
||||||
if (result)
|
|
||||||
{
|
|
||||||
return Ok("Password changed successfully.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return BadRequest("Failed to change the password.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return BadRequest($"An error occurred: {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[HttpPost("changePassword")]
|
|
||||||
[Authorize(Roles = Roles.Admin + "," + Roles.User)]
|
|
||||||
public ActionResult ChangePassword([FromBody] UpdatePasswordDto dto)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var result = UserService.UpdatePassword(dto);
|
|
||||||
if (result)
|
|
||||||
{
|
|
||||||
var loginDto = new LoginDto { Email = dto.email, Password = dto.newPassword };
|
|
||||||
var token = UserService.CreateTokenJwt(loginDto);
|
|
||||||
return Ok(new { Token = token });
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return BadRequest("Failed to change the password.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return BadRequest($"An error occurred: {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// New method to get all users
|
// New method to get all users
|
||||||
/* [HttpGet("all")]
|
/* [HttpGet("all")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
|
@ -34,7 +34,7 @@ namespace FirmTracker_Server.Controllers
|
|||||||
|
|
||||||
public WorkdayController()
|
public WorkdayController()
|
||||||
{
|
{
|
||||||
_workdayCRUD = new WorkdayRepository();
|
_workdayCRUD = new WorkdayRepository();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Endpoint to start a workday
|
// Endpoint to start a workday
|
||||||
@ -76,6 +76,8 @@ namespace FirmTracker_Server.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[HttpGet("user/workdays")]
|
[HttpGet("user/workdays")]
|
||||||
[Authorize(Roles = Roles.Admin + "," + Roles.User)]
|
[Authorize(Roles = Roles.Admin + "," + Roles.User)]
|
||||||
public IActionResult GetWorkdaysLoggedUser()
|
public IActionResult GetWorkdaysLoggedUser()
|
||||||
@ -93,7 +95,6 @@ namespace FirmTracker_Server.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Endpoint to get all workdays for a user
|
|
||||||
[HttpGet("user/{userMail}/workdays")]
|
[HttpGet("user/{userMail}/workdays")]
|
||||||
[Authorize(Roles = Roles.Admin + "," + Roles.User)]
|
[Authorize(Roles = Roles.Admin + "," + Roles.User)]
|
||||||
public IActionResult GetWorkdays(string userMail)
|
public IActionResult GetWorkdays(string userMail)
|
||||||
@ -108,9 +109,41 @@ namespace FirmTracker_Server.Controllers
|
|||||||
return BadRequest(new { message = "An error occurred while fetching workdays.", error = ex.Message });
|
return BadRequest(new { message = "An error occurred while fetching workdays.", error = ex.Message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("absences")]
|
||||||
|
[Authorize(Roles = Roles.Admin)]
|
||||||
|
public IActionResult GetAbsences()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var absences = _workdayCRUD.GetAbsences();
|
||||||
|
return Ok(absences);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return BadRequest(new { message = "An error occurred while fetching absences.", error = ex.Message });
|
||||||
|
}
|
||||||
|
}
|
||||||
[HttpPost("absence/add")]
|
[HttpPost("absence/add")]
|
||||||
[Authorize(Roles = Roles.Admin + "," + Roles.User)]
|
[Authorize(Roles = Roles.Admin)]
|
||||||
public IActionResult AddAbsence([FromBody] AddAbsenceDto dto)
|
public IActionResult AddAbsence([FromBody] string Absence)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
_workdayCRUD.AddAbsence(Absence);
|
||||||
|
|
||||||
|
return Ok(new { status = "added", Absence});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return BadRequest(new { message = "An error occurred while adding the absence.", error = ex.Message });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("user/absence/add")]
|
||||||
|
[Authorize(Roles = Roles.Admin)]
|
||||||
|
public IActionResult AddUserAbsence([FromBody] AddAbsenceDto dto)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -119,6 +152,7 @@ namespace FirmTracker_Server.Controllers
|
|||||||
return BadRequest(new { message = "User email must be provided." });
|
return BadRequest(new { message = "User email must be provided." });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fetch the userId based on the provided email
|
||||||
int userId;
|
int userId;
|
||||||
using (var session = SessionFactory.OpenSession())
|
using (var session = SessionFactory.OpenSession())
|
||||||
{
|
{
|
||||||
@ -130,45 +164,17 @@ namespace FirmTracker_Server.Controllers
|
|||||||
userId = user.UserId;
|
userId = user.UserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
_workdayCRUD.AddAbsence(userId, dto.AbsenceType, dto.StartTime, dto.EndTime);
|
// Add the absence for the retrieved userId
|
||||||
|
_workdayCRUD.AddAbsenceToUser(userId, dto.AbsenceType, dto.StartTime, dto.EndTime);
|
||||||
|
|
||||||
return Ok(new { status = "added", userId, dto.userEmail, absenceType = dto.AbsenceType });
|
return Ok(new { status = "added", userId, dto.userEmail, absenceType = dto.AbsenceType });
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return BadRequest(new { message = "An error occurred while adding the absence.", error = ex.Message });
|
return BadRequest(new { message = "An error occurred while adding the absence to user.", error = ex.Message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("user/{userMail}/day/info/{date}")]
|
|
||||||
[Authorize(Roles = Roles.Admin + "," + Roles.User)]
|
|
||||||
public IActionResult GetUserDayDetailsByMail(string userMail, DateTime date)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var dayDetails = _workdayCRUD.GetDayDetails(userMail, date);
|
|
||||||
return Ok(dayDetails);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return BadRequest(new { message = "An error occurred while fetching the day's details.", error = ex.Message });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[HttpGet("user/day/info/{date}")]
|
|
||||||
[Authorize(Roles = Roles.Admin + "," + Roles.User)]
|
|
||||||
public IActionResult GetUserDayDetails(DateTime date)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
|
|
||||||
|
|
||||||
var dayDetails = _workdayCRUD.GetDayDetailsForLoggedUser(int.Parse(userId), date);
|
|
||||||
return Ok(dayDetails);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return BadRequest(new { message = "An error occurred while fetching the day's details.", error = ex.Message });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ COPY . .
|
|||||||
|
|
||||||
|
|
||||||
# Copy the szyfrowanie.dll into the build directory (to ensure it's available during the build)
|
# Copy the szyfrowanie.dll into the build directory (to ensure it's available during the build)
|
||||||
#COPY ["szyfrowanie.dll", "./"]
|
COPY ["szyfrowanie.dll", "./"]
|
||||||
|
|
||||||
# Build the app
|
# Build the app
|
||||||
RUN dotnet build "FirmTracker-Server.csproj" -c Release -o /app/build
|
RUN dotnet build "FirmTracker-Server.csproj" -c Release -o /app/build
|
||||||
@ -31,7 +31,7 @@ EXPOSE 443
|
|||||||
COPY --from=publish /app/publish .
|
COPY --from=publish /app/publish .
|
||||||
|
|
||||||
# Copy the szyfrowanie.dll to the final image (if needed at runtime)
|
# Copy the szyfrowanie.dll to the final image (if needed at runtime)
|
||||||
#COPY ["szyfrowanie.dll", "./"]
|
COPY ["szyfrowanie.dll", "./"]
|
||||||
|
|
||||||
# Set the entry point for the container
|
# Set the entry point for the container
|
||||||
ENTRYPOINT ["dotnet", "FirmTracker-Server.dll"]
|
ENTRYPOINT ["dotnet", "FirmTracker-Server.dll"]
|
||||||
|
@ -35,6 +35,12 @@
|
|||||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.1.2" />
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.1.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="szyfrowanie">
|
||||||
|
<HintPath>./szyfrowanie.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Update="Properties\Resources.Designer.cs">
|
<Compile Update="Properties\Resources.Designer.cs">
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
|
31
JenkinsFile
31
JenkinsFile
@ -1,27 +1,24 @@
|
|||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
environment {
|
|
||||||
IMG_NAME = 'firmtracker-server'
|
|
||||||
DOCKER_REPO = 'maciejm0101/firmtracker'
|
|
||||||
}
|
|
||||||
stages {
|
stages {
|
||||||
stage('build') {
|
stage('Restore Dependencies') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
echo 'Restoring dependencies...'
|
||||||
sh 'docker build -t ${IMG_NAME} .'
|
sh 'dotnet restore'
|
||||||
sh 'docker tag ${IMG_NAME} ${DOCKER_REPO}:${IMG_NAME}'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('push') {
|
stage('Build') {
|
||||||
steps {
|
steps {
|
||||||
withCredentials([usernamePassword(credentialsId: 'DockerHub-LG', passwordVariable: 'PSWD', usernameVariable: 'LOGIN')]) {
|
echo 'Building the project...'
|
||||||
script {
|
sh 'dotnet build --configuration Release'
|
||||||
sh 'echo ${PSWD} | docker login -u ${LOGIN} --password-stdin'
|
}
|
||||||
sh 'docker push ${DOCKER_REPO}:${IMG_NAME}'
|
}
|
||||||
}
|
|
||||||
}
|
stage('Publish') {
|
||||||
|
steps {
|
||||||
|
echo 'Publishing the project...'
|
||||||
|
sh 'dotnet publish --configuration Release --output ./publish'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,9 @@
|
|||||||
/*
|
namespace FirmTracker_Server.Models
|
||||||
* This file is part of FirmTracker - Server.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
namespace FirmTracker_Server.Models
|
|
||||||
{
|
{
|
||||||
public class AddAbsenceDto
|
public class AddAbsenceDto
|
||||||
{
|
{
|
||||||
public string userEmail { get; set; }
|
public string userEmail { get; set; }
|
||||||
public string AbsenceType { get; set; }
|
public string AbsenceType { get; set; } // e.g., "Sick", "Vacation", etc.
|
||||||
public DateTime StartTime { get; set; }
|
public DateTime StartTime { get; set; }
|
||||||
public DateTime EndTime { get; set; }
|
public DateTime EndTime { get; set; }
|
||||||
|
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of FirmTracker - Server.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
namespace FirmTracker_Server.Models
|
|
||||||
{
|
|
||||||
public class ChangeUserPasswordDto
|
|
||||||
{
|
|
||||||
public string email { get; set; }
|
|
||||||
public string password { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +1,11 @@
|
|||||||
/*
|
namespace FirmTracker_Server.Models
|
||||||
* This file is part of FirmTracker - Server.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
namespace FirmTracker_Server.Models
|
|
||||||
{
|
{
|
||||||
public class CreateUserDto
|
public class CreateUserDto
|
||||||
{
|
{
|
||||||
public required string Login { get; set; }
|
public string Login { get; set; }
|
||||||
public required string Password { get; set; }
|
public string Password { get; set; }
|
||||||
public required string Email { get; set; }
|
public string Email { get; set; }
|
||||||
public required string Role { get; set; }
|
public string Role { get; set; }
|
||||||
public bool NewEncryption { get; set; } = true;
|
public bool NewEncryption { get; set; } = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of FirmTracker - Server.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
using FirmTracker_Server.nHibernate;
|
|
||||||
|
|
||||||
namespace FirmTracker_Server.Models
|
|
||||||
{
|
|
||||||
public class DayDetailsDto
|
|
||||||
{
|
|
||||||
public required string Email { get; set; }
|
|
||||||
public DateTime Date { get; set; }
|
|
||||||
public required string TotalWorkedHours { get; set; }
|
|
||||||
public required List<Workday> WorkdayDetails { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of FirmTracker - Server.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
using FirmTracker_Server.nHibernate;
|
|
||||||
|
|
||||||
namespace FirmTracker_Server.Models
|
|
||||||
{
|
|
||||||
public class DayDetailsLoggedUserDto
|
|
||||||
{
|
|
||||||
public int UserId { get; set; }
|
|
||||||
public DateTime Date { get; set; }
|
|
||||||
public string TotalWorkedHours { get; set; }
|
|
||||||
public List<Workday> WorkdayDetails { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +1,4 @@
|
|||||||
/*
|
using FirmTracker_Server.Controllers;
|
||||||
* This file is part of FirmTracker - Server.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
using FirmTracker_Server.Controllers;
|
|
||||||
|
|
||||||
namespace FirmTracker_Server.Models
|
namespace FirmTracker_Server.Models
|
||||||
{
|
{
|
||||||
|
@ -1,20 +1,4 @@
|
|||||||
/*
|
namespace FirmTracker_Server.Models
|
||||||
* This file is part of FirmTracker - Server.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
namespace FirmTracker_Server.Models
|
|
||||||
{
|
{
|
||||||
public class LoginDto
|
public class LoginDto
|
||||||
{
|
{
|
||||||
|
@ -1,20 +1,4 @@
|
|||||||
/*
|
namespace FirmTracker_Server.Models
|
||||||
* This file is part of FirmTracker - Server.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
namespace FirmTracker_Server.Models
|
|
||||||
{
|
{
|
||||||
public class UpdateAbsenceDto
|
public class UpdateAbsenceDto
|
||||||
{
|
{
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of FirmTracker - Server.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
namespace FirmTracker_Server.Models
|
|
||||||
{
|
|
||||||
public class UpdatePasswordDto
|
|
||||||
{
|
|
||||||
public string email { get; set; }
|
|
||||||
public string oldPassword { get; set; }
|
|
||||||
public string newPassword { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +1,4 @@
|
|||||||
/*
|
using System.ComponentModel.DataAnnotations;
|
||||||
* This file is part of FirmTracker - Server.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace FirmTracker_Server.Models
|
namespace FirmTracker_Server.Models
|
||||||
{
|
{
|
||||||
|
@ -1,20 +1,4 @@
|
|||||||
/*
|
using FirmTracker_Server.Entities;
|
||||||
* This file is part of FirmTracker - Server.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
using FirmTracker_Server.Entities;
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YourNamespace.Models
|
namespace YourNamespace.Models
|
||||||
|
24
Program.cs
24
Program.cs
@ -15,20 +15,29 @@
|
|||||||
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using NHibernate;
|
||||||
using NHibernate.Cfg;
|
using NHibernate.Cfg;
|
||||||
|
using NHibernate.Dialect;
|
||||||
|
using NHibernate.Driver;
|
||||||
|
using FirmTracker_Server.Controllers;
|
||||||
|
using FirmTracker_Server.nHibernate.Products;
|
||||||
using FirmTracker_Server.nHibernate;
|
using FirmTracker_Server.nHibernate;
|
||||||
using FirmTracker_Server.Utilities.Converters;
|
using FirmTracker_Server.Utilities.Converters;
|
||||||
using FirmTracker_Server.Utilities.Swagger;
|
using FirmTracker_Server.Utilities.Swagger;
|
||||||
|
using FluentValidation;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using FirmTracker_Server.Entities;
|
using FirmTracker_Server.Entities;
|
||||||
using FirmTracker_Server.Middleware;
|
using FirmTracker_Server.Middleware;
|
||||||
using FirmTracker_Server.Services;
|
using FirmTracker_Server.Services;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using FirmTracker_Server.Mappings;
|
using FirmTracker_Server.Mappings;
|
||||||
using Microsoft.AspNetCore.DataProtection;
|
using NuGet.Packaging;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -63,7 +72,7 @@ namespace FirmTracker_Server
|
|||||||
TestClass test = new TestClass();
|
TestClass test = new TestClass();
|
||||||
test.AddTestProduct();
|
test.AddTestProduct();
|
||||||
QuestPDF.Settings.License = QuestPDF.Infrastructure.LicenseType.Community;
|
QuestPDF.Settings.License = QuestPDF.Infrastructure.LicenseType.Community;
|
||||||
//builder.Services.AddDataProtection().DisableAutomaticKeyGeneration();
|
|
||||||
builder.Services.AddCors(options =>
|
builder.Services.AddCors(options =>
|
||||||
{
|
{
|
||||||
options.AddPolicy("AllowSpecificOrigin",
|
options.AddPolicy("AllowSpecificOrigin",
|
||||||
@ -97,9 +106,9 @@ namespace FirmTracker_Server
|
|||||||
|
|
||||||
|
|
||||||
var port = configSwagger.GetValue<int>("Port", 5075);
|
var port = configSwagger.GetValue<int>("Port", 5075);
|
||||||
// var port2 = configSwagger.GetValue<int>("Port", 7039);
|
var port2 = configSwagger.GetValue<int>("Port", 7039);
|
||||||
app.Urls.Add($"http://*:{port}");
|
app.Urls.Add($"http://*:{port}");
|
||||||
// app.Urls.Add($"https://*:{port2}");
|
app.Urls.Add($"https://*:{port2}");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -110,14 +119,14 @@ namespace FirmTracker_Server
|
|||||||
c.RoutePrefix = "swagger";
|
c.RoutePrefix = "swagger";
|
||||||
});
|
});
|
||||||
Console.WriteLine("uruchomiono swaggera");
|
Console.WriteLine("uruchomiono swaggera");
|
||||||
// app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch
|
||||||
{
|
{
|
||||||
Console.WriteLine("Nie uda³o siê uruchomiæ swaggera");
|
Console.WriteLine("Nie uda³o siê uruchomiæ swaggera");
|
||||||
}
|
}
|
||||||
|
|
||||||
// app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
app.UseCors("AllowSpecificOrigin");
|
app.UseCors("AllowSpecificOrigin");
|
||||||
|
|
||||||
@ -170,7 +179,6 @@ namespace FirmTracker_Server
|
|||||||
services.AddScoped<IPasswordHasher<User>, PasswordHasher<User>>();
|
services.AddScoped<IPasswordHasher<User>, PasswordHasher<User>>();
|
||||||
services.AddScoped<IExpenseRepository, ExpenseRepository>();
|
services.AddScoped<IExpenseRepository, ExpenseRepository>();
|
||||||
services.AddScoped<ITransactionRepository, TransactionRepository>();
|
services.AddScoped<ITransactionRepository, TransactionRepository>();
|
||||||
services.AddScoped<IProductRepository, ProductRepository>();
|
|
||||||
// services.AddScoped<IWorkdayRepository, WorkdayRepository>();
|
// services.AddScoped<IWorkdayRepository, WorkdayRepository>();
|
||||||
services.AddMvc();
|
services.AddMvc();
|
||||||
}
|
}
|
||||||
|
@ -9,11 +9,9 @@ using System.Globalization;
|
|||||||
using System.IdentityModel.Tokens.Jwt;
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using szyfrowanie;
|
||||||
using FirmTracker_Server.nHibernate;
|
using FirmTracker_Server.nHibernate;
|
||||||
using NHibernate;
|
|
||||||
using NHibernate.Criterion;
|
|
||||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
||||||
using NHibernate.Type;
|
|
||||||
|
|
||||||
namespace FirmTracker_Server.Services
|
namespace FirmTracker_Server.Services
|
||||||
{
|
{
|
||||||
@ -23,86 +21,26 @@ namespace FirmTracker_Server.Services
|
|||||||
int AddUser(CreateUserDto dto);
|
int AddUser(CreateUserDto dto);
|
||||||
string CreateTokenJwt(LoginDto dto);
|
string CreateTokenJwt(LoginDto dto);
|
||||||
IEnumerable<string> GetAllUserEmails();
|
IEnumerable<string> GetAllUserEmails();
|
||||||
bool UpdatePassword(UpdatePasswordDto dto);
|
|
||||||
bool ChangeUserPassword(ChangeUserPasswordDto dto);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UserService : IUserService
|
public class UserService : IUserService
|
||||||
{
|
{
|
||||||
// private readonly GeneralDbContext DbContext;
|
// private readonly GeneralDbContext DbContext;
|
||||||
private readonly IMapper Mapper;
|
private readonly IMapper Mapper;
|
||||||
private readonly IPasswordHasher<User> PasswordHasher;
|
private readonly IPasswordHasher<User> PasswordHasher;
|
||||||
private readonly AuthenticationSettings AuthenticationSettings;
|
private readonly AuthenticationSettings AuthenticationSettings;
|
||||||
// private readonly SimplerAES SimplerAES;
|
private readonly SimplerAES SimplerAES;
|
||||||
//private readonly SessionFactory sessionFactory;
|
//private readonly SessionFactory sessionFactory;
|
||||||
|
|
||||||
public UserService(IMapper mapper, IPasswordHasher<User> passwordHasher, AuthenticationSettings authenticationSettings)
|
public UserService( IMapper mapper, IPasswordHasher<User> passwordHasher, AuthenticationSettings authenticationSettings)
|
||||||
{
|
{
|
||||||
// DbContext = dbContext;
|
// DbContext = dbContext;
|
||||||
Mapper = mapper;
|
Mapper = mapper;
|
||||||
PasswordHasher = passwordHasher;
|
PasswordHasher = passwordHasher;
|
||||||
AuthenticationSettings = authenticationSettings;
|
AuthenticationSettings = authenticationSettings;
|
||||||
///SimplerAES = new SimplerAES();
|
SimplerAES = new SimplerAES();
|
||||||
//SessionFactory = sessionFactory;
|
//SessionFactory = sessionFactory;
|
||||||
}
|
}
|
||||||
public bool ChangeUserPassword(ChangeUserPasswordDto dto)
|
|
||||||
{
|
|
||||||
using (var session = SessionFactory.OpenSession())
|
|
||||||
using (var transaction = session.BeginTransaction())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var user = session.Query<User>().FirstOrDefault(u => u.Email == dto.email);
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
throw new Exception("User not found.");
|
|
||||||
}
|
|
||||||
|
|
||||||
user.PassHash = PasswordHasher.HashPassword(user, dto.password);
|
|
||||||
session.Update(user);
|
|
||||||
transaction.Commit();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
transaction.Rollback();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public bool UpdatePassword(UpdatePasswordDto dto)
|
|
||||||
{
|
|
||||||
using (var session = SessionFactory.OpenSession())
|
|
||||||
using (var transaction = session.BeginTransaction())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var user = session.Query<User>().FirstOrDefault(u => u.Email == dto.email);
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
throw new Exception("User not found.");
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = PasswordHasher.VerifyHashedPassword(user, user.PassHash, dto.oldPassword);
|
|
||||||
if (result != PasswordVerificationResult.Success)
|
|
||||||
{
|
|
||||||
throw new Exception("Invalid current password.");
|
|
||||||
}
|
|
||||||
|
|
||||||
user.PassHash = PasswordHasher.HashPassword(user, dto.newPassword);
|
|
||||||
session.Update(user);
|
|
||||||
transaction.Commit();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
transaction.Rollback();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public IEnumerable<string> GetAllUserEmails()
|
public IEnumerable<string> GetAllUserEmails()
|
||||||
{
|
{
|
||||||
using (var session = SessionFactory.OpenSession())
|
using (var session = SessionFactory.OpenSession())
|
||||||
@ -126,7 +64,7 @@ namespace FirmTracker_Server.Services
|
|||||||
var user = Mapper.Map<User>(dto);
|
var user = Mapper.Map<User>(dto);
|
||||||
|
|
||||||
// Encrypt or hash the password based on NewEncryption flag
|
// Encrypt or hash the password based on NewEncryption flag
|
||||||
user.PassHash = dto.NewEncryption ? PasswordHasher.HashPassword(user, dto.Password) : PasswordHasher.HashPassword(user, dto.Password);
|
user.PassHash = dto.NewEncryption ? SimplerAES.Encrypt(dto.Password) : PasswordHasher.HashPassword(user, dto.Password);
|
||||||
user.Role = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(dto.Role.ToLower());
|
user.Role = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(dto.Role.ToLower());
|
||||||
|
|
||||||
using (var session = SessionFactory.OpenSession())
|
using (var session = SessionFactory.OpenSession())
|
||||||
@ -171,9 +109,9 @@ namespace FirmTracker_Server.Services
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Console.WriteLine(PasswordHasher.HashPassword(user, user.PassHash));
|
Console.WriteLine(SimplerAES.Decrypt(user.PassHash)+" "+SimplerAES.Decrypt(dto.Password));
|
||||||
var ready = PasswordHasher.VerifyHashedPassword(user, user.PassHash, dto.Password);
|
var ready = SimplerAES.Decrypt(user.PassHash) == SimplerAES.Decrypt(dto.Password);
|
||||||
if (ready == 0)
|
if (!ready)
|
||||||
{
|
{
|
||||||
throw new WrongUserOrPasswordException("Nieprawidłowy login lub hasło.");
|
throw new WrongUserOrPasswordException("Nieprawidłowy login lub hasło.");
|
||||||
}
|
}
|
||||||
@ -186,7 +124,7 @@ namespace FirmTracker_Server.Services
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var ready = PasswordVerificationResult.Failed;
|
var ready = PasswordVerificationResult.Failed;
|
||||||
if (PasswordHasher.VerifyHashedPassword(user, user.PassHash, dto.Password) == PasswordVerificationResult.Success) { ready = PasswordVerificationResult.Success; } //PasswordHasher.VerifyHashedPassword(user, user.PassHash, dto.Password);
|
if (SimplerAES.Decrypt(user.PassHash) == SimplerAES.Decrypt(dto.Password)) { ready = PasswordVerificationResult.Success; } //PasswordHasher.VerifyHashedPassword(user, user.PassHash, dto.Password);
|
||||||
if (ready == PasswordVerificationResult.Failed)
|
if (ready == PasswordVerificationResult.Failed)
|
||||||
{
|
{
|
||||||
throw new WrongUserOrPasswordException("Nieprawidłowy login lub hasło.");
|
throw new WrongUserOrPasswordException("Nieprawidłowy login lub hasło.");
|
||||||
|
449
TestClass.cs
449
TestClass.cs
@ -60,22 +60,22 @@ namespace FirmTracker_Server
|
|||||||
|
|
||||||
var products = new List<Product>
|
var products = new List<Product>
|
||||||
{
|
{
|
||||||
CreateProduct("Tarta_truskawka", "produkt", 31.99m, 1, 20),
|
CreateProduct("Tarta_truskawka", "produkt", 31.99m, 1, 10),
|
||||||
CreateProduct("Tarta_czekolada", "produkt", 30.99m, 1, 20),
|
CreateProduct("Tarta_czekolada", "produkt", 30.99m, 1, 10),
|
||||||
CreateProduct("Tarta_agrest", "produkt", 32.90m, 1, 10),
|
CreateProduct("Tarta_agrest", "produkt", 32.90m, 1, 8),
|
||||||
CreateProduct("Tarta_pistacja", "produkt", 35.99m, 1, 15),
|
CreateProduct("Tarta_pistacja", "produkt", 35.99m, 1, 12),
|
||||||
CreateProduct("Tarta_karmel", "produkt", 32.00m, 1, 15),
|
CreateProduct("Tarta_karmel", "produkt", 32.00m, 1, 12),
|
||||||
CreateProduct("Rolada_beza", "produkt", 21.00m, 1, 12),
|
CreateProduct("Rolada_beza", "produkt", 21.00m, 1, 5),
|
||||||
CreateProduct("Rolada_róża", "produkt", 21.90m, 1, 10),
|
CreateProduct("Rolada_róża", "produkt", 21.90m, 1, 10),
|
||||||
CreateProduct("Kostka_truskawka", "produkt", 12.00m, 1, 15),
|
CreateProduct("Kostka_truskawka", "produkt", 12.00m, 1, 11),
|
||||||
CreateProduct("Kostka_lemonCurd", "produkt", 13.99m, 1, 15),
|
CreateProduct("Kostka_lemonCurd", "produkt", 13.99m, 1, 13),
|
||||||
CreateProduct("Kostka_hiszpańska", "produkt", 11.99m, 1, 10),
|
CreateProduct("Kostka_hiszpańska", "produkt", 11.99m, 1, 8),
|
||||||
CreateProduct("Kostka_wiosenna", "produkt", 11.99m, 1, 10),
|
CreateProduct("Kostka_wiosenna", "produkt", 11.99m, 1, 5),
|
||||||
CreateProduct("Kostka_jabłka", "produkt", 12.00m, 1, 15),
|
CreateProduct("Kostka_jabłka", "produkt", 12.00m, 1, 5),
|
||||||
CreateProduct("Kostka_porzeczka", "produkt", 12.99m, 1, 10),
|
CreateProduct("Kostka_porzeczka", "produkt", 12.99m, 1, 5),
|
||||||
CreateProduct("Kostka_królewska", "produkt", 13.50m, 1, 20),
|
CreateProduct("Kostka_królewska", "produkt", 13.50m, 1, 5),
|
||||||
CreateProduct("Kostka_czekolada", "produkt", 14.50m, 1, 12),
|
CreateProduct("Kostka_czekolada", "produkt", 14.50m, 1, 10),
|
||||||
CreateProduct("Kostka_wiśnia", "produkt", 12.50m, 1, 10),
|
CreateProduct("Kostka_wiśnia", "produkt", 12.50m, 1, 5),
|
||||||
CreateProduct("Kostka_beza", "produkt", 13.50m, 1, 20),
|
CreateProduct("Kostka_beza", "produkt", 13.50m, 1, 20),
|
||||||
CreateProduct("Kostka_leśna", "produkt", 12.00m, 1, 20),
|
CreateProduct("Kostka_leśna", "produkt", 12.00m, 1, 20),
|
||||||
CreateProduct("Kostka_kawowa", "produkt", 12.00m, 1, 10),
|
CreateProduct("Kostka_kawowa", "produkt", 12.00m, 1, 10),
|
||||||
@ -116,7 +116,38 @@ namespace FirmTracker_Server
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var transaction1 = new Transaction
|
||||||
|
{
|
||||||
|
Date = DateTime.Now.AddDays(-2),
|
||||||
|
Description = "zamówienie telefon",
|
||||||
|
Discount = 5,
|
||||||
|
EmployeeId = 1,
|
||||||
|
PaymentType = "Karta kredytowa",
|
||||||
|
};
|
||||||
|
var transaction2 = new Transaction
|
||||||
|
{
|
||||||
|
Date = DateTime.Now.AddDays(-3),
|
||||||
|
Description = "sprzedaż - kasa",
|
||||||
|
Discount = 30,
|
||||||
|
EmployeeId = 2,
|
||||||
|
PaymentType = "Gotówka",
|
||||||
|
};
|
||||||
|
var transaction3 = new Transaction
|
||||||
|
{
|
||||||
|
Date = DateTime.Now,
|
||||||
|
Description = "sprzedaż - kasa",
|
||||||
|
Discount = 15,
|
||||||
|
EmployeeId = 1,
|
||||||
|
PaymentType = "BLIK",
|
||||||
|
};
|
||||||
|
var transaction4 = new Transaction
|
||||||
|
{
|
||||||
|
Date = DateTime.Now,
|
||||||
|
Description = "zamówienie",
|
||||||
|
Discount = 15,
|
||||||
|
EmployeeId = 1,
|
||||||
|
PaymentType = "BLIK",
|
||||||
|
};
|
||||||
|
|
||||||
var expense1 = new Expense
|
var expense1 = new Expense
|
||||||
{
|
{
|
||||||
@ -138,6 +169,24 @@ namespace FirmTracker_Server
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var nieobecnosc1 = "Urlop / Urlop na żądanie" ;
|
||||||
|
var nieobecnosc2 = "Zwolnienie chorobowe";
|
||||||
|
var nieobecnosc3 = "Szkolenie";
|
||||||
|
var nieobecnosc4 = "Przerwa prywatna";
|
||||||
|
WorkdayRepository work = new WorkdayRepository();
|
||||||
|
work.AddAbsence(nieobecnosc1);
|
||||||
|
work.AddAbsence(nieobecnosc2);
|
||||||
|
work.AddAbsence(nieobecnosc3);
|
||||||
|
work.AddAbsence(nieobecnosc4);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(Exception a)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Nie udało się dodać typów nieobecności " + a.Message);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string appDirectory = Directory.GetCurrentDirectory();
|
string appDirectory = Directory.GetCurrentDirectory();
|
||||||
@ -155,14 +204,10 @@ namespace FirmTracker_Server
|
|||||||
|
|
||||||
//SessionFactory.Init(connectionString);
|
//SessionFactory.Init(connectionString);
|
||||||
|
|
||||||
string queryAdmin = "insert into Users(Email,PassHash,Role) select 'julia.c03@wp.pl', 'AQAAAAIAAYagAAAAEMQUuFPUNAddMmuZpCUAZpaDR31+BqMJhnamIAllDi+aTBJQ7tEtLuEMppgz0oLYyw==','Admin'";
|
string queryUser = "insert into Users(Email,PassHash,Role) select '123@wp.pl', 'GOsGemJarMJu8btZKF6Rung27JLZkdO7Wfd4CwLhL1k=','User'";
|
||||||
string queryUser = "insert into Users(Email,PassHash,Role) select 'sylwia1972@gmail.com', 'AQAAAAIAAYagAAAAEMQUuFPUNAddMmuZpCUAZpaDR31+BqMJhnamIAllDi+aTBJQ7tEtLuEMppgz0oLYyw==','User'";
|
string queryAdmin = "insert into Users(Email,PassHash,Role) select '321@wp.pl', 'GOsGemJarMJu8btZKF6Rung27JLZkdO7Wfd4CwLhL1k=','Admin'";
|
||||||
string queryUser2 = "insert into Users(Email,PassHash,Role) select '123@wp.pl', 'AQAAAAIAAYagAAAAEMQUuFPUNAddMmuZpCUAZpaDR31+BqMJhnamIAllDi+aTBJQ7tEtLuEMppgz0oLYyw==','User'";
|
|
||||||
string queryUser3 = "insert into Users(Email,PassHash,Role) select '321@wp.pl', 'AQAAAAIAAYagAAAAEMQUuFPUNAddMmuZpCUAZpaDR31+BqMJhnamIAllDi+aTBJQ7tEtLuEMppgz0oLYyw==','User'";
|
|
||||||
string queryUser4 = "insert into Users(Email,PassHash,Role) select 'magdalena.szwarc75@wp.pl', 'AQAAAAIAAYagAAAAEMQUuFPUNAddMmuZpCUAZpaDR31+BqMJhnamIAllDi+aTBJQ7tEtLuEMppgz0oLYyw==','User'";
|
|
||||||
string queryUser5 = "insert into Users(Email,PassHash,Role) select 'jac.ziel@gmail.com', 'AQAAAAIAAYagAAAAEMQUuFPUNAddMmuZpCUAZpaDR31+BqMJhnamIAllDi+aTBJQ7tEtLuEMppgz0oLYyw==','User'";
|
|
||||||
string queryUser6 = "insert into Users(Email,PassHash,Role) select 'renata.zielonka@wp.com', 'AQAAAAIAAYagAAAAEMQUuFPUNAddMmuZpCUAZpaDR31+BqMJhnamIAllDi+aTBJQ7tEtLuEMppgz0oLYyw==','User'";
|
|
||||||
|
|
||||||
|
|
||||||
SqlConnection connection = new SqlConnection(connectionString);
|
SqlConnection connection = new SqlConnection(connectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
@ -180,44 +225,6 @@ namespace FirmTracker_Server
|
|||||||
command2.ExecuteNonQuery();
|
command2.ExecuteNonQuery();
|
||||||
connection2.Close();
|
connection2.Close();
|
||||||
|
|
||||||
SqlConnection connection3 = new SqlConnection(connectionString);
|
|
||||||
connection.Open();
|
|
||||||
|
|
||||||
SqlCommand command3 = new SqlCommand(queryUser2, connection);
|
|
||||||
command2.CommandTimeout = 200;
|
|
||||||
command2.ExecuteNonQuery();
|
|
||||||
connection2.Close();
|
|
||||||
SqlConnection connection4 = new SqlConnection(connectionString);
|
|
||||||
connection.Open();
|
|
||||||
|
|
||||||
SqlCommand command4 = new SqlCommand(queryUser3, connection);
|
|
||||||
command2.CommandTimeout = 200;
|
|
||||||
command2.ExecuteNonQuery();
|
|
||||||
connection2.Close();
|
|
||||||
|
|
||||||
SqlConnection connection5 = new SqlConnection(connectionString);
|
|
||||||
connection.Open();
|
|
||||||
|
|
||||||
SqlCommand command5 = new SqlCommand(queryUser4, connection);
|
|
||||||
command2.CommandTimeout = 200;
|
|
||||||
command2.ExecuteNonQuery();
|
|
||||||
connection2.Close();
|
|
||||||
|
|
||||||
SqlConnection connection6 = new SqlConnection(connectionString);
|
|
||||||
connection.Open();
|
|
||||||
|
|
||||||
SqlCommand command6 = new SqlCommand(queryUser6, connection);
|
|
||||||
command2.CommandTimeout = 200;
|
|
||||||
command2.ExecuteNonQuery();
|
|
||||||
connection2.Close();
|
|
||||||
|
|
||||||
SqlConnection connection7 = new SqlConnection(connectionString);
|
|
||||||
connection.Open();
|
|
||||||
|
|
||||||
SqlCommand command7 = new SqlCommand(queryUser5, connection);
|
|
||||||
command2.CommandTimeout = 200;
|
|
||||||
command2.ExecuteNonQuery();
|
|
||||||
connection2.Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -241,307 +248,59 @@ namespace FirmTracker_Server
|
|||||||
{
|
{
|
||||||
productCrud.AddProduct(clientProduct);
|
productCrud.AddProduct(clientProduct);
|
||||||
}
|
}
|
||||||
/*transactionCrud.AddTransaction(transaction1);
|
transactionCrud.AddTransaction(transaction1);
|
||||||
transactionCrud.AddTransaction(transaction2);
|
transactionCrud.AddTransaction(transaction2);
|
||||||
transactionCrud.AddTransaction(transaction3);
|
transactionCrud.AddTransaction(transaction3);
|
||||||
transactionCrud.AddTransaction(transaction4);
|
transactionCrud.AddTransaction(transaction4);
|
||||||
transactionCrud.AddTransaction(transaction5);
|
|
||||||
transactionCrud.AddTransaction(transaction6);
|
|
||||||
transactionCrud.AddTransaction(transaction7);
|
|
||||||
transactionCrud.AddTransaction(transaction8);
|
|
||||||
transactionCrud.AddTransaction(transaction9);
|
|
||||||
transactionCrud.AddTransaction(transaction10);
|
|
||||||
transactionCrud.AddTransaction(transaction11);
|
|
||||||
transactionCrud.AddTransaction(transaction12);
|
|
||||||
transactionCrud.AddTransaction(transaction13);
|
|
||||||
transactionCrud.AddTransaction(transaction14);
|
|
||||||
transactionCrud.AddTransaction(transaction15);
|
|
||||||
transactionCrud.AddTransaction(transaction16);
|
|
||||||
transactionCrud.AddTransaction(transaction17);
|
|
||||||
transactionCrud.AddTransaction(transaction18);
|
|
||||||
transactionCrud.AddTransaction(transaction19);
|
|
||||||
transactionCrud.AddTransaction(transaction20);*/
|
|
||||||
expenseCrud.AddExpense(expense1);
|
expenseCrud.AddExpense(expense1);
|
||||||
expenseCrud.AddExpense(expense2);
|
expenseCrud.AddExpense(expense2);
|
||||||
expenseCrud.AddExpense(expense3);
|
expenseCrud.AddExpense(expense3);
|
||||||
|
|
||||||
var transactions = new List<Transaction>
|
List<TransactionProduct> testTransactionProducts = new List<TransactionProduct> {
|
||||||
{
|
new TransactionProduct { ProductID =17, Quantity = 3 },
|
||||||
new Transaction
|
new TransactionProduct { ProductID = 14, Quantity = 1 },
|
||||||
{
|
new TransactionProduct { ProductID = 1, Quantity = 1 },
|
||||||
Date = DateTime.Now.AddDays(-1),
|
};
|
||||||
Description = "zamówienie",
|
foreach (var transactionProduct in testTransactionProducts)
|
||||||
Discount = 5,
|
|
||||||
EmployeeId = 1,
|
|
||||||
PaymentType = "Gotówka"
|
|
||||||
},
|
|
||||||
new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(-2),
|
|
||||||
Description = "sprzedaż",
|
|
||||||
Discount = 10,
|
|
||||||
EmployeeId = 2,
|
|
||||||
PaymentType = "Karta kredytowa"
|
|
||||||
},
|
|
||||||
new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(-3),
|
|
||||||
Description = "sprzedaż",
|
|
||||||
Discount = 15,
|
|
||||||
EmployeeId = 3,
|
|
||||||
PaymentType = "BLIK"
|
|
||||||
},
|
|
||||||
new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now,
|
|
||||||
Description = "sprzedaż",
|
|
||||||
Discount = 20,
|
|
||||||
EmployeeId = 4,
|
|
||||||
PaymentType = "Gotówka"
|
|
||||||
},
|
|
||||||
new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(-5),
|
|
||||||
Description = "sprzedaż",
|
|
||||||
Discount = 8,
|
|
||||||
EmployeeId = 1,
|
|
||||||
PaymentType = "Gotówka"
|
|
||||||
},
|
|
||||||
new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(-6),
|
|
||||||
Description = "na telefon",
|
|
||||||
Discount = 12,
|
|
||||||
EmployeeId = 2,
|
|
||||||
PaymentType = "Karta kredytowa"
|
|
||||||
},
|
|
||||||
new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(-7),
|
|
||||||
Description = "sprzedaż",
|
|
||||||
Discount = 18,
|
|
||||||
EmployeeId = 3,
|
|
||||||
PaymentType = "BLIK"
|
|
||||||
},
|
|
||||||
new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(-8),
|
|
||||||
Description = "rezerwacja",
|
|
||||||
Discount = 25,
|
|
||||||
EmployeeId = 4,
|
|
||||||
PaymentType = "Gotówka"
|
|
||||||
},
|
|
||||||
new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(-10),
|
|
||||||
Description = "sprzedaż",
|
|
||||||
Discount = 9,
|
|
||||||
EmployeeId = 1,
|
|
||||||
PaymentType = "Gotówka"
|
|
||||||
},
|
|
||||||
new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(-11),
|
|
||||||
Description = "zamówienie telefoniczne",
|
|
||||||
Discount = 14,
|
|
||||||
EmployeeId = 2,
|
|
||||||
PaymentType = "Karta kredytowa"
|
|
||||||
},
|
|
||||||
new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(-12),
|
|
||||||
Description = "sprzedaż w punkcie",
|
|
||||||
Discount = 17,
|
|
||||||
EmployeeId = 3,
|
|
||||||
PaymentType = "BLIK"
|
|
||||||
},
|
|
||||||
new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(-13),
|
|
||||||
Description = "zamówienie",
|
|
||||||
Discount = 22,
|
|
||||||
EmployeeId = 4,
|
|
||||||
PaymentType = "Gotówka"
|
|
||||||
},
|
|
||||||
new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(-15),
|
|
||||||
Description = "sprzedaż",
|
|
||||||
Discount = 7,
|
|
||||||
EmployeeId = 1,
|
|
||||||
PaymentType = "Gotówka"
|
|
||||||
},
|
|
||||||
new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(-16),
|
|
||||||
Description = "zamówienie",
|
|
||||||
Discount = 13,
|
|
||||||
EmployeeId = 2,
|
|
||||||
PaymentType = "Karta kredytowa"
|
|
||||||
},
|
|
||||||
new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(-17),
|
|
||||||
Description = "sprzedaż",
|
|
||||||
Discount = 16,
|
|
||||||
EmployeeId = 3,
|
|
||||||
PaymentType = "BLIK"
|
|
||||||
},
|
|
||||||
new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(-18),
|
|
||||||
Description = "na telefon",
|
|
||||||
Discount = 21,
|
|
||||||
EmployeeId = 4,
|
|
||||||
PaymentType = "Gotówka"
|
|
||||||
},
|
|
||||||
new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(-20),
|
|
||||||
Description = "sprzedaż",
|
|
||||||
Discount = 10,
|
|
||||||
EmployeeId = 1,
|
|
||||||
PaymentType = "Gotówka"
|
|
||||||
},
|
|
||||||
new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(-21),
|
|
||||||
Description = "zamówienie telefoniczne",
|
|
||||||
Discount = 12,
|
|
||||||
EmployeeId = 2,
|
|
||||||
PaymentType = "Karta kredytowa"
|
|
||||||
},
|
|
||||||
new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(-22),
|
|
||||||
Description = "sprzedaż w punkcie",
|
|
||||||
Discount = 14,
|
|
||||||
EmployeeId = 3,
|
|
||||||
PaymentType = "BLIK"
|
|
||||||
},
|
|
||||||
new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(-23),
|
|
||||||
Description = "zamówienie online",
|
|
||||||
Discount = 18,
|
|
||||||
EmployeeId = 4,
|
|
||||||
PaymentType = "Gotówka"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var transactionProducts = new List<(int TransactionIndex, int ProductID, int Quantity)>
|
|
||||||
{
|
|
||||||
(0, 1, 1), // Transaction 1: Product 1 with quantity 1
|
|
||||||
(0, 2, 3), // Transaction 1: Product 2 with quantity 3
|
|
||||||
(1, 3, 4), // Transaction 2: Product 3 with quantity 4
|
|
||||||
(1, 4, 2), // Transaction 2: Product 4 with quantity 2
|
|
||||||
(2, 5, 3), // Transaction 3: Product 5 with quantity 3
|
|
||||||
(2, 6, 1), // Transaction 3: Product 6 with quantity 1
|
|
||||||
(3, 7, 5), // Transaction 4: Product 7 with quantity 5
|
|
||||||
(3, 8, 2), // Transaction 4: Product 8 with quantity 2
|
|
||||||
(4, 9, 3), // Transaction 5: Product 9 with quantity 3
|
|
||||||
(4, 10, 2), // Transaction 5: Product 10 with quantity 2
|
|
||||||
(5, 11, 4), // Transaction 6: Product 11 with quantity 4
|
|
||||||
(5, 12, 1), // Transaction 6: Product 12 with quantity 1
|
|
||||||
(6, 13, 3), // Transaction 7: Product 13 with quantity 3
|
|
||||||
(6, 14, 2), // Transaction 7: Product 14 with quantity 2
|
|
||||||
(7, 15, 5), // Transaction 8: Product 15 with quantity 5
|
|
||||||
(7, 16, 2), // Transaction 8: Product 16 with quantity 2
|
|
||||||
(8, 17, 3), // Transaction 9: Product 17 with quantity 3
|
|
||||||
(8, 18, 4), // Transaction 9: Product 18 with quantity 4
|
|
||||||
(9, 19, 2), // Transaction 10: Product 19 with quantity 2
|
|
||||||
(9, 20, 3), // Transaction 10: Product 20 with quantity 3
|
|
||||||
(10, 1, 1), // Transaction 11: Product 1 with quantity 1
|
|
||||||
(10, 2, 5), // Transaction 11: Product 2 with quantity 5
|
|
||||||
(11, 3, 2), // Transaction 12: Product 3 with quantity 2
|
|
||||||
(11, 4, 3), // Transaction 12: Product 4 with quantity 3
|
|
||||||
(12, 5, 1), // Transaction 13: Product 5 with quantity 1
|
|
||||||
(12, 6, 4), // Transaction 13: Product 6 with quantity 4
|
|
||||||
(13, 7, 2), // Transaction 14: Product 7 with quantity 2
|
|
||||||
(13, 8, 3), // Transaction 14: Product 8 with quantity 3
|
|
||||||
(14, 9, 3), // Transaction 15: Product 9 with quantity 3
|
|
||||||
(14, 10, 1), // Transaction 15: Product 10 with quantity 1
|
|
||||||
(15, 11, 2), // Transaction 16: Product 11 with quantity 2
|
|
||||||
(15, 12, 3), // Transaction 16: Product 12 with quantity 3
|
|
||||||
(16, 13, 3), // Transaction 17: Product 13 with quantity 3
|
|
||||||
(16, 14, 1), // Transaction 17: Product 14 with quantity 1
|
|
||||||
(17, 15, 4), // Transaction 18: Product 15 with quantity 4
|
|
||||||
(17, 16, 1), // Transaction 18: Product 16 with quantity 1
|
|
||||||
(18, 17, 2), // Transaction 19: Product 17 with quantity 2
|
|
||||||
(18, 18, 3), // Transaction 19: Product 18 with quantity 3
|
|
||||||
(19, 19, 1), // Transaction 20: Product 19 with quantity 1
|
|
||||||
(19, 20, 2), // Transaction 20: Product 20 with quantity 2
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Add transactions
|
|
||||||
foreach (var transaction in transactions)
|
|
||||||
{
|
{
|
||||||
transactionCrud.AddTransaction(transaction);
|
transactionCrud.AddTransactionProductToTransaction(transaction1.Id, transactionProduct);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add transaction products
|
List<TransactionProduct> testTransactionProducts2 = new List<TransactionProduct>
|
||||||
foreach (var transactionProduct in transactionProducts)
|
|
||||||
{
|
{
|
||||||
var transactionId = transactions[transactionProduct.TransactionIndex].Id;
|
new TransactionProduct { ProductID = 28, Quantity=5},
|
||||||
transactionCrud.AddTransactionProductToTransaction(
|
new TransactionProduct { ProductID = 22, Quantity=5}
|
||||||
transactionId,
|
};
|
||||||
new TransactionProduct
|
foreach (var transactionProduct in testTransactionProducts2)
|
||||||
{
|
{
|
||||||
ProductID = transactionProduct.ProductID,
|
transactionCrud.AddTransactionProductToTransaction(transaction2.Id, transactionProduct);
|
||||||
Quantity = transactionProduct.Quantity
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<TransactionProduct> testTransactionProducts3 = new List<TransactionProduct>
|
||||||
|
{
|
||||||
|
new TransactionProduct { ProductID = 3, Quantity=9},
|
||||||
|
new TransactionProduct { ProductID = 2, Quantity=1}
|
||||||
|
};
|
||||||
|
foreach (var transactionProduct in testTransactionProducts3)
|
||||||
|
{
|
||||||
|
transactionCrud.AddTransactionProductToTransaction(transaction3.Id, transactionProduct);
|
||||||
|
|
||||||
|
}
|
||||||
|
List<TransactionProduct> testTransactionProducts4 = new List<TransactionProduct>
|
||||||
|
{
|
||||||
|
new TransactionProduct { ProductID = 33, Quantity=12},
|
||||||
|
new TransactionProduct { ProductID = 12, Quantity=1}
|
||||||
|
};
|
||||||
|
foreach (var transactionProduct in testTransactionProducts4)
|
||||||
|
{
|
||||||
|
transactionCrud.AddTransactionProductToTransaction(transaction4.Id, transactionProduct);
|
||||||
|
|
||||||
/* List<TransactionProduct> testTransactionProducts = new List<TransactionProduct> {
|
}
|
||||||
new TransactionProduct { ProductID =17, Quantity = 3 },
|
|
||||||
new TransactionProduct { ProductID = 14, Quantity = 1 },
|
|
||||||
new TransactionProduct { ProductID = 1, Quantity = 1 },
|
|
||||||
};
|
|
||||||
foreach (var transactionProduct in testTransactionProducts)
|
|
||||||
{
|
|
||||||
transactionCrud.AddTransactionProductToTransaction(transaction1.Id, transactionProduct);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
List<TransactionProduct> testTransactionProducts2 = new List<TransactionProduct>
|
|
||||||
{
|
|
||||||
new TransactionProduct { ProductID = 28, Quantity=5},
|
|
||||||
new TransactionProduct { ProductID = 22, Quantity=5}
|
|
||||||
};
|
|
||||||
foreach (var transactionProduct in testTransactionProducts2)
|
|
||||||
{
|
|
||||||
transactionCrud.AddTransactionProductToTransaction(transaction2.Id, transactionProduct);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
List<TransactionProduct> testTransactionProducts3 = new List<TransactionProduct>
|
|
||||||
{
|
|
||||||
new TransactionProduct { ProductID = 3, Quantity=9},
|
|
||||||
new TransactionProduct { ProductID = 2, Quantity=1}
|
|
||||||
};
|
|
||||||
foreach (var transactionProduct in testTransactionProducts3)
|
|
||||||
{
|
|
||||||
transactionCrud.AddTransactionProductToTransaction(transaction3.Id, transactionProduct);
|
|
||||||
|
|
||||||
}
|
|
||||||
List<TransactionProduct> testTransactionProducts4 = new List<TransactionProduct>
|
|
||||||
{
|
|
||||||
new TransactionProduct { ProductID = 33, Quantity=12},
|
|
||||||
new TransactionProduct { ProductID = 12, Quantity=1}
|
|
||||||
};
|
|
||||||
foreach (var transactionProduct in testTransactionProducts4)
|
|
||||||
{
|
|
||||||
transactionCrud.AddTransactionProductToTransaction(transaction4.Id, transactionProduct);
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch(Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine(ex.ToString());
|
Console.WriteLine(ex.ToString());
|
||||||
throw;
|
throw;
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"AppSettings": {
|
"AppSettings": {
|
||||||
"ConnectionString": "Server=tcp:firmtracker-server.database.windows.net,1433;Initial Catalog=FirmTracker;Persist Security Info=False;User ID=FirmTrackerSa;Password=X27a61y183z799;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
|
"ConnectionString": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=master;Integrated Security=True;"
|
||||||
|
|
||||||
},
|
},
|
||||||
"TokenConfig": {
|
"TokenConfig": {
|
||||||
"JwtSecKey": "omgi5Rf4tqg351GQwefw1234567890123456",
|
"JwtSecKey": "omgi5Rf4tqg351GQwefw1234567890123456",
|
||||||
"JwtExpireDays": 1,
|
"JwtExpireDays": 30,
|
||||||
"JwtIssuer": "http://api.graphcom.pl"
|
"JwtIssuer": "http://api.graphcom.pl"
|
||||||
},
|
},
|
||||||
"profiles": {
|
"profiles": {
|
||||||
@ -17,7 +17,14 @@
|
|||||||
"applicationUrl": "http://localhost:5045"
|
"applicationUrl": "http://localhost:5045"
|
||||||
|
|
||||||
},
|
},
|
||||||
|
"https": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"applicationUrl": "https://localhost:7039"
|
||||||
|
|
||||||
|
},
|
||||||
"IIS Express": {
|
"IIS Express": {
|
||||||
"commandName": "IISExpress",
|
"commandName": "IISExpress",
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
|
10
nHIbernate/Absence.cs
Normal file
10
nHIbernate/Absence.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using FirmTracker_Server.Entities;
|
||||||
|
|
||||||
|
namespace FirmTracker_Server.nHibernate
|
||||||
|
{
|
||||||
|
public class Absence
|
||||||
|
{
|
||||||
|
public virtual int Id { get; set; }
|
||||||
|
public virtual string AbsenceName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
14
nHIbernate/AbsenceMapping.cs
Normal file
14
nHIbernate/AbsenceMapping.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using FirmTracker_Server.nHibernate;
|
||||||
|
using FluentNHibernate.Mapping;
|
||||||
|
namespace FirmTracker_Server.nHIbernate
|
||||||
|
{
|
||||||
|
public class AbsenceMapping : ClassMap<Absence>
|
||||||
|
{
|
||||||
|
public AbsenceMapping()
|
||||||
|
{
|
||||||
|
Table("Absences");
|
||||||
|
Id(x => x.Id).GeneratedBy.Identity();
|
||||||
|
Map(x => x.AbsenceName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,19 +1,11 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Transactions;
|
|
||||||
using FirmTracker_Server.nHibernate.Expenses;
|
using FirmTracker_Server.nHibernate.Expenses;
|
||||||
using FirmTracker_Server.nHibernate.Products;
|
|
||||||
using FirmTracker_Server.nHibernate.Transactions;
|
using FirmTracker_Server.nHibernate.Transactions;
|
||||||
using NHibernate;
|
using NHibernate;
|
||||||
using Transaction = FirmTracker_Server.nHibernate.Transactions.Transaction;
|
|
||||||
|
|
||||||
namespace FirmTracker_Server.nHibernate
|
namespace FirmTracker_Server.nHibernate
|
||||||
{
|
{
|
||||||
public interface IProductRepository
|
|
||||||
{
|
|
||||||
Product GetProduct(int id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface IExpenseRepository
|
public interface IExpenseRepository
|
||||||
{
|
{
|
||||||
List<Expense> GetAllExpenses();
|
List<Expense> GetAllExpenses();
|
||||||
@ -33,17 +25,6 @@ namespace FirmTracker_Server.nHibernate
|
|||||||
void DeleteTransaction(int transactionId);
|
void DeleteTransaction(int transactionId);
|
||||||
List<TransactionProduct> GetTransactionProductsForTransactions(List<int> transactionIds);
|
List<TransactionProduct> GetTransactionProductsForTransactions(List<int> transactionIds);
|
||||||
}
|
}
|
||||||
public class ProductRepository : IProductRepository
|
|
||||||
{
|
|
||||||
public Product GetProduct(int id)
|
|
||||||
{
|
|
||||||
using (var session = SessionFactory.OpenSession())
|
|
||||||
{
|
|
||||||
return session.Get<Product>(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class TransactionRepository : ITransactionRepository
|
public class TransactionRepository : ITransactionRepository
|
||||||
{
|
{
|
||||||
// Retrieve all transactions
|
// Retrieve all transactions
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using FirmTracker_Server.nHIbernate;
|
||||||
using FluentNHibernate.Cfg;
|
using FluentNHibernate.Cfg;
|
||||||
using FluentNHibernate.Cfg.Db;
|
using FluentNHibernate.Cfg.Db;
|
||||||
using NHibernate;
|
using NHibernate;
|
||||||
@ -56,7 +57,8 @@ namespace FirmTracker_Server.nHibernate
|
|||||||
.AddFromAssemblyOf<Reports.ReportExpenseMapping>()
|
.AddFromAssemblyOf<Reports.ReportExpenseMapping>()
|
||||||
.AddFromAssemblyOf<LogsMapping>()
|
.AddFromAssemblyOf<LogsMapping>()
|
||||||
.AddFromAssemblyOf<UserMapping>()
|
.AddFromAssemblyOf<UserMapping>()
|
||||||
.AddFromAssemblyOf<WorkdayMapping>();
|
.AddFromAssemblyOf<WorkdayMapping>()
|
||||||
|
.AddFromAssemblyOf<AbsenceMapping>();
|
||||||
|
|
||||||
})
|
})
|
||||||
.ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true, true)) //SchemaUpdate . Execute dla only update
|
.ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true, true)) //SchemaUpdate . Execute dla only update
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using FirmTracker_Server.Entities;
|
using FirmTracker_Server.Entities;
|
||||||
using FirmTracker_Server.nHibernate;
|
using FirmTracker_Server.nHibernate;
|
||||||
using static NHibernate.Engine.Query.CallableParser;
|
using static NHibernate.Engine.Query.CallableParser;
|
||||||
using FirmTracker_Server.Models;
|
|
||||||
|
|
||||||
public class WorkdayRepository
|
public class WorkdayRepository
|
||||||
{
|
{
|
||||||
@ -46,8 +45,29 @@ public class WorkdayRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void AddAbsence(string Absence)
|
||||||
public void AddAbsence(int userId, string absenceType, DateTime startTime, DateTime endTime)
|
{
|
||||||
|
using (var session = SessionFactory.OpenSession())
|
||||||
|
using (var transaction = session.BeginTransaction())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var absence = new Absence
|
||||||
|
{
|
||||||
|
AbsenceName = Absence,
|
||||||
|
};
|
||||||
|
|
||||||
|
session.Save(absence);
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw new Exception("An error occurred while adding the absence", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void AddAbsenceToUser(int userId, string absenceType, DateTime startTime, DateTime endTime)
|
||||||
{
|
{
|
||||||
using (var session = SessionFactory.OpenSession())
|
using (var session = SessionFactory.OpenSession())
|
||||||
using (var transaction = session.BeginTransaction())
|
using (var transaction = session.BeginTransaction())
|
||||||
@ -72,11 +92,13 @@ public class WorkdayRepository
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
transaction.Rollback();
|
transaction.Rollback();
|
||||||
throw new Exception("An error occurred while adding the absence", ex);
|
throw new Exception("An error occurred while adding the absence to user ", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public bool StopWorkday(int userId)
|
public bool StopWorkday(int userId)
|
||||||
{
|
{
|
||||||
using (var session = SessionFactory.OpenSession())
|
using (var session = SessionFactory.OpenSession())
|
||||||
@ -108,7 +130,28 @@ public class WorkdayRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public List<Absence> GetAbsences()
|
||||||
|
{
|
||||||
|
|
||||||
|
using (var session = SessionFactory.OpenSession())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var absences = session.Query<Absence>()
|
||||||
|
.Select(w => new Absence
|
||||||
|
{
|
||||||
|
AbsenceName = w.AbsenceName
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return absences;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception("An error occurred while fetching workdays", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
public List<Workday> GetWorkdaysByUser(string email)
|
public List<Workday> GetWorkdaysByUser(string email)
|
||||||
{
|
{
|
||||||
using (var session = SessionFactory.OpenSession())
|
using (var session = SessionFactory.OpenSession())
|
||||||
@ -143,96 +186,6 @@ public class WorkdayRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public DayDetailsDto GetDayDetails(string mail, DateTime date)
|
|
||||||
{
|
|
||||||
using (var session = SessionFactory.OpenSession())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Fetch workdays for the specified user on the given date
|
|
||||||
var startOfDay = date.Date;
|
|
||||||
var endOfDay = startOfDay.AddDays(1);
|
|
||||||
|
|
||||||
var workdays = session.Query<Workday>()
|
|
||||||
.Where(w => w.User.Email == mail && w.StartTime >= startOfDay && w.StartTime < endOfDay)
|
|
||||||
.Select(w => new Workday
|
|
||||||
{
|
|
||||||
StartTime = w.StartTime,
|
|
||||||
EndTime = w.EndTime ?? DateTime.Today.AddHours(17),
|
|
||||||
Absence = w.Absence,
|
|
||||||
})
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
TimeSpan totalWorkedHours = TimeSpan.Zero;
|
|
||||||
|
|
||||||
// Calculate total worked hours and adjust if there's an absence
|
|
||||||
foreach (var workday in workdays)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(workday.Absence))
|
|
||||||
{
|
|
||||||
totalWorkedHours += workday.WorkedHours;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new DayDetailsDto
|
|
||||||
{
|
|
||||||
Email = mail,
|
|
||||||
Date = date,
|
|
||||||
TotalWorkedHours = totalWorkedHours.ToString(@"hh\:mm\:ss"),
|
|
||||||
WorkdayDetails = workdays
|
|
||||||
};
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new Exception("An error occurred while fetching the day's details", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public DayDetailsLoggedUserDto GetDayDetailsForLoggedUser(int userId, DateTime date)
|
|
||||||
{
|
|
||||||
using (var session = SessionFactory.OpenSession())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Fetch workdays for the specified user on the given date
|
|
||||||
var startOfDay = date.Date;
|
|
||||||
var endOfDay = startOfDay.AddDays(1);
|
|
||||||
|
|
||||||
var workdays = session.Query<Workday>()
|
|
||||||
.Where(w => w.User.UserId == userId && w.StartTime >= startOfDay && w.StartTime < endOfDay)
|
|
||||||
.Select(w => new Workday
|
|
||||||
{
|
|
||||||
StartTime = w.StartTime,
|
|
||||||
EndTime = w.EndTime ?? DateTime.Today.AddHours(17),
|
|
||||||
Absence = w.Absence,
|
|
||||||
})
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
TimeSpan totalWorkedHours = TimeSpan.Zero;
|
|
||||||
|
|
||||||
// Calculate total worked hours and adjust if there's an absence
|
|
||||||
foreach (var workday in workdays)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(workday.Absence))
|
|
||||||
{
|
|
||||||
totalWorkedHours += workday.WorkedHours;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new DayDetailsLoggedUserDto
|
|
||||||
{
|
|
||||||
UserId = userId,
|
|
||||||
Date = date,
|
|
||||||
TotalWorkedHours = totalWorkedHours.ToString(@"hh\:mm\:ss"),
|
|
||||||
WorkdayDetails = workdays
|
|
||||||
};
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new Exception("An error occurred while fetching the day's details", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public List<Workday> GetWorkdaysByLoggedUser(string userId)
|
public List<Workday> GetWorkdaysByLoggedUser(string userId)
|
||||||
{
|
{
|
||||||
using (var session = SessionFactory.OpenSession())
|
using (var session = SessionFactory.OpenSession())
|
||||||
@ -252,6 +205,14 @@ public class WorkdayRepository
|
|||||||
})
|
})
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
foreach (var workday in workdays)
|
||||||
|
{
|
||||||
|
if (workday.Absence != "")
|
||||||
|
{
|
||||||
|
workday.WorkedHours = TimeSpan.Zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return workdays;
|
return workdays;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -253,7 +253,7 @@ namespace FirmTracker_Server.nHibernate.Transactions
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
transaction.Rollback();
|
transaction.Rollback();
|
||||||
throw;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user