forked from VahidN/DNTCommon.Web.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUploadFileExtensionsController.cs
More file actions
39 lines (34 loc) · 1.19 KB
/
UploadFileExtensionsController.cs
File metadata and controls
39 lines (34 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.Threading.Tasks;
using DNTCommon.Web.Core.TestWebApp.Models;
using Microsoft.AspNetCore.Mvc;
namespace DNTCommon.Web.Core.TestWebApp.Controllers
{
public class UploadFileExtensionsController : Controller
{
private readonly IUploadFileService _uploadFileService;
public UploadFileExtensionsController(IUploadFileService uploadFileService)
{
_uploadFileService = uploadFileService;
}
public IActionResult Index()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> UploadPhoto(UserFileViewModel userViewModel)
{
if (ModelState.IsValid)
{
var formFile = userViewModel.Photo;
if (!await _uploadFileService.SavePostedFileAsync(formFile, destinationDirectoryName: "images", allowOverwrite: false))
{
ModelState.AddModelError("", "Uploaded file is null or empty.");
return View(viewName: "Index");
}
RedirectToAction("Index");
}
return View(viewName: "Index");
}
}
}