diff --git a/.gitignore b/.gitignore index ed942e3..1a74988 100644 --- a/.gitignore +++ b/.gitignore @@ -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 @@ -264,4 +265,30 @@ paket-files/ # Python Tools for Visual Studio (PTVS) __pycache__/ -*.pyc \ No newline at end of file +*.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 diff --git a/.vs/WebApplication1/DesignTimeBuild/.dtbcache.v2 b/.vs/WebApplication1/DesignTimeBuild/.dtbcache.v2 index c37d760..08ab942 100644 Binary files a/.vs/WebApplication1/DesignTimeBuild/.dtbcache.v2 and b/.vs/WebApplication1/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/WebApplication1/FileContentIndex/1e5a52bc-5c43-4196-8c0f-6ff30c9309fb.vsidx b/.vs/WebApplication1/FileContentIndex/1e5a52bc-5c43-4196-8c0f-6ff30c9309fb.vsidx deleted file mode 100644 index 97a42ab..0000000 Binary files a/.vs/WebApplication1/FileContentIndex/1e5a52bc-5c43-4196-8c0f-6ff30c9309fb.vsidx and /dev/null differ diff --git a/.vs/WebApplication1/FileContentIndex/2e1ac3a7-d32d-4860-9ad8-7387aecb4110.vsidx b/.vs/WebApplication1/FileContentIndex/2e1ac3a7-d32d-4860-9ad8-7387aecb4110.vsidx deleted file mode 100644 index a5530ff..0000000 Binary files a/.vs/WebApplication1/FileContentIndex/2e1ac3a7-d32d-4860-9ad8-7387aecb4110.vsidx and /dev/null differ diff --git a/.vs/WebApplication1/FileContentIndex/33f23d2a-6b2c-4fae-b229-56a4d66af06b.vsidx b/.vs/WebApplication1/FileContentIndex/33f23d2a-6b2c-4fae-b229-56a4d66af06b.vsidx deleted file mode 100644 index 159b6f4..0000000 Binary files a/.vs/WebApplication1/FileContentIndex/33f23d2a-6b2c-4fae-b229-56a4d66af06b.vsidx and /dev/null differ diff --git a/.vs/WebApplication1/FileContentIndex/fc8d2ac4-97b0-4123-b96f-b59d26c222ba.vsidx b/.vs/WebApplication1/FileContentIndex/fc8d2ac4-97b0-4123-b96f-b59d26c222ba.vsidx deleted file mode 100644 index 21e01b5..0000000 Binary files a/.vs/WebApplication1/FileContentIndex/fc8d2ac4-97b0-4123-b96f-b59d26c222ba.vsidx and /dev/null differ diff --git a/.vs/WebApplication1/v17/.suo b/.vs/WebApplication1/v17/.suo index ab26104..ddbb0cf 100644 Binary files a/.vs/WebApplication1/v17/.suo and b/.vs/WebApplication1/v17/.suo differ diff --git a/DbWork/DBWork.cs b/DbWork/DBWork.cs new file mode 100644 index 0000000..e0772c1 --- /dev/null +++ b/DbWork/DBWork.cs @@ -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 GetUsers() + { + List users = new List(); + 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; + } + + + + } +} diff --git a/DbWork/DbWork.csproj b/DbWork/DbWork.csproj new file mode 100644 index 0000000..f7ad2b5 --- /dev/null +++ b/DbWork/DbWork.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/WebApplication1/IEntity.cs b/DbWork/IEntity.cs similarity index 71% rename from WebApplication1/IEntity.cs rename to DbWork/IEntity.cs index 48197ef..255e06f 100644 --- a/WebApplication1/IEntity.cs +++ b/DbWork/IEntity.cs @@ -1,4 +1,4 @@ -namespace WebApplication1 +namespace DbWork { public interface IEntity { diff --git a/DbWork/User.cs b/DbWork/User.cs new file mode 100644 index 0000000..3c5c296 --- /dev/null +++ b/DbWork/User.cs @@ -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; + } + } +} diff --git a/WebApplication1/UserHub.cs b/DbWork/UserHub.cs similarity index 95% rename from WebApplication1/UserHub.cs rename to DbWork/UserHub.cs index 501471d..d3963cb 100644 --- a/WebApplication1/UserHub.cs +++ b/DbWork/UserHub.cs @@ -1,4 +1,4 @@ -namespace WebApplication1 +namespace DbWork { public class UserHub where TEntity :class, IEntity { diff --git a/WebApplication1.sln b/WebApplication1.sln index 3906ad0..39b3368 100644 --- a/WebApplication1.sln +++ b/WebApplication1.sln @@ -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 @@ -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 diff --git a/WebApplication1/Pages/Index.cshtml b/WebApplication1/Pages/Index.cshtml index 0857b8c..6cdc621 100644 --- a/WebApplication1/Pages/Index.cshtml +++ b/WebApplication1/Pages/Index.cshtml @@ -1,5 +1,7 @@ @page @using WebApplication1; +@using DbWork +@using Microsoft.AspNetCore.Mvc.TagHelpers @model IndexModel @{ ViewData["Title"] = "Сомнительная страницв"; @@ -9,15 +11,32 @@

Заходи не бойся, уходи не плачь

Дримтим

+

@Model.Lalala

- @foreach (var item in Model.UserHub.Entities) + @foreach (var item in DBWork.GetUsers()) { - + + + + - } + }
@item.Id + @item.Id +
+ +
+
@item.Name +
+ +
+ @item.Kaka +
+ +
+

Добавка

@@ -30,7 +49,7 @@ -

Убавка

+ @*

Убавка

Введите ID пользователя


@@ -47,4 +66,13 @@

+ +

Метание каках

+

Введите ID пользователя

+
+
+

+ + +
*@
diff --git a/WebApplication1/Pages/Index.cshtml.cs b/WebApplication1/Pages/Index.cshtml.cs index 27fc217..e2ae562 100644 --- a/WebApplication1/Pages/Index.cshtml.cs +++ b/WebApplication1/Pages/Index.cshtml.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using System.Reflection; +using DbWork; using WebApplication1; namespace WebApplication1.Pages @@ -8,12 +9,12 @@ namespace WebApplication1.Pages public class IndexModel : PageModel { private readonly ILogger _logger; - public UserHub UserHub { get; set; } + public string Lalala { get; set; } - public IndexModel(ILogger logger, UserHub userHub) + public IndexModel(ILogger logger) { _logger = logger; - UserHub = userHub; + Lalala = "Do your HomeWork!!"; } public void OnGet() @@ -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"); } } diff --git a/WebApplication1/Pages/Shared/_Layout.cshtml b/WebApplication1/Pages/Shared/_Layout.cshtml index d6de52d..bf58c06 100644 --- a/WebApplication1/Pages/Shared/_Layout.cshtml +++ b/WebApplication1/Pages/Shared/_Layout.cshtml @@ -12,7 +12,7 @@