public ActionResult EditProfile(Person person, string RadioGender, string Action)
        {
            Person CU = new Person();
            if (person.PersonID != Guid.Empty)
            {
                CU = reposetory.GetPersonComplete(person.PersonID);
                if (CU == null) return HttpNotFound();
            }

            //Check for a uniq username against database
            if (person.PersonID == Guid.Empty || person.UserName != CU.UserName)
            {
                if (String.IsNullOrWhiteSpace(person.UserName) | !reposetory.IsUserNameUniqe(person.UserName))
                {
                    string SuggestedUserName = person.UserName;
                    if (person.PersonID == Guid.Empty)
                    {
                        reposetory.GenerateUniqueUserName(person);
                        ModelState.SetModelValue("UserName", new ValueProviderResult(null, string.Empty, CultureInfo.InvariantCulture));
                        if (!String.IsNullOrWhiteSpace(SuggestedUserName)) ModelState.AddModelError("UserName", string.Format(DomainStrings.UserNameNotUniqueSuggestion, SuggestedUserName));
                    }
                    else
                    {
                        person.UserName = CU.UserName;
                        //ModelState.Clear();
                        ModelState.SetModelValue("UserName", new ValueProviderResult(null, string.Empty, CultureInfo.InvariantCulture));
                        ModelState.AddModelError("UserName", string.Format(DomainStrings.UserNameNotUnique, SuggestedUserName));
                    }

                }
            }
            if (RadioGender == "M") person.Gender = Gender.Man;
            if (RadioGender == "F") person.Gender = Gender.Woman;
            person.Trim();
            if (CU.MailUndeliverable && (
                CU.FirstName != person.FirstName |
                CU.FamilyName != person.FamilyName |
                CU.Address != person.Address |
                CU.City != person.City |
                CU.Zip != person.Zip
                ))
            {
                CU.MailUndeliverable = false;
                CU.MailUndeliverableDate = null;
            }
            CU.UserName = person.UserName;
            CU.FirstName = person.FirstName;
            CU.FamilyName = person.FamilyName;
            CU.Address = person.Address;
            CU.City = person.City;
            CU.Zip = person.Zip;
            CU.Email = person.Email;
            CU.Country = person.Country;
            CU.Mobile = person.Mobile;
            CU.Phone = person.Phone;
            //CU.BasicTrainingDate = person.BasicTrainingDate;
            CU.BirthDate = person.BirthDate;
            CU.EmailNewsLetter = person.EmailNewsLetter;
            CU.PrintNewslettet = person.PrintNewslettet;
            CU.Gender = person.Gender;
            CU.ProfileInfo = person.ProfileInfo;
            //CU.Note = person.Note;
            //CU.SeniorInstructor = person.SeniorInstructor;



            if (ModelState.IsValid)
            {
                var refresh = person.PersonID == Guid.Empty;
                reposetory.SavePerson(CU);
                ViewBag.FormSucces = true;
                CurrentProfile.Clear();
                //if (refresh) return RedirectToAction("Edit", new { ID = CU.PersonID.ToString() });
            }
            //if (CU.Memberships == null) CU.Memberships = new List<NRMembership>();


            return View(CU);
        }
        public static Person ConvertPerson(SqlDataReader reader, Country country)
        {
            var personen = new Person();
            personen.PersonID = (Guid)reader["UserId"];
            personen.Email = reader["Email"] == DBNull.Value ? "" : ((String)reader["Email"]);
            personen.UserName = ((String)reader["UserName"]);
            personen.Password = reader["Password"] == DBNull.Value ? "" : (String)reader["Password"];
            personen.FirstName = ReturnProperty("Fornavn", (string)reader["PropertyNames"], (string)reader["PropertyValuesString"]);
            personen.FamilyName = ReturnProperty("Efternavn", (string)reader["PropertyNames"], (string)reader["PropertyValuesString"]);
            personen.Address = ReturnProperty("Vej", (string)reader["PropertyNames"], (string)reader["PropertyValuesString"]);
            personen.City = ReturnProperty("By", (string)reader["PropertyNames"], (string)reader["PropertyValuesString"]);
            personen.Zip = ReturnProperty("Postnr", (string)reader["PropertyNames"], (string)reader["PropertyValuesString"]);
            personen.Phone = ReturnProperty("Telefon", (string)reader["PropertyNames"], (string)reader["PropertyValuesString"]);
            personen.Mobile = ReturnProperty("Mobil", (string)reader["PropertyNames"], (string)reader["PropertyValuesString"]);
            String Koen = ReturnProperty("gender", (string)reader["PropertyNames"], (string)reader["PropertyValuesString"]);
            personen.Created = (DateTime)reader["CreateDate"];

            personen.Gender = Gender.NotDefined;
            if (Koen == "K") personen.Gender = Gender.Woman;
            if (Koen == "M") personen.Gender = Gender.Man;
            personen.Trim();

            personen.Country = country;
            if (string.IsNullOrWhiteSpace(personen.Phone) | personen.Phone.Length < 8) personen.Phone = String.Empty;
            if (string.IsNullOrWhiteSpace(personen.Mobile) | personen.Mobile.Length < 8) personen.Mobile = String.Empty;
            if (personen.Address.Length < 2) personen.Address = "  ";
            if (personen.Address.Length > 70) personen.Address = personen.Address.Substring(0, 70);
            if (personen.City.Length < 2) personen.City = "  ";
            if (personen.Zip.Length < 2) personen.Zip = "  ";
            if (personen.FirstName.Length < 2) personen.FirstName = "**";
            if (personen.FamilyName.Length < 2) personen.FamilyName = "**";

            if (personen.UserName.Length > 10 || Regex.Replace(personen.UserName, @"[^A-Z0-9ÆØÅ]", "") != personen.UserName || WebSecurity.GetUserId(personen.UserName) > 0)
                GenerateUniqUsername(personen);

            if (!string.IsNullOrEmpty(personen.Email) && !Regex.IsMatch(personen.Email, @"^(['\""]{1,}.+['\""]{1,}\s+)?<?[\w\.\-]+@([\w\-]+\.)+[A-Za-z]{2,}>?$"))
                personen.Email = "";

            var results = new List<ValidationResult>();
            var context = new ValidationContext(personen, null, null);
            if (!Validator.TryValidateObject(personen, context, results))
            {
                foreach (ValidationResult res in results)
                {
                    System.Diagnostics.Debug.WriteLine("ModelFaileur: " + res.ErrorMessage);

                }
            }

            return personen;
        }
        public ActionResult Edit(Person person, string RadioGender, string Action, Guid Attach)
        {
            Person CU = new Person();
            if (person.PersonID != Guid.Empty)
            {
                CU = reposetory.GetPersonComplete(person.PersonID);
                if (CU == null) return RedirectToAction("Index");
            }

            //Check for a uniq username against database
            if (person.PersonID == Guid.Empty || person.UserName != CU.UserName)
            {
                if (String.IsNullOrWhiteSpace(person.UserName) | !reposetory.IsUserNameUniqe(person.UserName))
                {
                    string SuggestedUserName = person.UserName;
                    if (person.PersonID == Guid.Empty)
                    {
                        reposetory.GenerateUniqueUserName(person);
                        ModelState.SetModelValue("UserName", new ValueProviderResult(null, string.Empty, CultureInfo.InvariantCulture));
                        if (!String.IsNullOrWhiteSpace(SuggestedUserName)) ModelState.AddModelError("UserName", string.Format(DomainStrings.UserNameNotUniqueSuggestion, SuggestedUserName));
                    }
                    else
                    {
                        person.UserName = CU.UserName;
                        //ModelState.Clear();
                        ModelState.SetModelValue("UserName", new ValueProviderResult(null, string.Empty, CultureInfo.InvariantCulture));
                        ModelState.AddModelError("UserName", string.Format(DomainStrings.UserNameNotUnique, SuggestedUserName));
                    }

                }
            }
            if (RadioGender == "M") person.Gender = Gender.Man;
            if (RadioGender == "F") person.Gender = Gender.Woman;
            person.Trim();
            if (CU.MailUndeliverable && (
                CU.FirstName != person.FirstName |
                CU.FamilyName != person.FamilyName |
                CU.Address != person.Address |
                CU.City != person.City |
                CU.Zip != person.Zip
                ))
            {
                CU.MailUndeliverable = false;
                CU.MailUndeliverableDate = null;
            }
            CU.UserName = person.UserName;
            CU.FirstName = person.FirstName;
            CU.FamilyName = person.FamilyName;
            CU.Address = person.Address;
            CU.City = person.City;
            CU.Zip = person.Zip;
            CU.Email = person.Email;
            CU.Country = person.Country;
            CU.Mobile = person.Mobile;
            CU.Phone = person.Phone;
            CU.BasicTrainingDate = person.BasicTrainingDate;
            CU.BirthDate = person.BirthDate;
            CU.EmailNewsLetter = person.EmailNewsLetter;
            CU.PrintNewslettet = person.PrintNewslettet;
            CU.Gender = person.Gender;
            CU.Note = person.Note;
            CU.SeniorInstructor = person.SeniorInstructor;

            if (String.IsNullOrWhiteSpace(CU.Password)) CU.Password = String.Empty.GeneratePassword();

            List<AssociationListModel> tmp = reposetory.GetAssociationList(); //.RemoveAll(item => CU.Memberships.ToList().Exists(p => p.Association.AssociationID == item.AssociationID));
            ViewBag.Attach = new SelectList(tmp, "AssociationID", "Name");

            if (Action == "add" && Attach != Guid.Empty)
            {
                Association association = reposetory.GetAssociation(Attach);
                if (association != null && association.Status == AssociationStatus.Active)
                {
                    NR.Models.NRMembership Mem = new NR.Models.NRMembership
                    {
                        Association = association,
                        SignupDate = DateTime.Now,
                        Type = PersonType.Active
                    };
                    CU.Memberships.Add(Mem);
                    reposetory.SavePerson(CU);
                    ModelState.Clear();
                }

            }


            if (Action == "Edit" & ModelState.IsValid)
            {
                var refresh = person.PersonID == Guid.Empty;
                reposetory.SavePerson(CU);
                if (refresh)
                {
                    //WebSecurity.IsConfirmed 
                    if (!WebSecurity.IsConfirmed(CU.UserName)) WebSecurity.CreateAccount(CU.UserName, CU.Password);
                    if (!string.IsNullOrWhiteSpace(CU.Email))
                    {
                        var mail = new WelcomeMailEmail
                        {
                            To = CU.Email,
                            UserName = CU.UserName,
                            Password = CU.Password
                        };
                        mail.Send();
                    }
                }
                ViewBag.FormSucces = true;
                ModelState.Clear();
            }
            if (CU.Memberships == null) CU.Memberships = new List<NR.Models.NRMembership>();

            if (CU.Causes == null) CU.Causes = new List<CausePartisipant>();
            return View(CU);
        }