Skip to content

Commit

Permalink
Implement DropZone for Mult Image Upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Rebwar Hosain Poori authored and Rebwar Hosain Poori committed May 8, 2019
1 parent 2310197 commit e2be40a
Show file tree
Hide file tree
Showing 39 changed files with 3,830 additions and 34 deletions.
1 change: 1 addition & 0 deletions HelpDesk.Domain.Contracts/Articles/IArticleRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace HelpDesk.Domain.Contracts.Articles
{
public interface IArticleRepository: IBaseRepository<Article>
{
int GetArticlesCountInCategory(int id);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ namespace HelpDesk.InfraStructures.DataAccess.Articles
{
public class ArticleRepository : BaseRepository<Article>, IArticleRepository
{
private readonly HelpDeskContext context;
public ArticleRepository(HelpDeskContext dbcontext) : base(dbcontext)
{
this.context = dbcontext;
}
public int GetArticlesCountInCategory(int id)
{
return context.Articles.Where(c => c.CategoryId == id).Count();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public CategoryRepository(HelpDeskContext dbcontext) : base(dbcontext)
this._dbcontext = dbcontext;
}


public List<Category> SearchCategory(string search)
{
return _dbcontext.Categories.Where(c => c.Name.Contains(search)).ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class HelpDeskDbContextFactory : IDesignTimeDbContextFactory<HelpDeskCont
public HelpDeskContext CreateDbContext(string[] args)
{
var builder = new DbContextOptionsBuilder<HelpDeskContext>();
builder.UseSqlServer(@"Server= .;Initial Catalog=HelpDesk;Integrated security=true");
builder.UseSqlServer(@"Server=(localdb)\ProjectsV13;Initial Catalog=HelpDesk;Integrated security=true");
return new HelpDeskContext(builder.Options);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="dropzone" Version="4.3.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.4">
<PrivateAssets>all</PrivateAssets>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 60 additions & 1 deletion HelpDesk.MVC/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using HelpDesk.Domain.Contracts.Articles;
Expand All @@ -13,6 +14,7 @@
using HelpDesk.MVC.Models.categories;
using MD.PersianDateTime;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using static System.Net.Mime.MediaTypeNames;

Expand Down Expand Up @@ -55,7 +57,8 @@ public IActionResult AddCategory(AddNewCategory model)
public IActionResult ListCat()
{
var cat = categoryRepository.GetAll().ToList();
return View(cat);
// ViewData["ArticlesCount"] = articleRepository.GetArticlesCountInCategory()
return View(cat);
}
public IActionResult ListArticle()
{
Expand Down Expand Up @@ -111,6 +114,35 @@ public IActionResult AddArticle()
cat.CatForDisplay = categoryRepository.GetAll().ToList();
return View(cat);
}
public void MultiUpload()
{

}
[HttpPost]

public async Task<IActionResult> UploadFilesAjax(AddNewArticleGetViewModel model)
{
long uploaded_size = 0;
string path_for_Uploaded_Files = _hostingEnvironment.WebRootPath + "\\Images\\Multi\\";
var uploaded_files = Request.Form.Files;
int iCounter = 0;
string sFiles_uploaded = "";
foreach (var uploaded_file in uploaded_files)
{
iCounter++;
uploaded_size += uploaded_file.Length;
sFiles_uploaded += "\n" + uploaded_file.FileName;
string uploaded_Filename = uploaded_file.FileName;
string new_Filename_on_Server = path_for_Uploaded_Files + "\\" + uploaded_Filename;

using (FileStream stream = new FileStream(new_Filename_on_Server, FileMode.Create))
{
await model.Image.CopyToAsync(stream);
}
}
string message = "Upload successful!\n files uploaded:" + iCounter + "\nsize:" + uploaded_size + "\n" + sFiles_uploaded;
return Json("oops");
}
[HttpPost]
public async Task<IActionResult> AddArticle(AddNewArticleGetViewModel model)
{
Expand Down Expand Up @@ -220,5 +252,32 @@ public IActionResult ArticleDetails(int id)
}

}
public IActionResult Upload(int id)
{
var article = articleRepository.Get(id);
if (article == null)
{
return BadRequest();
}
else
{
Article model = new Article();
model.Title = article.Title;
return View(model);
}
}
[HttpPost]
public async Task<IActionResult> Upload(IFormFile file,Article article)
{
var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "Images\\Multi");
if (file.Length > 0)
{
using (var fileStream = new FileStream(Path.Combine(uploads, file.FileName), FileMode.Create))
{
await file.CopyToAsync(fileStream);
}
}
return RedirectToAction("Index");
}
}
}
11 changes: 9 additions & 2 deletions HelpDesk.MVC/HelpDesk.MVC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>

<ItemGroup>
<Compile Remove="wwwroot\NewFolder1\**" />
<Content Remove="wwwroot\NewFolder1\**" />
<EmbeddedResource Remove="wwwroot\NewFolder1\**" />
<None Remove="wwwroot\NewFolder1\**" />
</ItemGroup>

<ItemGroup>
<None Include="wwwroot\js\site.js" />
</ItemGroup>


<ItemGroup>
<PackageReference Include="dropzone" Version="4.3.0" />
<PackageReference Include="MD.PersianDateTime" Version="3.8.3" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
Expand All @@ -33,8 +41,7 @@

<ItemGroup>
<Folder Include="Views\Shared\Admin\" />
<Folder Include="wwwroot\NewFolder1\" />
<Folder Include="wwwroot\NewFolder\" />
<Folder Include="wwwroot\Images\Multi\" />
</ItemGroup>

</Project>
16 changes: 13 additions & 3 deletions HelpDesk.MVC/Views/Admin/AddArticle.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
{
<link href="~/css/bootstrap3-wysihtml5.min.css" rel="stylesheet" />
<link href="~/css/select2.min.css" rel="stylesheet" />
<style>
.inputfield_upload {
display: block;
visibility: hidden;
width: 0;
height: 0;
}
</style>
}
<section class="content-header">
<h1>
Expand Down Expand Up @@ -67,7 +76,10 @@
<input type="file" asp-for="Image" class="form-control-" />
</div>
</div>

<div class="form-group">
<input type="file" id="files_input_field" name="files" multiple class="inputfield_upload" onchange="upload_files();" />
<input type="button" id="select_and_upload_button" value="Upload Photos.." />
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
Expand All @@ -94,10 +106,8 @@
relative_urls: false,
toolbar: 'undo redo | removeformat preview code | fontsizeselect bullist numlist | alignleft aligncenter alignright alignjustify | bold italic | pagebreak table link',
});
</script>


}


