Browse Source

Fixed issue where entity object was being used twice in the same scope.

master
Teknikode 7 years ago
parent
commit
9edb326304
  1. 6
      Teknik/Areas/Profile/Controllers/ProfileController.cs
  2. 8
      Teknik/Areas/Profile/Utility/UserHelper.cs

6
Teknik/Areas/Profile/Controllers/ProfileController.cs

@ -191,7 +191,7 @@ namespace Teknik.Areas.Profile.Controllers @@ -191,7 +191,7 @@ namespace Teknik.Areas.Profile.Controllers
{
if (Config.UserConfig.RegistrationEnabled)
{
if (Utility.UserHelper.UserExists(model.Username))
if (Utility.UserHelper.UserExists(db, model.Username))
{
return Json(new { error = "That username already exists." });
}
@ -276,7 +276,7 @@ namespace Teknik.Areas.Profile.Controllers @@ -276,7 +276,7 @@ namespace Teknik.Areas.Profile.Controllers
{
if (ModelState.IsValid)
{
User user = Utility.UserHelper.GetUser(User.Identity.Name);
User user = Utility.UserHelper.GetUser(db, User.Identity.Name);
if (user != null)
{
string email = string.Format("{0}@{1}", User.Identity.Name, Config.EmailConfig.Domain);
@ -428,7 +428,7 @@ namespace Teknik.Areas.Profile.Controllers @@ -428,7 +428,7 @@ namespace Teknik.Areas.Profile.Controllers
}
// Delete User
User user = Utility.UserHelper.GetUser(User.Identity.Name);
User user = Utility.UserHelper.GetUser(db, User.Identity.Name);
if (user != null)
{
user.UserSettings = db.UserSettings.Find(user.UserId);

8
Teknik/Areas/Profile/Utility/UserHelper.cs

@ -13,18 +13,16 @@ namespace Teknik.Areas.Profile.Utility @@ -13,18 +13,16 @@ namespace Teknik.Areas.Profile.Utility
{
public static class UserHelper
{
public static User GetUser(string username)
public static User GetUser(TeknikEntities db, string username)
{
TeknikEntities db = new TeknikEntities();
User user = db.Users.Where(b => b.Username == username).FirstOrDefault();
return user;
}
public static bool UserExists(string username)
public static bool UserExists(TeknikEntities db, string username)
{
User user = GetUser(username);
User user = GetUser(db, username);
if (user != null)
{
return true;

Loading…
Cancel
Save