Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
Lesson49
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Пасько Виталий
Lesson49
Commits
320b1ea3
Commit
320b1ea3
authored
Jun 20, 2022
by
TTrueBenji
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Реализовать функционал заказов.
*** Реализовал возможность закза смартфона. ***
parent
0b081e06
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
220 additions
and
5 deletions
+220
-5
HomeController.cs
PhoneStore/Controllers/HomeController.cs
+67
-1
OrdersController.cs
PhoneStore/Controllers/OrdersController.cs
+50
-0
PhoneStore.csproj
PhoneStore/PhoneStore.csproj
+8
-0
Index.cshtml
PhoneStore/Views/Home/Index.cshtml
+7
-1
Create.cshtml
PhoneStore/Views/Orders/Create.cshtml
+40
-0
Index.cshtml
PhoneStore/Views/Orders/Index.cshtml
+33
-0
Index.cshtml
PhoneStore/Views/Phone/Index.cshtml
+12
-3
_Layout.cshtml
PhoneStore/Views/Shared/_Layout.cshtml
+3
-0
No files found.
PhoneStore/Controllers/HomeController.cs
View file @
320b1ea3
using
System.Diagnostics
;
using
System.IO
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.Extensions.Hosting
;
using
Microsoft.Extensions.Logging
;
using
PhoneStore.Models
;
...
...
@@ -8,10 +10,14 @@ namespace PhoneStore.Controllers
public
class
HomeController
:
Controller
{
private
readonly
ILogger
<
HomeController
>
_logger
;
private
readonly
IHostEnvironment
_environment
;
public
HomeController
(
ILogger
<
HomeController
>
logger
)
public
HomeController
(
ILogger
<
HomeController
>
logger
,
IHostEnvironment
environment
)
{
_logger
=
logger
;
_environment
=
environment
;
}
[
HttpGet
]
...
...
@@ -20,6 +26,66 @@ namespace PhoneStore.Controllers
return
View
();
}
// [HttpGet]
// public IActionResult Test()
// {
// string filePath = Path.Combine(_environment.ContentRootPath, "Files/test.pdf");
// string fileType = "application/pdf";
// string fileName = "test.pdf";
// return PhysicalFile(filePath, fileType, fileName);
// }
// [HttpGet]
// public IActionResult Test()
// {
// string filePath = Path.Combine(_environment.ContentRootPath, "Files/test.pdf");
// byte[] bytes = System.IO.File.ReadAllBytes(filePath);
// string fileType = "application/pdf";
// string fileName = "test.pdf";
// return File(bytes, fileType, fileName);
// }
// [HttpGet]
// public IActionResult Test()
// {
// string filePath = Path.Combine(_environment.ContentRootPath, "Files/test.pdf");
// byte[] bytes = System.IO.File.ReadAllBytes(filePath);
// string fileType = "application/pdf";
// string fileName = "test.pdf";
// return File(bytes, fileType, fileName);
// }
// [HttpGet]
// public IActionResult Test()
// {
// string filePath = Path.Combine(_environment.ContentRootPath, "Files/test.pdf");
// FileStream stream = new FileStream(filePath, FileMode.Open);
// string fileType = "application/pdf";
// string fileName = "test.pdf";
// return File(stream, fileType, fileName);
// }
[
HttpGet
]
public
IActionResult
Test
()
{
string
filePath
=
Path
.
Combine
(
"~/Files/"
,
"test.txt"
);
string
fileType
=
"application/txt"
;
return
File
(
filePath
,
fileType
);
}
[
HttpGet
]
[
ActionName
(
"Test2"
)]
public
string
Test
(
Phone
phone
)
{
return
"tets"
;
}
[
HttpGet
]
[
ActionName
(
"Test3"
)]
public
string
Test
(
Phone
[]
phones
)
{
return
"tets"
;
}
public
IActionResult
Privacy
()
{
return
View
();
...
...
PhoneStore/Controllers/OrdersController.cs
0 → 100644
View file @
320b1ea3
using
System.Linq
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.EntityFrameworkCore
;
using
PhoneStore.Models
;
namespace
PhoneStore.Controllers
{
public
class
OrdersController
:
Controller
{
private
readonly
MobileContext
_db
;
public
OrdersController
(
MobileContext
db
)
{
_db
=
db
;
}
// GET
public
IActionResult
Index
()
{
var
orders
=
_db
.
Orders
.
Include
(
p
=>
p
.
Phone
)
.
ToList
();
return
View
(
orders
);
}
[
HttpGet
]
public
IActionResult
Create
(
int
phoneId
)
{
var
phone
=
_db
.
Phones
.
FirstOrDefault
(
p
=>
p
.
Id
==
phoneId
);
if
(
phone
is
null
)
return
Content
(
"Такого телефона нет."
);
Order
order
=
new
Order
{
Phone
=
phone
};
return
View
(
order
);
}
[
HttpPost
]
public
IActionResult
Create
(
Order
order
)
{
_db
.
Orders
.
Add
(
order
);
_db
.
SaveChanges
();
return
RedirectToAction
(
"Index"
);
}
}
}
\ No newline at end of file
PhoneStore/PhoneStore.csproj
View file @
320b1ea3
...
...
@@ -12,4 +12,12 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.17" />
</ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="wwwroot\Files\book.pdf" />
</ItemGroup>
<ItemGroup>
<Folder Include="Pages" />
</ItemGroup>
</Project>
PhoneStore/Views/Home/Index.cshtml
View file @
320b1ea3
...
...
@@ -5,4 +5,10 @@
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>
\ No newline at end of file
</div>
<form asp-action="Test">
<input type="text" name="id" placeholder="id">
<input type="text" name="quantity" placeholder="quantity">
<button type="submit">Отправить</button>
</form>
\ No newline at end of file
PhoneStore/Views/Orders/Create.cshtml
0 → 100644
View file @
320b1ea3
@model Order
@{
ViewBag.Title = "Заказать смартфон";
Layout = "_Layout";
}
<h2>Заполните форму для заказа</h2>
<div class="row">
<div class="col-md-6">
<form asp-action="Create" asp-controller="Orders" method="post">
<div class="form-row">
<label for="">
Имя покупателя
<input asp-for="UserName" type="text">
</label>
</div>
<div class="form-row">
<label for="">
Адрес доставки
<input asp-for="Address" type="text">
</label>
</div>
<div class="form-row">
<label for="">
Номер телефона
<input asp-for="ContactPhone" type="text">
</label>
</div>
<div class="form-row">
<label for="">
Смартфон :
<input disabled type="text" value="@Model.Phone.Name">
</label>
<input asp-for="PhoneId" type="hidden" value="@Model.Phone.Id">
</div>
<button type="submit">Заказать</button>
</form>
</div>
</div>
PhoneStore/Views/Orders/Index.cshtml
0 → 100644
View file @
320b1ea3
@model List<Order>
@{
ViewBag.Title = "Список заказов";
Layout = "_Layout";
}
@if (Model.Count == 0)
{
<h2>Список пуст</h2>
}
else
{
<table style="width: 100%">
<tr>
<th>Id</th>
<th>Адрес</th>
<th>Контактный телефон</th>
<th>Имя пользователя</th>
<th>Название телефона</th>
</tr>
@foreach (var order in Model)
{
<tr>
<td>@order.Id</td>
<td>@order.Address</td>
<td>@order.ContactPhone</td>
<td>@order.UserName</td>
<td>@order.Phone.Name</td>
</tr>
}
</table>
}
PhoneStore/Views/Phone/Index.cshtml
View file @
320b1ea3
...
...
@@ -21,6 +21,7 @@ else
<th>Компания</th>
<th>Стоимость</th>
<th></th>
<th></th>
</tr>
@foreach (var phone in Model)
{
...
...
@@ -31,12 +32,20 @@ else
<td>@phone.Price</td>
<td>
<a asp-route-id="@phone.Id"
asp-action="Add"
asp-controller="Basket"
class="btn btn-outline-warning">
asp-action="Add"
asp-controller="Basket"
class="btn btn-outline-warning">
В корзину
</a>
</td>
<td>
<a asp-route-phoneId="@phone.Id"
asp-action="Create"
asp-controller="Orders"
class="btn btn-outline-warning">
Заказать
</a>
</td>
</tr>
}
</table>
...
...
PhoneStore/Views/Shared/_Layout.cshtml
View file @
320b1ea3
...
...
@@ -27,6 +27,9 @@
<li
class=
"nav-item"
>
<a
class=
"nav-link text-dark"
asp-area=
""
asp-controller=
"Phone"
asp-action=
"Index"
>
Смартфоны
</a>
</li>
<li
class=
"nav-item"
>
<a
class=
"nav-link text-dark"
asp-area=
""
asp-controller=
"Orders"
asp-action=
"Index"
>
Заказы
</a>
</li>
</ul>
</div>
</div>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment