IMembershipService.CreateUser does not update data

Topics: Writing modules
Apr 23, 2012 at 3:48 PM

Hi,

I want to create a extend user from UserPartRecord.

I have a error: Let review my code.

// create user of orchard
var user = _membershipService.CreateUser(new CreateUserParams(createModel.UserName, createModel.Password, createModel.Email, null, null, true));
dynamic model = Services.ContentManager.UpdateEditor(user.ContentItem, this);
                   

// create customer
_customerService.CreateCustomer(createModel);

 

When excute  

var user = _membershipService.CreateUser(new CreateUserParams(createModel.UserName, createModel.Password, createModel.Email, null, null, true));

A user have been created. But it has not been stored in database.
If I remove  the line
_customerService.CreateCustomer(createModel);
data will be store.

Please give me some advices,
Thanks

Coordinator
Apr 23, 2012 at 4:02 PM

Having absolutely no clue what CreateCustomer is doing, I don't think one can guess.

Apr 23, 2012 at 5:07 PM

I found this error.

After it excute the funtion _membershipService.CreateUser, the real data is not yet created in database. The function CreateCustomer try to find the newest user to create model Customer. So it throw a error.

Do you have any solutions to create real data after excute the function CreateUser ?

Developer
Apr 23, 2012 at 5:20 PM
Edited Apr 23, 2012 at 5:20 PM

Why don't you just pass in the created 'user' into your 'CreateCustomer' method? That way, you don't need to look for the newest user (which is probably a bad idea anyway, as in between requests, another user could have been created).

Apr 24, 2012 at 12:00 AM

I know that.

The scenario is customization standard user of orchard.

This is Customer model:

public class Customer
    {
        public virtual int Id { get; set; }
        
        public virtual string FirstName { get; set; }
        public virtual string LastName {get; set;}
        public virtual string PhoneNumber {get; set;}
        public virtual string PhoneNumberExtentions { get; set; }

        public virtual UserPartRecord UserPartRecord { get; set; }

        public virtual IEnumerable<Job> Jobs { get; set; }
    }

Currently, I create user by funtion _membershipService.CreateUser then get ID (UserPardRecord) to create customer.

I just wanted to know the way to create real data in database after it excute funtion _membershipService.CreateUser.

Thanks,

Coordinator
Apr 24, 2012 at 12:14 AM

Don't do that. Users are content items for a reason: so that you can extend them by composition, like everything else in Orchard. Add parts instead.

Apr 24, 2012 at 6:58 AM

Our system need 2 user types: Customer and Courier.

Wich user type, it has another informations.

Can we extend user standar to resolve that?

Please give me more explanation!

Thanks,

Coordinator
Apr 24, 2012 at 7:30 AM

Sure. You could have a part that has a property that holds the info whether it's a customer or courier, and/or you could attach one part or the other from a handler depending on the type of user, etc.

Apr 25, 2012 at 12:59 AM

I'll try it.

Thanks,