85 lines
2.7 KiB
C#
85 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using Microsoft.AspNet.Identity;
|
|
using Microsoft.AspNet.Identity.EntityFramework;
|
|
using Weee.Models;
|
|
using Weee.Areas.Certification.Models;
|
|
using Weee.DAL;
|
|
using Resources;
|
|
|
|
namespace Weee.Areas.Certification.Controllers
|
|
{
|
|
public class AccountController : CertificationControllerBase
|
|
{
|
|
private readonly UserManager<User> userManager;
|
|
private readonly UserStore<User> userStore;
|
|
//private WeeeDataContext _db;
|
|
|
|
public AccountController(WeeeDataContext db)
|
|
:base(db)
|
|
{
|
|
userManager = DependencyResolver.Current.GetService<UserManager<User>>();
|
|
userStore = DependencyResolver.Current.GetService<UserStore<User>>();
|
|
//_db = new WeeeDataContext();
|
|
}
|
|
|
|
public ActionResult ChangePassword()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult ChangePassword(ChangePassword changePassword)
|
|
{
|
|
if (ModelState.IsValid) {
|
|
var user = userManager.Find(User.Identity.GetUserName(), changePassword.OriginalPassword);
|
|
|
|
if (user == null) {
|
|
ViewBag.PasswordIsInvalid = Resource.InvalidPasswordMsg;
|
|
return View();
|
|
}
|
|
|
|
var hashed = userManager.PasswordHasher.HashPassword(changePassword.NewPassword);
|
|
userStore.SetPasswordHashAsync(user, hashed).Wait();
|
|
userStore.UpdateAsync(user).Wait();
|
|
|
|
return RedirectToAction("Index", "Home");
|
|
}
|
|
|
|
return View();
|
|
}
|
|
|
|
public ActionResult UpdateCompanyInfo()
|
|
{
|
|
var userId = User.Identity.GetUserId();
|
|
var user = db.Users.Where(x => x.Id == userId).First();
|
|
var company = user.Company;
|
|
return View(company);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult UpdateCompanyInfo(CertificationCompany toBeSave)
|
|
{
|
|
var userId = User.Identity.GetUserId();
|
|
var user = db.Users.Where(x => x.Id == userId).First();
|
|
var company = user.Company;
|
|
|
|
if (ModelState.IsValid)
|
|
{
|
|
company.Name = toBeSave.Name;
|
|
company.EnglishName = toBeSave.EnglishName;
|
|
company.Address = toBeSave.Address;
|
|
company.VATNumber = toBeSave.VATNumber;
|
|
company.CEOName = toBeSave.CEOName;
|
|
company.IndustryDescription = toBeSave.IndustryDescription;
|
|
company.Description = toBeSave.Description;
|
|
db.SaveChanges();
|
|
}
|
|
|
|
return View(company);
|
|
}
|
|
}
|
|
} |