Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ publish/
#*.pubxml
*.publishproj

# Microsoft Azure Web App publish settings. Comment the next line if you want to
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
Expand Down Expand Up @@ -264,4 +265,30 @@ paket-files/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
*.pyc
/WebApplication1/obj/Debug/net6.0/WebApplication1.assets.cache
/WebApplication1/bin/Debug/net6.0/WebApplication1.deps.json
/WebApplication1/bin/Debug/net6.0/WebApplication1.dll
/WebApplication1/.vscode/launch.json
/WebApplication1/.vscode/tasks.json
/WebApplication1/bin/Debug/net6.0/WebApplication1.deps.json
/WebApplication1/bin/Debug/net6.0/WebApplication1.exe
/WebApplication1/bin/Debug/net6.0/WebApplication1.staticwebassets.runtime.json
/WebApplication1/obj/Debug/net6.0/apphost.exe
/WebApplication1/obj/Debug/net6.0/ref/WebApplication1.dll
/WebApplication1/obj/Debug/net6.0/refint/WebApplication1.dll
/WebApplication1/obj/Debug/net6.0/staticwebassets.build.json
/WebApplication1/obj/Debug/net6.0/staticwebassets.development.json
/WebApplication1/obj/Debug/net6.0/staticwebassets.pack.json
/WebApplication1/obj/Debug/net6.0/WebApplication1.csproj.AssemblyReference.cache
/WebApplication1/obj/Debug/net6.0/WebApplication1.csproj.CoreCompileInputs.cache
/WebApplication1/obj/Debug/net6.0/WebApplication1.csproj.FileListAbsolute.txt
/WebApplication1/obj/Debug/net6.0/WebApplication1.dll
/WebApplication1/obj/Debug/net6.0/WebApplication1.GeneratedMSBuildEditorConfig.editorconfig
/WebApplication1/obj/Debug/net6.0/WebApplication1.genruntimeconfig.cache
/WebApplication1/obj/Debug/net6.0/WebApplication1.pdb
/WebApplication1/obj/Debug/net6.0/WebApplication1.RazorAssemblyInfo.cs
/WebApplication1/obj/project.assets.json
/WebApplication1/obj/project.nuget.cache
/WebApplication1/obj/WebApplication1.csproj.nuget.dgspec.json
/WebApplication1/obj/WebApplication1.csproj.nuget.g.props
Binary file modified .vs/WebApplication1/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .vs/WebApplication1/v17/.suo
Binary file not shown.
58 changes: 58 additions & 0 deletions DbWork/DBWork.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Npgsql;
using System.Data.Common;

