Skip to content

Commit

Permalink
[Added] user can now change profile picture or avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
nobir committed Jul 20, 2022
1 parent a0de91e commit 7213d45
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Controllers/DashboardController.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ERPSystemTimologio.Auth;
using ERPSystemTimologio.EF;
using ERPSystemTimologio.Models;

namespace ERPSystemTimologio.Controllers
{
[LoggedIn]
public class DashboardController : Controller
{
private readonly TimologioEntities db = new TimologioEntities();

// GET: Dashboard
public ActionResult Index()
{
Expand All @@ -20,5 +25,41 @@ public ActionResult ViewProfile()
{
return View();
}

[HttpGet]
public ActionResult ProfilePicture()
{
return View();
}

[HttpPost]
public ActionResult ProfilePicture(HttpPostedFileBase Avatar)
{
var pp = new ProfilePicture
{
Filesize = 1024 // 1mb
};

var message = pp.Upload(Avatar, ((User)Session["user"]).Username.ToString());

if(message != null)
{
TempData["error_message"] = message;
return View();
}

var userId = ((User)Session["user"]).Id;
var user = this.db.Users.Where(u => u.Id == userId).SingleOrDefault();

user.Avatar = user.Username.ToString() + "." + Path.GetExtension(Avatar.FileName).Substring(1);

this.db.SaveChanges();

Session["user"] = user;

TempData["success_message"] = "Successfully Uploaded";

return View();
}
}
}

0 comments on commit 7213d45

Please sign in to comment.