Add project
This commit is contained in:
18
Common/Common.csproj
Normal file
18
Common/Common.csproj
Normal file
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Requests\**" />
|
||||
<Compile Remove="Responses\**" />
|
||||
<EmbeddedResource Remove="Requests\**" />
|
||||
<EmbeddedResource Remove="Responses\**" />
|
||||
<None Remove="Requests\**" />
|
||||
<None Remove="Responses\**" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
9
Common/Dtos/Common/BaseResponse.cs
Normal file
9
Common/Dtos/Common/BaseResponse.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System.Net;
|
||||
|
||||
namespace Common.Dtos.Common;
|
||||
|
||||
public abstract class BaseResponse
|
||||
{
|
||||
public bool Ok { get; set; }
|
||||
public string? Error { get; set; }
|
||||
}
|
||||
22
Common/Dtos/Common/PagedList.cs
Normal file
22
Common/Dtos/Common/PagedList.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace Common.Dtos.Common;
|
||||
|
||||
public class PagedList<T>
|
||||
{
|
||||
public PagedList(T[] items, int pageNumber, int pageSize, int totalItemsCount, int numberOfPages)
|
||||
{
|
||||
Items = items;
|
||||
PageNumber = pageNumber;
|
||||
PageSize = pageSize;
|
||||
TotalItemsCount = totalItemsCount;
|
||||
NumberOfPages = numberOfPages;
|
||||
}
|
||||
|
||||
public static PagedList<T> Empty(int pagedNumber, int pageSize)
|
||||
=> new([], pagedNumber, pageSize, 0, 0);
|
||||
|
||||
public T[] Items { get; }
|
||||
public int PageNumber { get; }
|
||||
public int PageSize { get; }
|
||||
public int TotalItemsCount { get; }
|
||||
public int NumberOfPages { get; }
|
||||
}
|
||||
7
Common/Dtos/Common/PagedRequest.cs
Normal file
7
Common/Dtos/Common/PagedRequest.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Common.Dtos.Common;
|
||||
|
||||
public abstract class PagedRequest
|
||||
{
|
||||
public int PageNumber { get; set; }
|
||||
public int PageSize { get; set; }
|
||||
}
|
||||
11
Common/Dtos/Common/ValidationProblems.cs
Normal file
11
Common/Dtos/Common/ValidationProblems.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Common.Dtos.Common;
|
||||
|
||||
public class ValidationProblems
|
||||
{
|
||||
public ValidationProblems()
|
||||
{
|
||||
Errors = [];
|
||||
}
|
||||
|
||||
public List<string> Errors { get; set; }
|
||||
}
|
||||
8
Common/Dtos/Season/CreateSeasonRequest.cs
Normal file
8
Common/Dtos/Season/CreateSeasonRequest.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Common.Dtos.Season;
|
||||
|
||||
public class CreateSeasonRequest
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
public DateOnly StartDate { get; set; }
|
||||
public DateOnly EndDate { get; set; }
|
||||
}
|
||||
8
Common/Dtos/Season/CreateSeasonResponse.cs
Normal file
8
Common/Dtos/Season/CreateSeasonResponse.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Common.Dtos.Common;
|
||||
|
||||
namespace Common.Dtos.Season;
|
||||
|
||||
public class CreateSeasonResponse : BaseResponse
|
||||
{
|
||||
public string? CreateSeasonResult { get; set; }
|
||||
}
|
||||
9
Common/Dtos/Season/GetSeasonsRequest.cs
Normal file
9
Common/Dtos/Season/GetSeasonsRequest.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using Common.Dtos.Common;
|
||||
|
||||
namespace Common.Dtos.Season;
|
||||
|
||||
public class GetSeasonsRequest : PagedRequest
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
public bool? HideObsolete { get; set; }
|
||||
}
|
||||
10
Common/Dtos/Season/SeasonDto.cs
Normal file
10
Common/Dtos/Season/SeasonDto.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Common.Dtos.Season;
|
||||
|
||||
public class SeasonDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public DateOnly StartDate { get; set; }
|
||||
public DateOnly EndDate { get; set; }
|
||||
public bool IsCurrent => StartDate <= DateOnly.FromDateTime(DateTime.Now) && EndDate >= DateOnly.FromDateTime(DateTime.Now);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Common.Dtos.Specialization;
|
||||
|
||||
public class CreateSpecializationRequest
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
public string? ShortName { get; set; }
|
||||
}
|
||||
12
Common/Dtos/Specialization/CreateSpecializationResponse.cs
Normal file
12
Common/Dtos/Specialization/CreateSpecializationResponse.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Common.Dtos.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Common.Dtos.Specialization
|
||||
{
|
||||
public class CreateSpecializationResponse : BaseResponse
|
||||
{
|
||||
public string? CreateSpecializationResult { get; set; }
|
||||
}
|
||||
}
|
||||
8
Common/Dtos/Specialization/GetSpecializationsRequest.cs
Normal file
8
Common/Dtos/Specialization/GetSpecializationsRequest.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Common.Dtos.Common;
|
||||
|
||||
namespace Common.Dtos.Specialization;
|
||||
|
||||
public class GetSpecializationsRequest : PagedRequest
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
15
Common/Dtos/Specialization/SpecializationDto.cs
Normal file
15
Common/Dtos/Specialization/SpecializationDto.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text;
|
||||
|
||||
namespace Common.Dtos.Specialization;
|
||||
|
||||
public class SpecializationDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? ShortName { get; set; }
|
||||
}
|
||||
8
Common/Dtos/Student/CreateStudentRequest.cs
Normal file
8
Common/Dtos/Student/CreateStudentRequest.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Common.Dtos.Student;
|
||||
|
||||
public class CreateStudentRequest
|
||||
{
|
||||
public required string FirstName { get; set; }
|
||||
public required string LastName { get; set; }
|
||||
public required string AlbumNumber { get; set; }
|
||||
}
|
||||
8
Common/Dtos/Student/CreateStudentResponse.cs
Normal file
8
Common/Dtos/Student/CreateStudentResponse.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Common.Dtos.Common;
|
||||
|
||||
namespace Common.Dtos.Student;
|
||||
|
||||
public class CreateStudentResponse : BaseResponse
|
||||
{
|
||||
public string? CreateStudentResult { get; set; }
|
||||
}
|
||||
10
Common/Dtos/Student/StudentBasicDto.cs
Normal file
10
Common/Dtos/Student/StudentBasicDto.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Common.Dtos.Student;
|
||||
|
||||
public class StudentBasicDto
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string? FirstName { get; set; }
|
||||
public string? LastName { get; set; }
|
||||
public string? AlbumNumber { get; set; }
|
||||
public string FullNameReverese => $"{LastName} {FirstName} ({AlbumNumber})";
|
||||
}
|
||||
7
Common/Dtos/Subject/CreateSubjectRequest.cs
Normal file
7
Common/Dtos/Subject/CreateSubjectRequest.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Common.Dtos.Subject;
|
||||
|
||||
public class CreateSubjectRequest
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
public string? ShortName { get; set; }
|
||||
}
|
||||
12
Common/Dtos/Subject/CreateSubjectResponse.cs
Normal file
12
Common/Dtos/Subject/CreateSubjectResponse.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Common.Dtos.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Common.Dtos.Subject
|
||||
{
|
||||
public class CreateSubjectResponse : BaseResponse
|
||||
{
|
||||
public string? CreateSubjectResult { get; set; }
|
||||
}
|
||||
}
|
||||
8
Common/Dtos/Subject/GetSubjectsRequest.cs
Normal file
8
Common/Dtos/Subject/GetSubjectsRequest.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Common.Dtos.Common;
|
||||
|
||||
namespace Common.Dtos.Subject;
|
||||
|
||||
public class GetSubjectsRequest : PagedRequest
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
12
Common/Dtos/Subject/SubjectDto.cs
Normal file
12
Common/Dtos/Subject/SubjectDto.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Common.Dtos.Subject;
|
||||
|
||||
public class SubjectDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? ShortName { get; set; }
|
||||
}
|
||||
11
Common/Extensions/JsonExtensions.cs
Normal file
11
Common/Extensions/JsonExtensions.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Common.Extensions
|
||||
{
|
||||
public static class JsonExtensions
|
||||
{
|
||||
private static JsonSerializerOptions _jso = new() { PropertyNameCaseInsensitive = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
|
||||
public static string ToJson<T>(this T source) => JsonSerializer.Serialize(source, _jso);
|
||||
public static T FromJson<T>(this string source) => JsonSerializer.Deserialize<T>(source, _jso) ?? default!;
|
||||
}
|
||||
}
|
||||
20
Common/Extensions/StringExtensions.cs
Normal file
20
Common/Extensions/StringExtensions.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Common.Pagination;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace Common.Extensions;
|
||||
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static IDictionary<string, object?> AsDictionary(this object source,
|
||||
BindingFlags bindingAttr = BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance)
|
||||
{
|
||||
return source.GetType().GetProperties(bindingAttr).ToDictionary
|
||||
(
|
||||
propInfo => propInfo.Name,
|
||||
propInfo => propInfo.GetValue(source, null)
|
||||
);
|
||||
}
|
||||
}
|
||||
15
Common/Pagination/PaginationExtensions.cs
Normal file
15
Common/Pagination/PaginationExtensions.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Common.Pagination;
|
||||
|
||||
public static class PaginationExtensions
|
||||
{
|
||||
public static string ToPaginationSummary(this PaginationProperties props)
|
||||
{
|
||||
var before = (props.PageSize * (props.PageNumber - 1)) + 1;
|
||||
var after = Math.Min((props.PageSize * props.PageNumber), props.TotalItems);
|
||||
return props.TotalItems == 0 ? $"{props.Text}: brak" : $"{props.Text}: {before}-{after} z {props.TotalItems}";
|
||||
}
|
||||
}
|
||||
21
Common/Pagination/PaginationProperties.cs
Normal file
21
Common/Pagination/PaginationProperties.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Common.Pagination;
|
||||
|
||||
public class PaginationProperties
|
||||
{
|
||||
public PaginationProperties(string text, int pageSize)
|
||||
{
|
||||
Text = text;
|
||||
PageNumber = 1;
|
||||
PageSize = pageSize;
|
||||
}
|
||||
|
||||
public int PageNumber { get; set; }
|
||||
public int PageSize { get; set; }
|
||||
public int TotalItems { get; set; }
|
||||
public int NumberOfPages { get; set; }
|
||||
public string? Text { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user