4 changes: 2 additions & 2 deletions HelpDesk.MVC/Views/Admin/ListArticle.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
</td>

<td>
<a asp-controller="Admin" asp-action="ArticleDetails" asp-route-id="@item.Id" class="btn btn-default" data-id="@item.Id"><i class="fa fa-edit"></i>جزئیات </a>

<a asp-controller="Admin" asp-action="ArticleDetails" asp-route-id="@item.Id" class="btn btn-default" data-id="@item.Id"><i class="fa fa-book"></i>جزئیات </a>
<a asp-controller="Admin" asp-action="upload" asp-route-id="@item.Id" class="btn btn-success" data-id="@item.Id"><i class="fa fa-image"></i> عکس سه بعدی </a>
<a asp-controller="Admin" asp-action="EditArticle" asp-route-id="@item.Id" class="btn btn-primary" data-id="@item.Id"><i class="fa fa-edit"></i>ویرایش </a>
<a class="btn btn-danger deleteArticle" data-id="@item.Id" data-controller="Admin" data-action="deletearticle" data-body-message="برای حذف این مطلب مطمئن هستید؟"><i class="fa fa-trash"></i> حذف</a>
</td>
Expand Down
63 changes: 63 additions & 0 deletions HelpDesk.MVC/Views/Admin/Upload.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
@model HelpDesk.Domain.Core.Articles.Article
@{
ViewData["Title"] = "Upload";
Layout = "~/Views/Admin/_Layout.cshtml";
}
@section text_editor
{
<link href="~/vendor/dropzone/dropzone.min.css" rel="stylesheet" />
<script src="~/vendor/dropzone/dropzone.min.js"></script>
}
<section class="content-header">
<h1>
<small>ساخت حالت سه بعدی عکس</small>
</h1>
<ol class="breadcrumb">
<li><a asp-action="Index" asp-controller="Admin"><i class="fa fa-dashboard"></i> داشبورد</a></li>
</ol>
</section>

<section class="content">
<div class="row">
<div class="col-md-9">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title"> درج عکس جهت ساخت حالت سه بعدی برای</h3>
<h4 class="box-title"> @Model.Title</h4>
</div>
<div class="box-body">
<div class="form-group">
<div id="dropzone">
<form action="/Admin/Upload" class="dropzone needsclick dz-clickable" id="uploader">
<div class="dz-message needsclick">
جهت آپلود دسته ای ، عکسها را اینجا درگ کنید یا کلیک کنید<br>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
@section Tiny_Mce
{
<script>
$(document).ready(function () {
Dropzone.options.uploader = {
paramName: "file",
maxFiles: 3,
maxFilesize: 2,
accept: function (file, done) {
if (file.name == "test.jpg") {
alert("Can't upload a test file.");
}
else {
}
}
};
});
</script>
}

1 change: 1 addition & 0 deletions HelpDesk.MVC/Views/Admin/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@
</body>
@RenderSection("Tiny_Mce", false)


</html>
3 changes: 1 addition & 2 deletions HelpDesk.MVC/Views/Admin/articleDetails.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
ViewData["Title"] = "articleDetails";
Layout = "~/Views/Admin/_Layout.cshtml";
}

<section class="content-header">
<h1>
<small>جزئیات مطلب @Model.Title</small>
Expand All @@ -30,7 +29,7 @@
<p>@Model.Title</p>
</div>
<div class="form-group">
<img class="img-bordered-sm img-bordered-sm" src="@Model.Image" asp-append-version="true" />
<img class="img-bordered-sm" style="max-width:50%" src="@Model.Image" asp-append-version="true" />


</div>
Expand Down
2 changes: 1 addition & 1 deletion HelpDesk.MVC/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<!-- RTL CSS -->
<link rel="stylesheet" href="~/css/rtl.css">
@RenderSection("autocomplete_css", false)

@RenderSection("Article_Detail_css",false)
<title>Pars Help Desk سیستم پشتیبانی شرکت پارس</title>
</head>
<body>
Expand Down
Loading

0 comments on commit e2be40a

Please sign in to comment.