commit b48b36ae12e61abe961acd6764560c093a933f7f Author: neroduckale Date: Wed Dec 13 03:17:50 2023 +0500 коммит на русском языке в котором я могу писать все что хочу и мне никто не запретит. входный коммит №1 diff --git a/nrdkwebsite/DatabaseHandler.cs b/nrdkwebsite/DatabaseHandler.cs new file mode 100644 index 0000000..d8f16d6 --- /dev/null +++ b/nrdkwebsite/DatabaseHandler.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; + +namespace nrdkwebsite; + +public sealed class DatabaseHandler : DbContext +{ + public DbSet users { get; set; } = null!; + public DatabaseHandler(DbContextOptions options) : base(options) + { + + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity(entity => + { + entity.Property(u => u.nickname) + .HasColumnName("nickname") + .HasColumnType("varchar(100)") + .ValueGeneratedOnAdd(); + entity.Property(u => u.id) + .HasColumnName("id") + .HasColumnType("int") + .ValueGeneratedOnAdd(); + entity.Property(u => u.mast) + .HasColumnName("mast") + .HasColumnType("varchar(20)") + .ValueGeneratedOnAdd(); + }); + } +} \ No newline at end of file diff --git a/nrdkwebsite/Pages/_ViewImports.cshtml b/nrdkwebsite/Pages/_ViewImports.cshtml new file mode 100644 index 0000000..f90b56a --- /dev/null +++ b/nrdkwebsite/Pages/_ViewImports.cshtml @@ -0,0 +1,3 @@ +@using nrdkwebsite +@namespace nrdkwebsite.Pages +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers \ No newline at end of file diff --git a/nrdkwebsite/Pages/_ViewStart.cshtml b/nrdkwebsite/Pages/_ViewStart.cshtml new file mode 100644 index 0000000..2157e73 --- /dev/null +++ b/nrdkwebsite/Pages/_ViewStart.cshtml @@ -0,0 +1,4 @@ +@using nrdkwebsite.Pages +@{ + Layout = "layout"; +} diff --git a/nrdkwebsite/Pages/about.cshtml b/nrdkwebsite/Pages/about.cshtml new file mode 100644 index 0000000..93561fb --- /dev/null +++ b/nrdkwebsite/Pages/about.cshtml @@ -0,0 +1,7 @@ +@page +@model About + + +
+ neroduckale. +
\ No newline at end of file diff --git a/nrdkwebsite/Pages/about.cshtml.cs b/nrdkwebsite/Pages/about.cshtml.cs new file mode 100644 index 0000000..3216551 --- /dev/null +++ b/nrdkwebsite/Pages/about.cshtml.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace nrdkwebsite.Pages; + +public class About : PageModel +{ + private readonly ILogger _logger; + + public About(ILogger logger) + { + _logger = logger; + } + + public void OnGet() + { + + } +} \ No newline at end of file diff --git a/nrdkwebsite/Pages/error.cshtml b/nrdkwebsite/Pages/error.cshtml new file mode 100644 index 0000000..6f92b95 --- /dev/null +++ b/nrdkwebsite/Pages/error.cshtml @@ -0,0 +1,26 @@ +@page +@model ErrorModel +@{ + ViewData["Title"] = "Error"; +} + +

Error.

+

An error occurred while processing your request.

+ +@if (Model.ShowRequestId) +{ +

+ Request ID: @Model.RequestId +

+} + +

Development Mode

+

+ Swapping to the Development environment displays detailed information about the error that occurred. +

+

+ The Development environment shouldn't be enabled for deployed applications. + It can result in displaying sensitive information from exceptions to end users. + For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development + and restarting the app. +