namespace DbWork
{
public static class DBWork
{
private static NpgsqlConnection npgSqlConnection = new NpgsqlConnection("Server=localhost;Port=5432;Username=postgres;Password=1473200;Database=homework;");

public static void AddUser(User user)
{
npgSqlConnection.Open();
NpgsqlCommand npgSqlCommand = new NpgsqlCommand($"INSERT INTO users VALUES ({user.Id}, '{user.Name}', {user.Kaka})", npgSqlConnection);
int count = npgSqlCommand.ExecuteNonQuery();
npgSqlConnection.Close();
}

public static void DeleteUser(User user)
{
npgSqlConnection.Open();
NpgsqlCommand npgSqlCommand = new NpgsqlCommand($"DELETE FROM users WHERE user_id = {user.Id}", npgSqlConnection);
int count = npgSqlCommand.ExecuteNonQuery();
npgSqlConnection.Close();
}
public static void ChangeUser(User user)
{
npgSqlConnection.Open();
NpgsqlCommand npgSqlCommand = new NpgsqlCommand($"UPDATE users SET user_name = '{user.Name}' WHERE user_id = {user.Id}", npgSqlConnection);
int count = npgSqlCommand.ExecuteNonQuery();
npgSqlConnection.Close();
}

public static void AddKaka(User user)
{
npgSqlConnection.Open();
NpgsqlCommand npgSqlCommand = new NpgsqlCommand($"UPDATE users SET user_kakah = user_kakah + {user.Kaka} WHERE user_id = {user.Id}", npgSqlConnection);
int count = npgSqlCommand.ExecuteNonQuery();
npgSqlConnection.Close();
}

public static List<User> GetUsers()
{
List<User> users = new List<User>();
npgSqlConnection.Open();
NpgsqlCommand npgSqlCommand = new NpgsqlCommand("SELECT * FROM users ORDER BY user_id", npgSqlConnection);
NpgsqlDataReader npgSqlDataReader = npgSqlCommand.ExecuteReader();
foreach (DbDataRecord dbDataRecord in npgSqlDataReader)
{
users.Add(new User(Convert.ToInt32(dbDataRecord["user_id"]), dbDataRecord["user_name"].ToString(), Convert.ToInt32(dbDataRecord["user_kakah"])));
}
npgSqlConnection.Close();
return users;
}



}
}
13 changes: 13 additions & 0 deletions DbWork/DbWork.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.1" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion WebApplication1/IEntity.cs → DbWork/IEntity.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace WebApplication1
namespace DbWork
{
public interface IEntity
{
Expand Down
17 changes: 17 additions & 0 deletions DbWork/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace DbWork
{
public class User: IEntity
{
public int Id { get; set; }
public string Name { get; set; }
public int Kaka { get; set; }
public string PhotoPath { get; set; }

public User(int id, string name, int kaka)
{
Id= id;
Name= name;
Kaka= kaka;
}
}
}
2 changes: 1 addition & 1 deletion WebApplication1/UserHub.cs → DbWork/UserHub.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace WebApplication1
namespace DbWork
{
public class UserHub<TEntity> where TEntity :class, IEntity
{
Expand Down
8 changes: 7 additions & 1 deletion WebApplication1.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33213.308
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApplication1", "WebApplication1\WebApplication1.csproj", "{25FE39B0-868F-449F-B601-02596D64A25B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApplication1", "WebApplication1\WebApplication1.csproj", "{25FE39B0-868F-449F-B601-02596D64A25B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DbWork", "DbWork\DbWork.csproj", "{210DE8FF-AB4D-4AB8-9F85-79C9E1A5BF98}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,6 +17,10 @@ Global
{25FE39B0-868F-449F-B601-02596D64A25B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{25FE39B0-868F-449F-B601-02596D64A25B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{25FE39B0-868F-449F-B601-02596D64A25B}.Release|Any CPU.Build.0 = Release|Any CPU
{210DE8FF-AB4D-4AB8-9F85-79C9E1A5BF98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{210DE8FF-AB4D-4AB8-9F85-79C9E1A5BF98}.Debug|Any CPU.Build.0 = Debug|Any CPU
{210DE8FF-AB4D-4AB8-9F85-79C9E1A5BF98}.Release|Any CPU.ActiveCfg = Release|Any CPU
{210DE8FF-AB4D-4AB8-9F85-79C9E1A5BF98}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
36 changes: 32 additions & 4 deletions WebApplication1/Pages/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@page
@using WebApplication1;
@using DbWork
@using Microsoft.AspNetCore.Mvc.TagHelpers
@model IndexModel
@{
ViewData["Title"] = "Сомнительная страницв";
Expand All @@ -9,15 +11,32 @@
<div class="text-center">
<h1>Заходи не бойся, уходи не плачь</h1>
<h1>Дримтим</h1>
<h1>@Model.Lalala</h1>

<table class="table">
@foreach (var item in Model.UserHub.Entities)
@foreach (var item in DBWork.GetUsers())
{
<tr>
<td>@item.Id </td>
<td>
@item.Id
<form asp-page-handler="Delete" asp-route-id="@item.Id" method="post">
<button class="btn btn-default">delete</button>
</form>
</td>

<td>@item.Name </td>

<td>
<form asp-page-handler="AddKaka" asp-route-id="@item.Id" method="post">
<button class="btn btn-default">+</button>
</form>
@item.Kaka
<form asp-page-handler="RemoveKaka" asp-route-id="@item.Id" method="post">
<button class="btn btn-default">-</button>
</form>
</td>
</tr>
}
}
</table>

<h2>Добавка</h2>
Expand All @@ -30,7 +49,7 @@
<input type="submit" value="Прищучить" asp-page-handler="Add" />
</form>

<h2>Убавка</h2>
@* <h2>Убавка</h2>
<p>Введите ID пользователя</p>
<form method="post">
<label for="id">АйИди</label><br />
Expand All @@ -47,4 +66,13 @@
<input type="text" name="name" id="name" /><br /><br />
<input type="submit" value="Махнуть" asp-page-handler="Change" />
</form>

<h2>Метание каках</h2>
<p>Введите ID пользователя</p>
<form method="post">
<label for="id">АйИди</label><br />
<input type="number" name="id" id="id" /><br /><br />
<input type="submit" value="+" style="height:20px; width:20px; padding:0; border:0" asp-page-handler="AddKaka" />
<input type="submit" value="-" style="height:20px; width:20px; padding:0; border:0" asp-page-handler="RemoveKaka" />
</form>*@
</div>
29 changes: 21 additions & 8 deletions WebApplication1/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Reflection;
using DbWork;
using WebApplication1;

namespace WebApplication1.Pages
{
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
public UserHub<User> UserHub { get; set; }
public string Lalala { get; set; }

public IndexModel(ILogger<IndexModel> logger, UserHub<User> userHub)
public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
UserHub = userHub;
Lalala = "Do your HomeWork!!";
}

public void OnGet()
Expand All @@ -22,22 +23,34 @@ public void OnGet()

public IActionResult OnPostAdd(string name, int id)
{
UserHub.Entities.Any(u => u.Id == id);
UserHub.Add(new User(id, name));

DBWork.AddUser(new User(id, name, 0));
return RedirectToPage("index");
}

public IActionResult OnPostDelete(int id)
{

UserHub.Remove(id);
DBWork.DeleteUser(new User(id, "", 0));
return RedirectToPage("index");
}

public IActionResult OnPostChange(int id, string name)
{
UserHub.Change(new User(id, name));
DBWork.ChangeUser(new User(id, name, 0));
return RedirectToPage("index");
}

public IActionResult OnPostAddKaka(int id)
{

DBWork.AddKaka(new User(id, "", 1));
return RedirectToPage("index");
}

public IActionResult OnPostRemoveKaka(int id)
{

DBWork.AddKaka(new User(id, "", -1));
return RedirectToPage("index");
}
}
Expand Down
7 changes: 5 additions & 2 deletions WebApplication1/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-page="/Index">WebApplication1</a>
<a class="navbar-brand" asp-area="" asp-page="/Index">Our 1st RazorPage project</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
Expand All @@ -22,6 +22,9 @@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Team">OUR TEAM</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
</li>
Expand All @@ -38,7 +41,7 @@

<footer class="border-top footer text-muted">
<div class="container">
&copy; 2023 - WebApplication1 - <a asp-area="" asp-page="/Privacy">Privacy</a>
&copy; 2023 - Some trash - <a asp-area="" asp-page="/Privacy">Privacy</a>
</div>
</footer>

Expand Down
60 changes: 60 additions & 0 deletions WebApplication1/Pages/Team.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@page
@using DbWork
@using Microsoft.AspNetCore.Mvc.TagHelpers
@model TeamModel
@{
}

<h1 class="text-center">Employees</h1>

<div class="row">
@foreach (var item in DBWork.GetUsers())
{
var photoPath = $"/images/{item.PhotoPath ?? "noimage.png"}";
<div class="col-12 col-sm-6 col-lg-4">
<div class="card-deck">
<div class="card m-3">
<div class="card-header text-center">
<h3>@item.Name</h3>
</div>

<div class="text-center">
<img class="card-img-top" src="@photoPath" asp-append-version="true"/>
</div>

<div class="card-footer text-center">
<div class="row">
<div class="col">
<form asp-page-handler="RemoveKaka" asp-route-id="@item.Id" method="post">
<button class="btn btn-success m-1">-</button>
</form>
</div>
<div class="col">
<button class="btn btn-primary m-1">@item.Kaka</button>
</div>
<div class="col">
<form asp-page-handler="AddKaka" asp-route-id="@item.Id" method="post">
<button class="btn btn-danger m-1">+</button>
</form>
</div>
</div>
<form asp-page-handler="Delete" asp-route-id="@item.Id" method="post">
<button class="btn btn-primary">delete</button>
</form>
</div>
</div>
</div>
</div>
}

</div>

<h2>Добавка</h2>
<p>Введите имя пользователя и его ID</p>
<form method ="post">
<label for ="name">Имя</label><br />
<input type="text" name="name" id="name" /><br /><br />
<label for="id">АйИди</label><br />
<input type="number" name="id" id="id" /><br /><br />
<input type="submit" value="Прищучить" asp-page-handler="Add" />
</form>
Loading