Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
lesson60
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
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
Нурбек Созоев
lesson60
Commits
37433489
Commit
37433489
authored
Jun 03, 2019
by
Нурбек Созоев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил считывание с файла
parent
d3e8bf8d
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
42 deletions
+58
-42
ProductController.cs
Store/Controllers/ProductController.cs
+15
-34
CreateProduct.cshtml
Store/Views/Product/CreateProduct.cshtml
+37
-0
Details.cshtml
Store/Views/Product/Details.cshtml
+4
-6
Index.cshtml
Store/Views/Product/Index.cshtml
+2
-2
No files found.
Store/Controllers/ProductController.cs
View file @
37433489
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
Microsoft.AspNetCore.Mvc
;
using
Store.Models
;
...
...
@@ -7,45 +6,26 @@ namespace Store.Controllers
{
public
class
ProductController
:
Controller
{
public
IActionResult
Index
()
{
List
<
Product
>
products
=
new
List
<
Product
>
{
new
Product
{
Id
=
Guid
.
NewGuid
().
ToString
(),
Name
=
"Asus A234"
,
Amount
=
100
,
Brand
=
"Asus"
,
Category
=
"TV"
},
new
Product
private
ProductContext
_context
;
public
ProductController
(
ProductContext
context
)
{
Id
=
Guid
.
NewGuid
().
ToString
(),
Name
=
"Asus A674"
,
Amount
=
150
,
Brand
=
"Asus"
,
Category
=
"TV"
_context
=
context
;
}
};
ViewBag
.
products
=
products
;
return
View
();
public
IActionResult
Index
()
{
return
View
(
_context
.
Products
);
}
public
IActionResult
Details
(
string
id
)
{
return
View
(
new
Product
{
Id
=
Guid
.
NewGuid
().
ToString
(),
Name
=
"Asus A674"
,
Amount
=
150
,
Brand
=
"Asus"
,
Category
=
"TV"
});
Product
product
=
_context
.
Products
.
FirstOrDefault
(
p
=>
p
.
Id
==
id
);
ViewBag
.
product
=
product
;
return
View
();
}
[
ActionName
(
"CreateProduct"
)]
[
HttpGet
]
public
IActionResult
Create
()
{
...
...
@@ -55,7 +35,8 @@ namespace Store.Controllers
[
HttpPost
]
public
IActionResult
Create
(
Product
product
)
{
_context
.
Products
.
Add
(
product
);
_context
.
SaveChanges
();
return
View
(
"Details"
,
product
);
}
}
...
...
Store/Views/Product/Create.cshtml
→
Store/Views/Product/Create
Product
.cshtml
View file @
37433489
@model Store.Models.Product
@{
Layout = "_MainLayout";
}
...
...
@@ -8,22 +9,27 @@
<form action="/Product/Create" method="post" >
<div class="form-group">
<label for="">Name</label>
<input type="text" class="form-control"
id="Name" name="Name"
placeholder="Enter name">
<input type="text" class="form-control"
value="@Model.Name" id="Name" name="Name"
placeholder="Enter name">
</div>
<div class="form-group">
<label for="">Category</label>
<input type="text" class="form-control" id="Category" name="Category" placeholder="Enter category">
<input type="text" class="form-control"
value="@Model.Category"
id="Category" name="Category" placeholder="Enter category">
</div>
<div class="form-group">
<label for="">Brand</label>
<input type="text" class="form-control" id="Brand" name="Brand" placeholder="Enter brand">
<input type="text" class="form-control"
value="@Model.Brand"
id="Brand" name="Brand" placeholder="Enter brand">
</div>
<div class="form-group">
<label for="">Amount</label>
<input type="text" class="form-control" id="Amount" name="Amount" placeholder="Enter amount">
<input type="text" class="form-control" value="@Model.Amount" id="Amount" name="Amount" placeholder="Enter amount">
</div>
<div class="form-group">
<label for="">Description</label>
<input type="text" class="form-control" value="@Model.Description" id="Description" name="Description" placeholder="Enter amount">
</div>
<button type="submit" class="btn btn-primary">Create</button>
...
...
Store/Views/Product/Details.cshtml
View file @
37433489
@model Store.Models.Product
@{
Layout = "_MainLayout";
}
...
...
@@ -9,19 +7,19 @@
<tbody>
<tr>
<td>Name:</td>
<td>@
Model
.Name</td>
<td>@
ViewBag.product
.Name</td>
</tr>
<tr>
<td>Category:</td>
<td>@
Model
.Category</td>
<td>@
ViewBag.product
.Category</td>
</tr>
<tr>
<td>Brand:</td>
<td>@
Model
.Brand</td>
<td>@
ViewBag.product
.Brand</td>
</tr>
<tr>
<td>Amount:</td>
<td>@
Model
.Amount</td>
<td>@
ViewBag.product
.Amount</td>
</tr>
</tbody>
</table>
Store/Views/Product/Index.cshtml
View file @
37433489
@using Store.Models
@model IEnumerable<Store.Models.Product>
@{
Layout = "_MainLayout";
}
...
...
@@ -19,7 +19,7 @@
</tr>
</thead>
<tbody>
@foreach (Product product in
ViewBag.products
)
@foreach (Product product in
Model
)
{
<tr>
<th scope="row">@product.Id</th>
...
...
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