-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Added] added ProfilePicture model and view
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Web; | ||
using System.Web.UI; | ||
|
||
namespace ERPSystemTimologio.Models | ||
{ | ||
public class ProfilePicture | ||
{ | ||
public string ErrorMessage { get; set; } | ||
public decimal Filesize { get; set; } | ||
public string Upload(HttpPostedFileBase file, string username) | ||
{ | ||
try | ||
{ | ||
var supportFileType = new[] { "jpg", "jpeg", "png", "gif" }; | ||
var getFileExtension = Path.GetExtension(file.FileName).Substring(1); | ||
|
||
if (!supportFileType.Contains(getFileExtension)) | ||
{ | ||
ErrorMessage = "File must be jpg/jpeg/png/gif format"; | ||
return ErrorMessage; | ||
} | ||
else if (file.ContentLength > (Filesize * 1024)) | ||
{ | ||
ErrorMessage = "File size must be less than " + Filesize + "KB"; | ||
return ErrorMessage; | ||
} | ||
|
||
string _path = Path.Combine(HttpContext.Current.Server.MapPath("~/Content/images/avatar"), username + "." + getFileExtension); | ||
file.SaveAs(_path); | ||
|
||
return null; | ||
} | ||
catch (Exception) | ||
{ | ||
ErrorMessage = "Upload Container Should Not Be Empty"; | ||
return ErrorMessage; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
@{ | ||
ViewBag.Title = "ProfilePicture"; | ||
|
||
ERPSystemTimologio.EF.User sessionUser = null; | ||
|
||
if (Session["user"] != null) | ||
{ | ||
sessionUser = (ERPSystemTimologio.EF.User)Session["user"]; | ||
} | ||
} | ||
|
||
<form action="@Url.Action("ProfilePicture", "Dashboard")" method="POST" enctype="multipart/form-data"> | ||
<div class="card text-center"> | ||
<div class="card-body"> | ||
<div class="row mb-3 has-validation"> | ||
<label for="avatar" class="col-sm-3 col-form-label">Avatar</label> | ||
<div class="col-sm-9"> | ||
<div class="custom-file"> | ||
<input type="file" | ||
class="custom-file-input form-control @(!ViewData.ModelState.IsValidField("Avatar") ? "is-invalid" : "")" id="avatar" | ||
name="Avatar"> | ||
<label class="custom-file-label" for="avatar">Choose file</label> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="row mb-3"> | ||
<div class="col-sm-9 offset-sm-3"> | ||
<button id="avatar-upload-btn" type="submit" class="btn btn-success">Upload</button> | ||
</div> | ||
</div> | ||
</div> | ||
@if (sessionUser != null && sessionUser.Avatar != null) | ||
{ | ||
<div class="card-footer"> | ||
<img src="@Url.Content("~/Content/images/"+sessionUser.Avatar.ToString())" class="img-thumbnail rounded mx-auto d-block" alt="@sessionUser.Name"> | ||
</div> | ||
} | ||
</div> | ||
</form> |