Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
W
webinar62
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
Нурбек Созоев
webinar62
Commits
fa702ff1
Commit
fa702ff1
authored
Jun 15, 2019
by
Нурбек Созоев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил логику загрузки файла (или аватарки Person)
parent
9ad3dc36
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
4 deletions
+82
-4
PersonController.cs
MyCities/Controllers/PersonController.cs
+20
-1
PersonCreateViewModel.cs
MyCities/ViewModels/PersonCreateViewModel.cs
+41
-0
Create.cshtml
MyCities/Views/Home/Create.cshtml
+0
-3
Create.cshtml
MyCities/Views/Person/Create.cshtml
+21
-0
No files found.
MyCities/Controllers/PersonController.cs
View file @
fa702ff1
using
System.IO
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
using
MyCities.Models
;
using
MyCities.Repositories
;
using
MyCities.Repositories
;
using
MyCities.ViewModels
;
namespace
MyCities.Controllers
namespace
MyCities.Controllers
{
{
...
@@ -12,10 +15,26 @@ namespace MyCities.Controllers
...
@@ -12,10 +15,26 @@ namespace MyCities.Controllers
_repository
=
repository
;
_repository
=
repository
;
}
}
// GET
public
IActionResult
Index
()
public
IActionResult
Index
()
{
{
return
View
(
_repository
.
Persons
);
return
View
(
_repository
.
Persons
);
}
}
[
HttpGet
]
public
IActionResult
Create
()
{
return
View
();
}
[
HttpPost
]
public
IActionResult
Create
(
PersonCreateViewModel
viewModel
)
{
using
(
var
stream
=
new
FileStream
(
viewModel
.
GetFilePath
(),
FileMode
.
Create
))
{
viewModel
.
Avatar
.
CopyTo
(
stream
);
}
_repository
.
Add
(
viewModel
.
GetPerson
());
return
RedirectToAction
(
"Index"
);
}
}
}
}
}
MyCities/ViewModels/PersonCreateViewModel.cs
0 → 100644
View file @
fa702ff1
using
System.IO
;
using
Microsoft.AspNetCore.Http
;
using
MyCities.Models
;
namespace
MyCities.ViewModels
{
public
class
PersonCreateViewModel
{
public
string
FullName
{
get
;
set
;
}
public
string
NickName
{
get
;
set
;
}
public
IFormFile
Avatar
{
get
;
set
;
}
public
string
GetFilePath
()
{
return
Path
.
Combine
(
Directory
.
GetCurrentDirectory
(),
"wwwroot"
,
"images"
,
Avatar
.
FileName
);
}
public
string
GetAvatarImagePath
()
{
return
Path
.
Combine
(
"images"
,
Avatar
.
FileName
);
}
public
Person
GetPerson
()
{
return
new
Person
{
FullName
=
FullName
,
NickName
=
NickName
,
AvatarImagePath
=
GetAvatarImagePath
()
};
}
}
}
MyCities/Views/Home/Create.cshtml
View file @
fa702ff1
...
@@ -19,7 +19,4 @@
...
@@ -19,7 +19,4 @@
</div>
</div>
<button type="submit" hlp-color="primary">Create</button>
<button type="submit" hlp-color="primary">Create</button>
<mysuperbtn></mysuperbtn>
<button type="submit" class="btn btn-primary">Clear</button>
<a asp-controller="Home" asp-actoin="Index" class="btn btn-primary">Cancel</a>
</form>
</form>
MyCities/Views/Person/Create.cshtml
0 → 100644
View file @
fa702ff1
@{
Layout = "_Layout";
}
<form asp-controller="Person" asp-action="Create" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="FullName">FullName:</label>
<input class="form-control" name="FullName"/>
</div>
<div class="form-group">
<label for="Nickname">Nickname:</label>
<input class="form-control" name="Nickname"/>
</div>
<div class="form-group">
<label for="Avatar">Avatar</label>
<input type="file" class="form-control-file" name="Avatar">
</div>
<button type="submit" hlp-color="primary">Create</button>
</form>
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