Contents tagged with MVC3 Razor
-
4 Year Anniversary Posting on Weblogs.Asp.Net!
On January 24th, 2012 I celebrate my 4th year of writing on this blog. I have written over 140 posts and have received over 700 comments.
-
ChangePassword Method for Entity Framework MVC3 Razor Custom Member Provider C# Using LINQ
From my C# MVC3 Razor Custom Membership Provider article and source code, here is the code for the ChangePassword method. I welcome any suggestions for improvement.
public override bool ChangePassword(string username, string oldPassword, string newPassword) { try { byte[] hashedNewPassword = HashPassword(newPassword.Trim()); byte[] hashedOldPassword = HashPassword(oldPassword.Trim()); using (var context = new SSSEntities()) { UserProfile u = context.UserProfiles .SingleOrDefault(up => up.UserName == username && up.UserPassword == hashedOldPassword); if (u != null) { u.UserPassword = hashedNewPassword; context.SaveChanges(); return true; } else return false; } } catch (InvalidOperationException ex) { throw ex; } catch (ArgumentException) { throw; } }
[SIGNATURE] -
GetUser Methods for Entity Framework MVC3 Razor Custom Member Provider C# Using LINQ
From my C# MVC3 Razor Custom Membership Provider article and source code, here is the code for the GetUser methods. I welcome any suggestions for improvement.
public override MembershipUser GetUser(object providerUserKey, bool userIsOnline) { using (var context = new SSSEntities()) { UserProfile u = context.UserProfiles .SingleOrDefault(up => up.UserId == Convert.ToInt32(providerUserKey)); MembershipUser membershipUser = GetMembershipUser(u); return membershipUser; } } public override MembershipUser GetUser(string username, bool userIsOnline) { using (var context = new SSSEntities()) { UserProfile u = context.UserProfiles .SingleOrDefault(up => up.UserName == username); MembershipUser membershipUser = GetMembershipUser(u); return membershipUser; } } // custom method to return a UserProfile public UserProfile GetUser(string username) { using (var context = new SSSEntities()) { UserProfile u = context.UserProfiles .SingleOrDefault(up => up.UserName == username); return u; } } // custom method to return a UserProfile public UserProfile GetUser(object providerUserKey) { using (var context = new SSSEntities()) { UserProfile u = context.UserProfiles .SingleOrDefault(up => up.UserId == Convert.ToInt32(providerUserKey)); return u; } }
[SIGNATURE] -
CreateUser Method for Entity Framework MVC3 Razor Custom Member Provider C# Using LINQ
From my C# MVC3 Razor Custom Membership Provider article and source code, here is the code for the CreateUser method. I welcome any suggestions for improvement.
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { // only first 3 fields are passed in from the AccountModels.cs try { status = UsernameExists(username); if (status == MembershipCreateStatus.DuplicateUserName) { return null; } status = DuplicateEmail(email); if (status == MembershipCreateStatus.DuplicateEmail) { return null; } byte[] hashedPassword = HashPassword(password.Trim()); GetValues gv = new GetValues(); string ipAddress = gv.getIPAddress(); int userStatus = Convert.ToInt32(SSS.GlobalListValues.Enums.UserStatusCode.Active); using (var context = new SSSEntities()) { UserProfile newUser = new UserProfile() { Email = email, UserPassword = hashedPassword, UserName = username, DateCreated = DateTime.Now, DateUpdated = DateTime.Now, DatePasswordLastChanged = DateTime.Now, DateLastLogin = DateTime.Now, UserStatusCode = userStatus, IpAddress = ipAddress, }; // insert the User Role int userRole = Convert.ToInt32(SSS.GlobalListValues.Enums.UserRoleCode.User_Public); // look up the desired user role : // uses a UserRole join table with a many to many relation // between the UserProfile table and the ListValue table ListValue ur = context.ListValues .SingleOrDefault(lv => lv.ListValueId == userRole); newUser.UserProfileUserRoles.Add(ur); context.UserProfiles.AddObject(newUser); context.SaveChanges(); // NKT: after creation, go back and retrieve the auto-generated identity key and // update the userId's for the created and updated userId int userId = newUser.UserId; newUser.CreatedUserId = userId; newUser.UpdatedUserId = userId; context.SaveChanges(); status = MembershipCreateStatus.Success; return GetMembershipUser(newUser); } } catch (ArgumentException) { status = MembershipCreateStatus.ProviderError; return null; } }
[SIGNATURE] -
DeleteUser Method for Entity Framework MVC3 Razor Custom Member Provider C# Using LINQ
From my C# MVC3 Razor Custom Membership Provider article and source code, here is the code for the DeleteUser method. I welcome any suggestions for improvement.
public override bool DeleteUser(string username, bool deleteAllRelatedData) { // deleteAllRelatedData not implemented try { using (var context = new SSSEntities()) { UserProfile u = context.UserProfiles .SingleOrDefault(up => up.UserName == username); context.UserProfiles.DeleteObject(u); context.SaveChanges(); return true; } } catch { return false; }
[SIGNATURE] -
C# MVC3 Razor Entity Framework & LINQ Custom Membership Provider with Custom Role Provider
This C# project demonstrates how to create an MVC3 Razor Entity Framework & LINQ Custom Membership Provider with Custom Role Provider. Perhaps you are working with a legacy database or you prefer working with a database that uses numeric identity keys instead of Guids. The example UserProfile table in this project uses an integer UserId as the primary key and various other fields that aren't in the default ASP.NET User table. Use the Log On Link in the project and the Register link to create your own account.
-
Installing Ajax Control Toolkit in Visual Studio 2010
I needed to install the Ajax Control Toolkit for Visual Studio 2010 4.0 Framework, so I googled "install ajax control toolkit visual studio 2010" and found this step by step guide:
-
Broken Styles and Loading Alternate Themes Dynamically
I decided to play around with the option of loading alternate themes dynamically. I found a few gotchas I'd like to share.
-
Guide to .NET Technical Interviewing
I am a strong believer of bringing your laptop to an interview and showing them what you have done. I believe that if a candidate is capable of doing some really great programming, they can easily fit into any aspect of development required. Just because a candidate has never done "xyz" before and can't tell you the difference between "xyzThis" and "xyzThat" doesn't mean they aren't able to quickly learn "xyz."
-
PLINQO LINQ to SQL and nHibernate ORM Code Generators
In my quest for the perfect Object Relational Mapper (ORM) for a major upcoming project utilizing SQL Server 2008, I was torn between using LINQ to SQL versus nHibernate.