public ActionResult Edit(Guid?ID) { NR.Models.NRMembership CU; if (ID == null) { CU = new NR.Models.NRMembership { Association = reposetory.GetAssociation(CurrentProfile.AssociationID), SignupDate = DateTime.Now, Type = PersonType.Active, Person = new Person { Country = Country.DK } }; //CU.Person = new Person(); } else { CU = reposetory.GetMembership((Guid)ID); if (CU == null) { return(HttpNotFound()); } } return(View(CU)); }
public ActionResult CreatePerson(Guid ID) { Lead dbLead = new Lead(); dbLead = reposetory.GetLead(ID); if (dbLead == null) { return(RedirectToAction("Index")); } NRMembership CU = new NR.Models.NRMembership { Association = reposetory.GetAssociation(CurrentProfile.AssociationID), SignupDate = DateTime.Now, Type = PersonType.Active, Person = new Person { Country = Country.DK, FirstName = dbLead.FirstName, FamilyName = dbLead.FamilyName, Address = dbLead.Address, Zip = dbLead.Zip, City = dbLead.City, Phone = dbLead.Phone, Mobile = dbLead.Mobile } }; return(View("../People/edit", CU)); }
public ActionResult _UploadCSV(HttpPostedFileBase file, Guid id, string Forening) { if (file != null) { string line; Dictionary<string, string> ProfilImages = new Dictionary<string, string>(); ProfilDirSetting = Server.MapPath(Url.Content(ConfigurationManager.AppSettings["ProfileImage"])); var Memberships = new List<NRMembership>(); List<String[]> Data = new List<String[]>(); //FileStream aFile = new FileStream("../../sportsResults.csv", FileMode.Open); StreamReader sr = new StreamReader(file.InputStream, Encoding.GetEncoding(1252)); // read data in line by line string header = sr.ReadLine(); if (!header.StartsWith(@"""ID"";""Forening (R)"";""Username"";""Password"";""Indmeldt"";""Fodselsdag"";""Fornavn"";""Efternavn"";""Adresse"";""Postnr"";""By"";""Email"";""Mobil"";""Telefon"";""Notat"";""Aktiv"";""Udmeldt"";""Udmeldt"";""Ønsker IKKE Natteravnenyt"";""Idkort"";""Førstehjælp"";""Grunduddannelse"";""Billede"";""Login"";""Netværk"";""Login"";""Funktioner"";")) return Json(new { success = false, errorMessage = "Ikke korrekt header" }); Data.Add(header.Split(';')); while ((line = sr.ReadLine()) != null) { while (!line.Trim().EndsWith("\";")) { line += sr.ReadLine(); } var AvivaData = line.Split(';'); for (int t = 0; t < AvivaData.Length; t++) { AvivaData[t] = AvivaData[t].TrimStart('"').TrimEnd('"'); } if (AvivaData.Length > 15 & (Forening == string.Empty | Forening == AvivaData[1])) { Data.Add(AvivaData); DateTime OutDate; var membership = new NRMembership { Person = new Person() }; int Avivaid; if (int.TryParse(AvivaData[0].Trim(), out Avivaid)) membership.Person.IDWEB = Avivaid; membership.Person.UserName = AvivaData[2] + new Guid().ToString(); membership.Person.Password = AvivaData[3]; if (DateTime.TryParse(AvivaData[4], out OutDate)) membership.SignupDate = OutDate; if (DateTime.TryParse(AvivaData[5], out OutDate)) membership.Person.BirthDate = OutDate; membership.Person.FirstName = AvivaData[6]; membership.Person.FamilyName = AvivaData[7]; membership.Person.Address = AvivaData[8]; membership.Person.Zip = AvivaData[9]; membership.Person.City = AvivaData[10]; membership.Person.Email = AvivaData[11]; membership.Person.Mobile = AvivaData[12]; membership.Person.Phone = AvivaData[13]; membership.Note = AvivaData[14]; membership.Type = AvivaData[15].Contains("x") ? PersonType.Active : PersonType.Passiv; if (AvivaData[16].Contains("x")) membership.AbsentDate = DateTime.Now; if (AvivaData[18].Contains("x")) membership.Person.PrintNewslettet = false; if (AvivaData[26].Contains("Holdleder")) membership.Teamleader = true; if (AvivaData[26].Contains("Administrator")) membership.Secretary = true; if (AvivaData[26].Contains("Formand")) membership.BoardFunction = BoardFunctionType.BoardMember; if (AvivaData[26].Contains("Næstformand")) membership.BoardFunction = BoardFunctionType.BoardMember; if (AvivaData[26].Contains("Kasserer")) membership.BoardFunction = BoardFunctionType.Accountant; if (AvivaData[26].Contains("Sekretær")) membership.BoardFunction = BoardFunctionType.BoardMember; if (AvivaData[26].Contains("Bestyrelses medlem")) membership.BoardFunction = BoardFunctionType.BoardMember; if (AvivaData[26].Contains("Suppleant")) membership.BoardFunction = BoardFunctionType.Alternate; if (AvivaData[26].Contains("Revisor")) membership.BoardFunction = BoardFunctionType.Auditor; if (AvivaData[26].Contains("Revisor Suppleant")) membership.BoardFunction = BoardFunctionType.AuditorAlternate; membership.Person.Gender = Gender.NotDefined; membership.Person.Trim(); if (!string.IsNullOrWhiteSpace(membership.Person.FullName) & !string.IsNullOrWhiteSpace(membership.Person.Mobile) & !string.IsNullOrWhiteSpace(membership.Person.Email) ) { membership.Person.Country = Country.DK; if (string.IsNullOrWhiteSpace(membership.Person.Phone) | membership.Person.Phone.Length < 8) membership.Person.Phone = String.Empty; if (string.IsNullOrWhiteSpace(membership.Person.Mobile) | membership.Person.Mobile.Length < 8) membership.Person.Mobile = String.Empty; if (membership.Person.Address.Length < 2) membership.Person.Address = " "; if (membership.Person.Address.Length > 70) membership.Person.Address = membership.Person.Address.Substring(0, 70); if (membership.Person.City.Length < 2) membership.Person.City = " "; if (membership.Person.Zip.Length < 2) membership.Person.Zip = " "; if (membership.Person.FirstName.Length < 2) membership.Person.FirstName = "**"; if (membership.Person.FamilyName.Length < 2) membership.Person.FamilyName = "**"; if (membership.Person.UserName.Length > 10 || Regex.Replace(membership.Person.UserName, @"[^A-Z0-9ÆØÅ]", "") != membership.Person.UserName || WebSecurity.GetUserId(membership.Person.UserName) > 0) GenerateUniqUsername(membership.Person); if (!string.IsNullOrEmpty(membership.Person.Email) && !Regex.IsMatch(membership.Person.Email, @"^\S+@\S+\.\S+$")) membership.Person.Email = ""; if (membership.Person.UserName.Length < 3) GenerateUniqUsername(membership.Person); if (Regex.IsMatch(membership.Person.Password, @"^[a-zA-Z0-9æøåÆØÅ*!#%&]{6,10}$")) membership.Person.Password.GeneratePassword(); Memberships.Add(membership); if (AvivaData[22].Contains("media/")) { ProfilImages.Add(membership.Person.UserName, AvivaData[22]); } } } //line = sr.ReadLine(); } sr.Close(); string HtmlData = "<table border=\"1\">"; foreach (var ld in Data) { HtmlData += "<tr>"; foreach (string str in ld) { HtmlData += "<td>" + str + "</td>"; } HtmlData += "</tr>"; } HtmlData += "</table>"; using (var context = new Repository()) { Association association = context.Associations.Find(id); foreach (var M in Memberships) { M.AssociationID = association.AssociationID; context.Entry(M).State = EntityState.Added; try { context.SaveChanges(); if (!M.Absent) //&& !WebSecurity.UserExists(m.Person.UserName)) { WebSecurity.CreateAccount(M.Person.UserName, M.Person.Password); //if (WebSecurity.ConfirmAccount(M.Person.UserName)) //{ // System.Diagnostics.Debug.WriteLine("**Migrating Person: \"" + M.Person.UserName + "\" / (" + M.Person.Password + ")"); //} } string ImagePath; if (ProfilImages.TryGetValue(M.Person.UserName, out ImagePath)) { var img = DownloadImageFromUrl(string.Format("http://www.natteravnene.dk/aviva/{0}", ImagePath)); if (img != null) { string newFileName = string.Format(ProfilDirSetting, M.Person.PersonID.ToString()); string newFileLocation = newFileName; if (Directory.Exists(Path.GetDirectoryName(newFileLocation)) == false) { Directory.CreateDirectory(Path.GetDirectoryName(newFileLocation)); } img.Save(newFileLocation); //progress += " - Image transferred"; } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(string.Format("{0} Exception caught.", e)); } } } return Json(new { success = true, data = HtmlData }); } return Json(new { success = false, errorMessage = "Tjaa... Fejl" }); }
public static Association ExtractAssociation(int id) { Dictionary<int, Guid> Assdictionary = new Dictionary<int, Guid>(); Dictionary<string, string> UserNamedictionary = new Dictionary<string, string>(); Dictionary<int, String> Locationdictionary = new Dictionary<int, String>(); Random random = new Random(); Association association = null; //Get Association using (SqlConnection cn = new SqlConnection(seedConnectionString)) { SqlCommand cmd = new SqlCommand("SELECT * FROM [Foreninger] WHERE ForeningsID = " + id.ToString(), cn); cmd.CommandType = CommandType.Text; cn.Open(); var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); while ((reader.Read())) { association = ConvertAssociation(reader); association.UseSchedulePlanning = true; association.PageSponsor = new NR.Models.Content { Title = DefaultForening.PageContentSponsorTitle, Body = DefaultForening.PageContentSponsor }; association.PageAbout = new NR.Models.Content { Title = DefaultForening.PageContentAboutTitle, Body = DefaultForening.PageContentAbout }; association.PagePress = new NR.Models.Content { Title = DefaultForening.PageContentPressTitle, Body = DefaultForening.PageContentPress }; association.PageLink = new NR.Models.Content { Title = DefaultForening.PageContentLinkTitle, Body = DefaultForening.PageContentLink }; Assdictionary.Add((int)reader["ForeningsID"], association.AssociationID); } } //Get persons association.Memberships = new List<NRMembership>(); using (SqlConnection cn = new SqlConnection(seedConnectionString)) { SqlCommand cmd = new SqlCommand(@"SELECT [Ravnetur].[dbo].[aspnet_Users].[UserId] ,[UserName] ,[Email] ,[Password] ,[PropertyNames] ,[PropertyValuesString] ,[LastActivityDate] ,[CreateDate] ,(SELECT CAST(1 AS BIT) AS Expr1 FROM [Ravnetur].[dbo].[aspnet_UsersInRoles] WHERE ([Ravnetur].[dbo].[aspnet_UsersInRoles].UserId = [Ravnetur].[dbo].[aspnet_Users].UserId AND [Ravnetur].[dbo].[aspnet_UsersInRoles].RoleId = 'ED1CAE67-880D-4EC0-A00F-81DD0A191749')) as [Planner] FROM [Ravnetur].[dbo].[aspnet_Users] LEFT JOIN [Ravnetur].[dbo].[aspnet_Profile] ON [Ravnetur].[dbo].[aspnet_Users].UserId = [Ravnetur].[dbo].[aspnet_Profile].UserId LEFT JOIN [Ravnetur].[dbo].[aspnet_Membership] ON [Ravnetur].[dbo].[aspnet_Users].UserId = [Ravnetur].[dbo].[aspnet_Membership].UserId;", cn); cmd.CommandType = CommandType.Text; cn.Open(); var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); while ((reader.Read())) { if (reader["PropertyValuesString"] != null & !Convert.IsDBNull(reader["PropertyValuesString"])) { string StrId = ReturnProperty("ForeningsID", (string)reader["PropertyNames"], (string)reader["PropertyValuesString"]); if (StrId != String.Empty && Convert.ToInt32(StrId) == id) { Person person = ConvertPerson(reader, association.Country); List<NRMembership> ms = association.Memberships.ToList(); var ExistUser = from UN in ms where UN.Person.UserName == person.UserName select UN; if (ExistUser.Any()) { char ch; for (int i = 0; i < 2; i++) { ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))); person.UserName = person.UserName + ch.ToString(); } } UserNamedictionary.Add((String)reader["UserName"], person.UserName); NRMembership membership = new NRMembership(); if (ReturnProperty("Udmeldt", (string)reader["PropertyNames"], (string)reader["PropertyValuesString"]) == "True") membership.AbsentDate = DateTime.Now; membership.Teamleader = ReturnProperty("TurLeder", (string)reader["PropertyNames"], (string)reader["PropertyValuesString"]) == "True" ? true : false; membership.BoardFunction = BoardFunctionType.none; membership.SignupDate = DateTime.Now; membership.Type = PersonType.Active; membership.SignupDate = person.Created; membership.Person = person; //membership.Association = association; if (reader["Planner"] != null & !Convert.IsDBNull(reader["Planner"])) membership.Planner = true; //person.Memberships.Add(membership); association.Memberships.Add(membership); //person.CurrentAssociation = association.AssociationID; //association.People.Add(person); } } } } //Get locations association.Locations = new List<Location>(); using (SqlConnection cn = new SqlConnection(seedConnectionString)) { SqlCommand cmd = new SqlCommand("SELECT * FROM [Lokationer] WHERE ForeningsID = " + id.ToString(), cn); cmd.CommandType = CommandType.Text; cn.Open(); var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); while ((reader.Read())) { Location location = ConvertLocation(reader); if (!String.IsNullOrWhiteSpace(location.Name.Replace(".", ""))) { association.Locations.Add(location); Locationdictionary.Add((int)TjekDBNull(reader["LokID"]), location.ShortName); } } } if (!association.Locations.Any()) { Location location = new Location { Name = association.Name, ShortName = "STD", Description = "Standard lokationen for forningen" }; association.Locations.Add(location); } //Get Folders association.Folders = new List<Folder>(); using (SqlConnection cn = new SqlConnection(seedConnectionString)) { SqlCommand cmd = new SqlCommand("SELECT * FROM [TurMapper] WHERE ForeningsID = " + id.ToString(), cn); cmd.CommandType = CommandType.Text; cn.Open(); var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); while ((reader.Read())) { Folder folder = ConvertFolder(reader); folder.Start = folder.Start.Date; folder.Finish = folder.Finish.Date.AddDays(1).AddSeconds(-1); int TurmappeID = (int)TjekDBNull(reader["TurMappeID"]); folder.Teams = new List<Team>(); using (SqlConnection cn1 = new SqlConnection(seedConnectionString)) { SqlCommand cmd1 = new SqlCommand("SELECT * FROM [Turer] WHERE TurmappeID = " + TurmappeID.ToString(), cn1); cmd1.CommandType = CommandType.Text; cn1.Open(); var reader1 = cmd1.ExecuteReader(CommandBehavior.CloseConnection); while ((reader1.Read())) { Team team = new Team { Start = (DateTime)reader1["Start"], Note = (String)TjekDBNull(reader1["Note"]), Created = (DateTime)reader1["Oprettet"], Lastchanged = (DateTime)reader1["SidstRettet"], Association = association, Teammembers = new List<Person>() }; if (String.IsNullOrWhiteSpace(team.Note)) team.Note = null; string Dur = (String)reader1["Tid"]; TimeSpan DurT; if (TimeSpan.TryParse(Dur, out DurT)) { team.Duration = DurT; } switch ((String)reader1["Status"]) { case "OK": team.Status = TeamStatus.OK; break; case "Aflyst": team.Status = TeamStatus.Cancelled; break; case "Nedlagt": team.Status = TeamStatus.Droped; break; default: team.Status = TeamStatus.Planned; break; } //UserNamedictionary String UserName; if (UserNamedictionary.TryGetValue((String)reader1["TurlederID"], out UserName)) { Person TL = association.Memberships.Where(m => m.Person.UserName == UserName).Select(m => m.Person).FirstOrDefault(); team.Teammembers.Add(TL); team.TeamLeaderId = TL.PersonID; } if (UserNamedictionary.TryGetValue((String)reader1["Ravn1ID"], out UserName)) { team.Teammembers.Add(association.Memberships.Where(m => m.Person.UserName == UserName).Select(m => m.Person).FirstOrDefault()); } if (UserNamedictionary.TryGetValue((String)reader1["Ravn2ID"], out UserName)) { team.Teammembers.Add(association.Memberships.Where(m => m.Person.UserName == UserName).Select(m => m.Person).FirstOrDefault()); } else if ((String)reader1["Ravn2ID"] == "PRØVETUR") { team.Trial = true; } string Loc; if (Locationdictionary.Any() && TjekDBNull(reader1["Lokation"]) != null && Locationdictionary.TryGetValue((int)reader1["Lokation"], out Loc)) { team.Location = association.Locations.Where(l => l.ShortName == Loc).FirstOrDefault(); } else { team.Location = association.Locations.Where(l => l.ShortName == "STD").FirstOrDefault(); } folder.Teams.Add(team); } } association.Folders.Add(folder); } } return association; }
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)); }
public ActionResult Edit(NRMembership Membership, string RadioGender, string Action) { NRMembership CU = new NR.Models.NRMembership { AssociationID = CurrentProfile.AssociationID, SignupDate = DateTime.Now, Type = PersonType.Active }; CU.Person = new Person(); if (Membership.MembershipID != Guid.Empty) { CU = reposetory.GetMembership(Membership.MembershipID); if (CU == null) { return(HttpNotFound()); } } //Check for a uniq username against database if (Membership.Person.PersonID == Guid.Empty || (Membership.Person.UserName != CU.Person.UserName)) { if (String.IsNullOrWhiteSpace(Membership.Person.UserName) | !reposetory.IsUserNameUniqe(Membership.Person.UserName)) { string SuggestedUserName = Membership.Person.UserName; if (Membership.Person.PersonID == Guid.Empty) { reposetory.GenerateUniqueUserName(Membership.Person); ModelState.SetModelValue("Person.UserName", new ValueProviderResult(Membership.Person.UserName, Membership.Person.UserName.ToString(), CultureInfo.InvariantCulture)); if (!String.IsNullOrWhiteSpace(SuggestedUserName)) { ModelState.AddModelError("Person.UserName", string.Format(DomainStrings.UserNameNotUniqueSuggestion, SuggestedUserName)); } } else { Membership.Person.UserName = CU.Person.UserName; //ModelState.Clear(); ModelState.SetModelValue("Person.UserName", new ValueProviderResult(Membership.Person.UserName, Membership.Person.UserName.ToString(), CultureInfo.InvariantCulture)); ModelState.AddModelError("Person.UserName", string.Format(DomainStrings.UserNameNotUnique, SuggestedUserName)); } } } if (RadioGender == "M") { Membership.Person.Gender = Gender.Man; } if (RadioGender == "F") { Membership.Person.Gender = Gender.Woman; } Membership.Person.Trim(); if (CU.Person.MailUndeliverable && ( CU.Person.FirstName != Membership.Person.FirstName | CU.Person.FamilyName != Membership.Person.FamilyName | CU.Person.Address != Membership.Person.Address | CU.Person.City != Membership.Person.City | CU.Person.Zip != Membership.Person.Zip )) { CU.Person.MailUndeliverable = false; CU.Person.MailUndeliverableDate = null; } CU.Person.UserName = Membership.Person.UserName; CU.Type = Membership.Type; CU.Person.FirstName = Membership.Person.FirstName; CU.Person.FamilyName = Membership.Person.FamilyName; CU.Person.Address = Membership.Person.Address; CU.Person.City = Membership.Person.City; CU.Person.Zip = Membership.Person.Zip; CU.Person.Email = Membership.Person.Email; CU.SignupDate = Membership.SignupDate; CU.Person.Country = Membership.Person.Country; CU.Person.Mobile = Membership.Person.Mobile; CU.Person.Phone = Membership.Person.Phone; CU.Person.BasicTrainingDate = Membership.Person.BasicTrainingDate; CU.Person.BirthDate = Membership.Person.BirthDate; CU.Person.EmailNewsLetter = Membership.Person.EmailNewsLetter; CU.Person.PrintNewslettet = Membership.Person.PrintNewslettet; CU.Person.Gender = Membership.Person.Gender; CU.Teamleader = Membership.Teamleader; CU.Note = Membership.Note; if (String.IsNullOrWhiteSpace(CU.Person.Password)) { CU.Person.Password = String.Empty.GeneratePassword(); } if (ModelState.IsValid) { var refresh = Membership.Person.PersonID == Guid.Empty; reposetory.SavePerson(CU); //TODO: Remove Websecurity account if status is changed from Active if (refresh) { //ensure that form i updated if resubmit of form i done //ModelState.SetModelValue("MembershipID", new ValueProviderResult(CU.MembershipID, CU.MembershipID.ToString(), CultureInfo.InvariantCulture)); //ModelState.SetModelValue("Person.PersonID", new ValueProviderResult(CU.Person.PersonID, CU.Person.PersonID.ToString(), CultureInfo.InvariantCulture)); //Create Websecurity Memebership if account is active if (CU.Type == PersonType.Active) { if (!WebSecurity.IsConfirmed(CU.Person.UserName)) { WebSecurity.CreateAccount(CU.Person.UserName, CU.Person.Password); } //Send Welcome mail if user has an E-mail if (!String.IsNullOrWhiteSpace(CU.Person.Email)) { var mail = new WelcomeMailEmail { To = CU.Person.Email, UserName = CU.Person.UserName, Password = CU.Person.Password }; mail.Send(); } else if (!String.IsNullOrWhiteSpace(CU.Person.Mobile)) { Association association = reposetory.GetAssociation(CU.Person.CurrentAssociation); #if DUMMYTEXT ITextMessage SMSGateway = TextServiceProviderFactory.GetTextServiceProviderrInstance("NR.Infrastructure.DummyTextGateway", association == null ? null : association.TextServiceProviderUserName, association == null ? null : association.TextServiceProviderPassword); #else ITextMessage SMSGateway = TextServiceProviderFactory.GetTextServiceProviderrInstance(association.TextServiceProvider, association == null ? null : association.TextServiceProviderUserName, association == null ? null : association.TextServiceProviderPassword); #endif SMSGateway.FromText = General.SystemTextMessagesFrom; SMSGateway.Message = String.Format(General.SystemTextMessagesWelcome, CU.Person.UserName, CU.Person.Password); SMSGateway.Recipient = new List <Person> { CU.Person }; if (association != null) { reposetory.NewTextMessage(SMSGateway, association.AssociationID); SMSGateway.HandShakeUrl = Url.Action("TextXStatus", "Account", new { ID = SMSGateway.TextId }, "http"); } if (SMSGateway.Send()) { } ; } Notification not = reposetory.Notify(CU.Person, String.Format(Notifications.NewPerson, CU.Person.FullName)); reposetory.NotifyAddAdministration(not); reposetory.NotifyAddAssociation(not, CU.AssociationID); reposetory.NotifySave(not); } } ModelState.Clear(); ViewBag.FormSucces = true; return(View(CU)); } return(View(Membership)); }
public ActionResult CreatePerson(Guid ID) { Lead dbLead = new Lead(); dbLead = reposetory.GetLead(ID); if (dbLead == null) return RedirectToAction("Index"); NRMembership CU = new NR.Models.NRMembership { Association = reposetory.GetAssociation(CurrentProfile.AssociationID), SignupDate = DateTime.Now, Type = PersonType.Active, Person = new Person { Country = Country.DK, FirstName = dbLead.FirstName, FamilyName = dbLead.FamilyName, Address = dbLead.Address, Zip = dbLead.Zip, City = dbLead.City, Phone = dbLead.Phone, Mobile = dbLead.Mobile } }; return View("../People/edit", CU); }
public ActionResult Edit(NRMembership Membership, string RadioGender, string Action) { NRMembership CU = new NR.Models.NRMembership { AssociationID = CurrentProfile.AssociationID, SignupDate = DateTime.Now, Type = PersonType.Active }; CU.Person = new Person(); if (Membership.MembershipID != Guid.Empty) { CU = reposetory.GetMembership(Membership.MembershipID); if (CU == null) return HttpNotFound(); } //Check for a uniq username against database if (Membership.Person.PersonID == Guid.Empty || (Membership.Person.UserName != CU.Person.UserName)) { if (String.IsNullOrWhiteSpace(Membership.Person.UserName) | !reposetory.IsUserNameUniqe(Membership.Person.UserName)) { string SuggestedUserName = Membership.Person.UserName; if (Membership.Person.PersonID == Guid.Empty) { reposetory.GenerateUniqueUserName(Membership.Person); ModelState.SetModelValue("Person.UserName", new ValueProviderResult(Membership.Person.UserName, Membership.Person.UserName.ToString(), CultureInfo.InvariantCulture)); if (!String.IsNullOrWhiteSpace(SuggestedUserName)) ModelState.AddModelError("Person.UserName", string.Format(DomainStrings.UserNameNotUniqueSuggestion, SuggestedUserName)); } else { Membership.Person.UserName = CU.Person.UserName; //ModelState.Clear(); ModelState.SetModelValue("Person.UserName", new ValueProviderResult(Membership.Person.UserName, Membership.Person.UserName.ToString(), CultureInfo.InvariantCulture)); ModelState.AddModelError("Person.UserName", string.Format(DomainStrings.UserNameNotUnique, SuggestedUserName)); } } } if (RadioGender == "M") Membership.Person.Gender = Gender.Man; if (RadioGender == "F") Membership.Person.Gender = Gender.Woman; Membership.Person.Trim(); if (CU.Person.MailUndeliverable && ( CU.Person.FirstName != Membership.Person.FirstName | CU.Person.FamilyName != Membership.Person.FamilyName | CU.Person.Address != Membership.Person.Address | CU.Person.City != Membership.Person.City | CU.Person.Zip != Membership.Person.Zip )) { CU.Person.MailUndeliverable = false; CU.Person.MailUndeliverableDate = null; } CU.Person.UserName = Membership.Person.UserName; CU.Type = Membership.Type; CU.Person.FirstName = Membership.Person.FirstName; CU.Person.FamilyName = Membership.Person.FamilyName; CU.Person.Address = Membership.Person.Address; CU.Person.City = Membership.Person.City; CU.Person.Zip = Membership.Person.Zip; CU.Person.Email = Membership.Person.Email; CU.SignupDate = Membership.SignupDate; CU.Person.Country = Membership.Person.Country; CU.Person.Mobile = Membership.Person.Mobile; CU.Person.Phone = Membership.Person.Phone; CU.Person.BasicTrainingDate = Membership.Person.BasicTrainingDate; CU.Person.BirthDate = Membership.Person.BirthDate; CU.Person.EmailNewsLetter = Membership.Person.EmailNewsLetter; CU.Person.PrintNewslettet = Membership.Person.PrintNewslettet; CU.Person.Gender = Membership.Person.Gender; CU.Teamleader = Membership.Teamleader; CU.Note = Membership.Note; if (String.IsNullOrWhiteSpace(CU.Person.Password)) CU.Person.Password = String.Empty.GeneratePassword(); if (ModelState.IsValid) { var refresh = Membership.Person.PersonID == Guid.Empty; reposetory.SavePerson(CU); //TODO: Remove Websecurity account if status is changed from Active if (refresh) { //ensure that form i updated if resubmit of form i done //ModelState.SetModelValue("MembershipID", new ValueProviderResult(CU.MembershipID, CU.MembershipID.ToString(), CultureInfo.InvariantCulture)); //ModelState.SetModelValue("Person.PersonID", new ValueProviderResult(CU.Person.PersonID, CU.Person.PersonID.ToString(), CultureInfo.InvariantCulture)); //Create Websecurity Memebership if account is active if (CU.Type == PersonType.Active) { if (!WebSecurity.IsConfirmed(CU.Person.UserName)) WebSecurity.CreateAccount(CU.Person.UserName, CU.Person.Password); //Send Welcome mail if user has an E-mail if (!String.IsNullOrWhiteSpace(CU.Person.Email)) { var mail = new WelcomeMailEmail { To = CU.Person.Email, UserName = CU.Person.UserName, Password = CU.Person.Password }; mail.Send(); } else if (!String.IsNullOrWhiteSpace(CU.Person.Mobile)) { Association association = reposetory.GetAssociation(CU.Person.CurrentAssociation); #if DUMMYTEXT ITextMessage SMSGateway = TextServiceProviderFactory.GetTextServiceProviderrInstance("NR.Infrastructure.DummyTextGateway", association == null ? null : association.TextServiceProviderUserName, association == null ? null : association.TextServiceProviderPassword); #else ITextMessage SMSGateway = TextServiceProviderFactory.GetTextServiceProviderrInstance(association.TextServiceProvider, association == null ? null : association.TextServiceProviderUserName, association == null ? null : association.TextServiceProviderPassword); #endif SMSGateway.FromText = General.SystemTextMessagesFrom; SMSGateway.Message = String.Format(General.SystemTextMessagesWelcome, CU.Person.UserName, CU.Person.Password); SMSGateway.Recipient = new List<Person> { CU.Person }; if (association != null) { reposetory.NewTextMessage(SMSGateway, association.AssociationID); SMSGateway.HandShakeUrl = Url.Action("TextXStatus", "Account", new { ID = SMSGateway.TextId }, "http"); } if (SMSGateway.Send()) { }; } Notification not = reposetory.Notify(CU.Person, String.Format(Notifications.NewPerson, CU.Person.FullName)); reposetory.NotifyAddAdministration(not); reposetory.NotifyAddAssociation(not, CU.AssociationID); reposetory.NotifySave(not); } } ModelState.Clear(); ViewBag.FormSucces = true; return View(CU); } return View(Membership); }
public ActionResult Edit(Guid? ID) { NR.Models.NRMembership CU; if (ID == null) { CU = new NR.Models.NRMembership { Association = reposetory.GetAssociation(CurrentProfile.AssociationID), SignupDate = DateTime.Now, Type = PersonType.Active, Person = new Person { Country = Country.DK } }; //CU.Person = new Person(); } else { CU = reposetory.GetMembership((Guid)ID); if (CU == null) return HttpNotFound(); } return View(CU); }
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); }