diff --git a/nrdkwebsite/Pages/error.cshtml.cs b/nrdkwebsite/Pages/error.cshtml.cs new file mode 100644 index 0000000..93b0804 --- /dev/null +++ b/nrdkwebsite/Pages/error.cshtml.cs @@ -0,0 +1,26 @@ +using System.Diagnostics; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace nrdkwebsite.Pages; + +[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] +[IgnoreAntiforgeryToken] +public class ErrorModel : PageModel +{ + public string? RequestId { get; set; } + + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + + private readonly ILogger _logger; + + public ErrorModel(ILogger logger) + { + _logger = logger; + } + + public void OnGet() + { + RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; + } +} \ No newline at end of file diff --git a/nrdkwebsite/Pages/errors/404.cshtml b/nrdkwebsite/Pages/errors/404.cshtml new file mode 100644 index 0000000..9e9dcec --- /dev/null +++ b/nrdkwebsite/Pages/errors/404.cshtml @@ -0,0 +1,8 @@ +@page +@model error404 + +@{ + ViewData["Title"] = "not found"; +} + +

404! Страница не найдена

\ No newline at end of file diff --git a/nrdkwebsite/Pages/errors/404.cshtml.cs b/nrdkwebsite/Pages/errors/404.cshtml.cs new file mode 100644 index 0000000..8bbfb3f --- /dev/null +++ b/nrdkwebsite/Pages/errors/404.cshtml.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace nrdkwebsite.Pages.errors; + +public class error404 : PageModel +{ + public void OnGet() + { + + } + +} \ No newline at end of file diff --git a/nrdkwebsite/Pages/index.cshtml b/nrdkwebsite/Pages/index.cshtml new file mode 100644 index 0000000..e4de078 --- /dev/null +++ b/nrdkwebsite/Pages/index.cshtml @@ -0,0 +1,10 @@ +@page +@model IndexModel +@{ + ViewData["Title"] = "Home page"; +} + + +

Привет, это сайт neroduckale

+

Мой никнейм читается по разному - неродакля, неродукель, неродакале, но одно в нем остается неизменным - неро.

