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
25 changes: 25 additions & 0 deletions WebApplication2.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApplication2", "WebApplication2\WebApplication2.csproj", "{A3C4B520-7F32-41BD-BB6D-89C04904A2D5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A3C4B520-7F32-41BD-BB6D-89C04904A2D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A3C4B520-7F32-41BD-BB6D-89C04904A2D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3C4B520-7F32-41BD-BB6D-89C04904A2D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3C4B520-7F32-41BD-BB6D-89C04904A2D5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FC182C95-8D23-411D-A5E0-8E2C33E072C8}
EndGlobalSection
EndGlobal
119 changes: 119 additions & 0 deletions WebApplication2/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using WebApplication2.Models;
// Add-Migration InitialCreate -Namespace WebApplication2;
namespace WebApplication2.Controllers
{
public class HomeController : Controller
{
private ApplicationContext db;
public HomeController(ApplicationContext context)
{
db = context;
}

public async Task<IActionResult> Index()
{
//return View();
return View(await db.t_Users.ToListAsync());
}
public IActionResult Create()
{
return View();
}
[HttpPost]
public async Task<IActionResult> Create(User user)
{
db.t_Users.Add(user);
await db.SaveChangesAsync();
return RedirectToAction("Index");
}

public async Task<IActionResult> Details(int? id)
{
if (id != null)
{
User user = await db.t_Users.FirstOrDefaultAsync(p => p.Id == id);
if (user != null)
return View(user);
}
return NotFound();
}

public async Task<IActionResult> Edit(int? id)
{
if (id != null)
{
User user = await db.t_Users.FirstOrDefaultAsync(p => p.Id == id);
if (user != null)
return View(user);
}
return NotFound();
}
[HttpPost]
public async Task<IActionResult> Edit(User user)
{
db.t_Users.Update(user);
await db.SaveChangesAsync();
return RedirectToAction("Index");
}

[HttpGet]
[ActionName("Delete")]
public async Task<IActionResult> ConfirmDelete(int? id)
{
if (id != null)
{
User user = await db.t_Users.FirstOrDefaultAsync(p => p.Id == id);
if (user != null)
return View(user);
}
return NotFound();
}

[HttpPost]
public async Task<IActionResult> Delete(int? id)
{
if (id != null)
{
User user = await db.t_Users.FirstOrDefaultAsync(p => p.Id == id);
if (user != null)
{
db.t_Users.Remove(user);
await db.SaveChangesAsync();
return RedirectToAction("Index");
}
}
return NotFound();
}

/*private readonly ILogger<HomeController> _logger;

public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}

public IActionResult Index()
{
return View();
}

public IActionResult Privacy()
{
return View();
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}*/
}
}
43 changes: 43 additions & 0 deletions WebApplication2/Migrations/20200512125157_Migration1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions WebApplication2/Migrations/20200512125157_Migration1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore.Migrations;

namespace WebApplication2.Migrations
{
public partial class Migration1 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "t_Users",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(nullable: true),
Age = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_t_Users", x => x.Id);
});
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "t_Users");
}
}
}
40 changes: 40 additions & 0 deletions WebApplication2/Migrations/ApplicationContextModelSnapshot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using WebApplication2.Models;

namespace WebApplication2.Migrations
{
[DbContext(typeof(ApplicationContext))]
partial class ApplicationContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("WebApplication2.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

b.Property<int>("Age")
.HasColumnType("int");

b.Property<string>("Name")
.HasColumnType("nvarchar(max)");

b.HasKey("Id");

b.ToTable("t_Users");
});
#pragma warning restore 612, 618
}
}
}
21 changes: 21 additions & 0 deletions WebApplication2/Models/ApplicationContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;


namespace WebApplication2.Models
{
public class ApplicationContext : DbContext
{
// public DbSet<User> Users { get; set; }
/*public DbSet<TV> TVS { get; set; }*/
public DbSet<WebApplication2.Models.User> t_Users { get; set; }
public ApplicationContext(DbContextOptions<ApplicationContext> options)
:base(options)
{
Database.EnsureCreated();
}
}
}
11 changes: 11 additions & 0 deletions WebApplication2/Models/ErrorViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace WebApplication2.Models
{
public class ErrorViewModel
{
public string RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}
}
14 changes: 14 additions & 0 deletions WebApplication2/Models/TV.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebApplication2.Models
{
public class TV
{
public int ChanelNumber { get; set; }
public string Marka { get; set; }
public int NumberOfcolors { get; set; }
}
}
14 changes: 14 additions & 0 deletions WebApplication2/Models/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebApplication2.Models
{
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
}
26 changes: 26 additions & 0 deletions WebApplication2/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace WebApplication2
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
27 changes: 27 additions & 0 deletions WebApplication2/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:50299",
"sslPort": 44392
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"WebApplication2": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Loading