public Courier <AppUser> EditUser(AddUpdateUserParcel parcel) { Courier <AppUser> courier = new Courier <AppUser>(); var cursor = userMgr.FindById(parcel.Target.Id); cursor.FirstName = parcel.FirstName; cursor.LastName = parcel.LastName; cursor.Email = parcel.Email; cursor.UserName = parcel.UserName; cursor.PasswordHash = userMgr.PasswordHasher.HashPassword(parcel.Password); var roles = cursor.Roles; if (roles.Count == 1) { var role = roleMgr.FindById(roles.First().RoleId); userMgr.RemoveFromRole(cursor.Id, role.Name); } var result = userMgr.Update(cursor); userMgr.AddToRole(cursor.Id, parcel.RoleName); courier.Success = result.Succeeded; courier.Message = ""; foreach (var e in result.Errors) { courier.Message += "ERROR : " + e + ". "; } courier.Package = cursor; return(courier); }
public Courier <AppUser> CreateNewUser(AddUpdateUserParcel parcel) { Courier <AppUser> courier = new Courier <AppUser>(); var user = new AppUser() { FirstName = parcel.FirstName, LastName = parcel.LastName, Email = parcel.Email, UserName = parcel.UserName }; userMgr.Create(user, parcel.Password); userMgr.AddToRole(user.Id, parcel.RoleName); courier.Package = userMgr.Find(user.UserName, parcel.Password); if (courier.Package != null && courier.Package.UserName == parcel.UserName && courier.Package.Email == parcel.Email && courier.Package.FirstName == parcel.FirstName && courier.Package.LastName == parcel.LastName) { courier.Success = true; } else { courier.Success = false; courier.Message = "There was an issue adding the user to the database."; } return(courier); }