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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"**/CVS": true,
"**/.DS_Store": true,
"CourseApp": true,
"CourseApp.test":true,
"CourseApp.Tests":true,
"WebApplication":true
}
}
2 changes: 1 addition & 1 deletion CourseApp.Tests/CourseApp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp5</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
4 changes: 4 additions & 0 deletions CourseApp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Global
{74C10DE5-3D2E-4614-B6CD-4379A98D7289}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74C10DE5-3D2E-4614-B6CD-4379A98D7289}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74C10DE5-3D2E-4614-B6CD-4379A98D7289}.Release|Any CPU.Build.0 = Release|Any CPU
{AA99FDD0-84D3-4846-B383-62F6903D335D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA99FDD0-84D3-4846-B383-62F6903D335D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA99FDD0-84D3-4846-B383-62F6903D335D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA99FDD0-84D3-4846-B383-62F6903D335D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion CourseApp/CourseApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp5</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>

Expand Down
25 changes: 23 additions & 2 deletions CourseApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
namespace CourseApp
{
using System;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

public class Program
{
public static void Main(string[] args)
{
Console.WriteLine($"Hello world");
Console.ReadLine();
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var enc1251 = Encoding.GetEncoding(1251);

System.Console.OutputEncoding = System.Text.Encoding.UTF8;
System.Console.InputEncoding = enc1251;

Console.WriteLine("Main Starts");

// создаем задачу
Task task1 = new Task(() =>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove this one from samples

{
Console.WriteLine("Task Starts");
Thread.Sleep(1000); // задержка на 1 секунду - имитация долгой работы
Console.WriteLine("Task Ends");
});
task1.Start(); // запускаем задачу
task1.Wait(); // ожидаем выполнения задачи
Console.WriteLine("Main Ends");

// Console.ReadLine();
}
}
}
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
# Tprogramming 2021

Master branch :)
Master branch :)

`docker volume create --name=mssqldata`

### Adding migrations

To create initial migration in the console please add the following commands. First of all you need to install migration [tools](https://docs.microsoft.com/ru-ru/ef/core/cli/dotnet).

```
dotnet tool install --global dotnet-ef
dotnet tool update --global dotnet-ef
```
Restart you terminal/VScode - and check the following command in terminal.
```
dotnet ef
```

**Note!** If you faced with issues ant the command was not executed - check you environmental variables. For windows in `Path` variable you should be able to see

```
%USERPROFILE%\.dotnet\tools
```

Execute next command strictly in the `WebApplication` folder

```
dotnet add package Microsoft.EntityFrameworkCore.Design
```

Finally you may work with migration (from `WebApplication` folder). The following command will create initial migration.

```
dotnet ef migrations add InitialMigration
```
105 changes: 105 additions & 0 deletions WebApplication/Controllers/ProductsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
namespace WebApplication.Controllers
{
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using WebApplication.Models;

[Route("api/[controller]")]
[ApiController]
public class ProductsController : ControllerBase
{
private readonly ApplicationContext _context;

public ProductsController(ApplicationContext context)
{
_context = context;
}

// GET: api/Products
[HttpGet]
public async Task<ActionResult<IEnumerable<Product>>> GetProducts()
{
return await _context.Products.ToListAsync();
}

// GET: api/Products/5
[HttpGet("{id}")]
public async Task<ActionResult<Product>> GetProduct(int id)
{
var product = await _context.Products.FindAsync(id);

if (product == null)
{
return NotFound();
}

return product;
}

// PUT: api/Products/5
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("{id}")]
public async Task<IActionResult> PutProduct(int id, Product product)
{
if (id != product.Id)
{
return BadRequest();
}

_context.Entry(product).State = EntityState.Modified;

try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!ProductExists(id))
{
return NotFound();
}
else
{
throw;
}
}

return NoContent();
}

// POST: api/Products
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost]
public async Task<ActionResult<Product>> PostProduct(Product product)
{
_context.Products.Add(product);
await _context.SaveChangesAsync();

return CreatedAtAction("GetProduct", new { id = product.Id }, product);
}

// DELETE: api/Products/5
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteProduct(int id)
{
var product = await _context.Products.FindAsync(id);
if (product == null)
{
return NotFound();
}

_context.Products.Remove(product);
await _context.SaveChangesAsync();

return NoContent();
}

private bool ProductExists(int id)
{
return _context.Products.Any(e => e.Id == id);
}
}
}
24 changes: 24 additions & 0 deletions WebApplication/Controllers/TempController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace WebApplication.Controllers
{
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using WebApplication.Models;

[ApiController]
[Route("/api/[controller]")]
public class TempController : ControllerBase
{
private ApplicationContext db;

public TempController(ApplicationContext context)
{
db = context;
}

[HttpGet]
public IEnumerable<Product> Get()
{
return db.Products;
}
}
}
21 changes: 21 additions & 0 deletions WebApplication/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["WebApplication/WebApplication.csproj", "WebApplication/"]
RUN dotnet restore "WebApplication/WebApplication.csproj"
COPY . .
WORKDIR "/src/WebApplication"
RUN dotnet build "WebApplication.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "WebApplication.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication.dll"]

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

34 changes: 34 additions & 0 deletions WebApplication/Migrations/20220418061640_InitialMigration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace WebApplication.Migrations
{
public partial class InitialMigration : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Products",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
Description = table.Column<string>(type: "nvarchar(max)", nullable: true),
Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Products", x => x.Id);
});
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Products");
}
}
}
Loading