+спасибо мактайлорс за помощь с созданием сайта. version: 0.3 diff --git a/nrdkwebsite/Pages/index.cshtml.cs b/nrdkwebsite/Pages/index.cshtml.cs new file mode 100644 index 0000000..511dbb9 --- /dev/null +++ b/nrdkwebsite/Pages/index.cshtml.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace nrdkwebsite.Pages; + +public class IndexModel : PageModel +{ + private readonly ILogger _logger; + + public IndexModel(ILogger logger) + { + _logger = logger; + } + + + public void OnGet() + { + + } +} \ No newline at end of file diff --git a/nrdkwebsite/Pages/layout.cshtml b/nrdkwebsite/Pages/layout.cshtml new file mode 100644 index 0000000..4050af7 --- /dev/null +++ b/nrdkwebsite/Pages/layout.cshtml @@ -0,0 +1,35 @@ +@{ + if (ViewBag.Title == null) ViewBag.Title = "unknown"; +} + + + + + neroduckale's @ViewBag.Title + + + + @* *@ + + + + + +
+ + + +
+ +
+ @RenderBody() +
+ + + \ No newline at end of file diff --git a/nrdkwebsite/Pages/users.cshtml b/nrdkwebsite/Pages/users.cshtml new file mode 100644 index 0000000..3ddda27 --- /dev/null +++ b/nrdkwebsite/Pages/users.cshtml @@ -0,0 +1,16 @@ +@page +@using System.Collections +@model Users + + + + + + +
текст заголовкатекст заголовка
данныеданные
+ + \ No newline at end of file diff --git a/nrdkwebsite/Pages/users.cshtml.cs b/nrdkwebsite/Pages/users.cshtml.cs new file mode 100644 index 0000000..01bcfde --- /dev/null +++ b/nrdkwebsite/Pages/users.cshtml.cs @@ -0,0 +1,11 @@ +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace nrdkwebsite.Pages; + +public class Users : PageModel +{ + public void OnGet() + { + + } +} \ No newline at end of file diff --git a/nrdkwebsite/Pages/ygolek.cshtml b/nrdkwebsite/Pages/ygolek.cshtml new file mode 100644 index 0000000..95ca1ba --- /dev/null +++ b/nrdkwebsite/Pages/ygolek.cshtml @@ -0,0 +1,6 @@ +@page +@model nrdkwebsite.Pages.Ygolek + + + + \ No newline at end of file diff --git a/nrdkwebsite/Pages/ygolek.cshtml.cs b/nrdkwebsite/Pages/ygolek.cshtml.cs new file mode 100644 index 0000000..8dd5150 --- /dev/null +++ b/nrdkwebsite/Pages/ygolek.cshtml.cs @@ -0,0 +1,11 @@ +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace nrdkwebsite.Pages; + +public class Ygolek : PageModel +{ + public void OnGet() + { + + } +} \ No newline at end of file diff --git a/nrdkwebsite/Program.cs b/nrdkwebsite/Program.cs new file mode 100644 index 0000000..214ab99 --- /dev/null +++ b/nrdkwebsite/Program.cs @@ -0,0 +1,60 @@ +using Microsoft.EntityFrameworkCore; +using nrdkwebsite; +using Pomelo.EntityFrameworkCore.MySql.Infrastructure; + +var builder = WebApplication.CreateBuilder(args); +#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type. +var connection = builder.Configuration.GetConnectionString("DefaultConnection"); +#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type. +builder.Services.AddDbContext(options => options.UseMySql(connection, ServerVersion.Create(new Version(8, 0, 35), ServerType.MySql))); +builder.Services.AddRazorPages(); +var app = builder.Build(); +if (!app.Environment.IsDevelopment()) +{ + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); +} +app.UseStatusCodePagesWithReExecute("/errors/{0}"); +app.UseHttpsRedirection(); +app.UseStaticFiles(); + +app.MapGet("/api/users", (DatabaseHandler db) => db.users.ToList()); //WORKS +app.MapGet("/api/users/{id:int}", (int id, DatabaseHandler db) => { + var users = db.users.ToList(); + User? user = users.FirstOrDefault(u => u.id == id); + // если не найден, отправляем статусный код и сообщение об ошибке + if (user == null) return Results.NotFound(new { message = "Пользователь не найден" }); + + // если пользователь найден, отправляем его + return Results.Json(user); +}); //WORKS +app.MapGet("/api/users/nickname/{name}", (string name, DatabaseHandler db) => { + var users = db.users.ToList(); + User? user = users.FirstOrDefault(u => u.nickname == name); + // если не найден, отправляем статусный код и сообщение об ошибке + if (user == null) return Results.NotFound(new { message = "Пользователь не найден" }); + + // если пользователь найден, отправляем его + return Results.Json(user); +}); //WORKS +app.MapDelete("/api/users/{id:int}", async (int id, DatabaseHandler db) => { + User? user = db.users.FirstOrDefault(u => u.id == id); + if (user == null) return Results.NotFound(new { message = "Пользователь не найден" }); + db.users.Remove(user); + await db.SaveChangesAsync(); + return Results.Json(user); +}); //WORKS +app.MapPost("/api/users", async (User user, DatabaseHandler db)=> +{ + user.id = db.users.Count() + 1; + await db.users.AddAsync(user); + await db.SaveChangesAsync(); + return user; +}); //WORKS + +app.UseRouting(); +app.UseAuthorization(); +app.MapRazorPages(); +app.Run(); + diff --git a/nrdkwebsite/User.cs b/nrdkwebsite/User.cs new file mode 100644 index 0000000..7354bb5 --- /dev/null +++ b/nrdkwebsite/User.cs @@ -0,0 +1,15 @@ +namespace nrdkwebsite; + +public class User +{ + public string nickname { get; set; } + public int id { get; set; } + public string mast { get; set; } + + public User(string nickname, int id, string mast) + { + this.nickname = nickname; + this.id = id; + this.mast = mast; + } +} \ No newline at end of file diff --git a/nrdkwebsite/wwwroot/css/style.css b/nrdkwebsite/wwwroot/css/style.css new file mode 100644 index 0000000..03cd81f --- /dev/null +++ b/nrdkwebsite/wwwroot/css/style.css @@ -0,0 +1,38 @@ +body { + font-family: 'Raleway', sans-serif; + color: white; + margin: 0; + background: #2c2c2c; +} +a { + text-decoration: none; +} +.content { + text-align: center; + padding-top: 20px; +} + +.header-links { /*