Esempio n. 1
0
        public ActionResult PreViewEmail(string name)
        {
            dynamic email = new WelcomeMailEmail();
            // set up the email ...
            email.To = "*****@*****.**";
            email.UserName = "******";
            email.Password = "******";
            email.Send();
            return new EmailViewResult(email);

        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }