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
c784e08b
Commit
c784e08b
authored
Jun 30, 2022
by
TTrueBenji
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавить Action About.
*** - Добавил Action About. - Убрал вызов излишнего метода Include. ***
#1
parent
ea32df3f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
9 deletions
+26
-9
PhonesController.cs
PhoneStore/Controllers/PhonesController.cs
+18
-9
About.cshtml
PhoneStore/Views/Phones/About.cshtml
+8
-0
No files found.
PhoneStore/Controllers/PhonesController.cs
View file @
c784e08b
...
@@ -27,18 +27,13 @@ namespace PhoneStore.Controllers
...
@@ -27,18 +27,13 @@ namespace PhoneStore.Controllers
_environment
=
environment
;
_environment
=
environment
;
_uploadService
=
uploadService
;
_uploadService
=
uploadService
;
}
}
/// <summary>
/// Действие, которое возвращает страницу со списком смартфонов
/// </summary>
/// <returns></returns>
[
HttpGet
]
[
HttpGet
]
public
IActionResult
Index
(
int
?
brandId
,
string
name
)
public
IActionResult
Index
(
int
?
brandId
,
string
name
)
{
{
IEnumerable
<
Brand
>
brands
=
_db
.
Brands
;
IQueryable
<
Phone
>
phones
=
_db
.
Phones
IQueryable
<
Phone
>
phones
=
_db
.
Phones
.
Include
(
p
=>
p
.
Brand
)
.
AsQueryable
();
.
AsQueryable
();
IEnumerable
<
Brand
>
brands
=
_db
.
Brands
;
if
(
brandId
is
>
0
)
if
(
brandId
is
>
0
)
phones
=
_db
.
Phones
.
Where
(
p
=>
p
.
BrandId
==
brandId
);
phones
=
_db
.
Phones
.
Where
(
p
=>
p
.
BrandId
==
brandId
);
...
@@ -106,6 +101,7 @@ namespace PhoneStore.Controllers
...
@@ -106,6 +101,7 @@ namespace PhoneStore.Controllers
[
HttpGet
]
[
HttpGet
]
public
IActionResult
Edit
(
int
phoneId
)
public
IActionResult
Edit
(
int
phoneId
)
{
{
var
brands
=
_db
.
Brands
.
ToList
();
var
phone
=
_db
.
Phones
.
FirstOrDefault
(
p
=>
p
.
Id
==
phoneId
);
var
phone
=
_db
.
Phones
.
FirstOrDefault
(
p
=>
p
.
Id
==
phoneId
);
if
(
phone
is
null
)
if
(
phone
is
null
)
{
{
...
@@ -117,7 +113,7 @@ namespace PhoneStore.Controllers
...
@@ -117,7 +113,7 @@ namespace PhoneStore.Controllers
Name
=
phone
.
Name
,
Name
=
phone
.
Name
,
Price
=
phone
.
Price
,
Price
=
phone
.
Price
,
BrandId
=
(
int
)
phone
.
BrandId
,
BrandId
=
(
int
)
phone
.
BrandId
,
Brands
=
_db
.
Brands
.
ToList
()
Brands
=
brands
};
};
return
View
(
model
);
return
View
(
model
);
}
}
...
@@ -151,5 +147,18 @@ namespace PhoneStore.Controllers
...
@@ -151,5 +147,18 @@ namespace PhoneStore.Controllers
return
Ok
(
"Файл успешно загружен"
);
return
Ok
(
"Файл успешно загружен"
);
}
}
[
HttpGet
]
public
IActionResult
About
(
int
?
id
)
{
if
(!
id
.
HasValue
)
return
RedirectToAction
(
"Error"
,
"Errors"
,
new
{
statusCode
=
777
});
var
phone
=
_db
.
Phones
.
Include
(
p
=>
p
.
Brand
)
.
FirstOrDefault
(
p
=>
p
.
Id
==
id
);
if
(
phone
is
null
)
return
RedirectToAction
(
"Error"
,
"Errors"
,
new
{
statusCode
=
777
});
return
View
(
phone
);
}
}
}
}
}
\ No newline at end of file
PhoneStore/Views/Phones/About.cshtml
0 → 100644
View file @
c784e08b
@model Phone
@{
ViewBag.Title = "Подробная информация";
Layout = "_Layout";
}
<h2>@Model.Name</h2>
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