public ActionResult Edit(EditModel model)
 {
     if (ModelState.IsValid)
     {
         MembershipUser user = Membership.GetUser(model.UserName);
         user.Email = model.Email;
         Membership.UpdateUser(user);
         UserProfile profile = UserProfile.GetUserProfile(model.UserName);
         profile.FirstName = model.FirstName;
         profile.LastName = model.LastName;
         profile.CompanyId = model.CompanyId;
         profile.Phone = model.Phone;
         profile.Save();
         string[] roles = Roles.GetRolesForUser(model.UserName);
         if(roles.Length > 0)
         {
             Roles.RemoveUserFromRoles(model.UserName, roles);
         }
         if (model.SelectedRoles != null)
         {
             Roles.AddUserToRoles(model.UserName, model.SelectedRoles);
         }
         return RedirectToAction("Index");
     }
     else
     {
         return View(model);
     }
 }
 //
 // GET: /Users/Edit/5
 public ActionResult Edit(string id)
 {
     UserProfile profile = UserProfile.GetUserProfile(id);
     MembershipUser user = Membership.GetUser(id);
     var model = new EditModel
     {
         UserName = id,
         Email = user.Email,
         FirstName = profile.FirstName,
         LastName = profile.LastName,
         Phone = profile.Phone,
         CompanyId = profile.CompanyId
     };
     string[] allRoles = Roles.GetAllRoles();
     string[] userRoles = Roles.GetRolesForUser(id);
     model.SelectedRoles = userRoles;
     model.Roles = new MultiSelectList(allRoles, userRoles);
     var companies = CompaniesRepository.Get();
     ViewBag.Companies = new SelectList(companies, "CompanyId", "Name", model.CompanyId);
     return View(model);
 }