-
Notifications
You must be signed in to change notification settings - Fork 38
Added sample web Application #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jskonst
wants to merge
3
commits into
master
Choose a base branch
from
web_sample
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(() => | ||
| { | ||
| Console.WriteLine("Task Starts"); | ||
| Thread.Sleep(1000); // задержка на 1 секунду - имитация долгой работы | ||
| Console.WriteLine("Task Ends"); | ||
| }); | ||
| task1.Start(); // запускаем задачу | ||
| task1.Wait(); // ожидаем выполнения задачи | ||
| Console.WriteLine("Main Ends"); | ||
|
|
||
| // Console.ReadLine(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] |
50 changes: 50 additions & 0 deletions
50
WebApplication/Migrations/20220418061640_InitialMigration.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
WebApplication/Migrations/20220418061640_InitialMigration.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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