Search code examples
asp.netasp.net-mvcperformanceasp.net-mvc-4membership

Asp Net MVC - Membership full update or Controller checking for better performance?


Mates, to update an user profile, if the user wants to update just a single detail, lets say an email in my controller I am doing this:

try
        {
            MembershipUser user = Membership.GetUser(model.UserName);

            user.Email = model.Email;
            user.IsApproved = model.Active;
            user.ChangePassword(model.Password, model.ConfirmPassword);

            string password = user.GetPassword();
            user.ChangePasswordQuestionAndAnswer(password, model.SecretQuestion, model.SecretQuestionPassword);

            Membership.UpdateUser(user);

            return Content("Usuário Atualizado com Sucesso!");

        }

The question is: Do I need to put some If conditions to check if other values is set, by cheking if the field is not disabled so I can change only the required collumn or it´s ok to perform a complete update as I have all the field with the values returned from database with its values?

I want a solution with a good performance and I don´t know if would be better to check all the fields or perform a complete update.

Could you please help me? Thanks


Solution

  • Thinking about performance in such a use case is a waste of time. Will your users massively update their emails, say... 1000 times a second? This is one of the features used almost never.

    Think about good design. Make meaningful methods. Optimize later, only if you have performance issues.