Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                mvMain.SetActiveView(viewRegistration);

                var context = new AssociationsContext();
                List<Country> countries = new List<Country>(context.Countries.GetAll().OrderBy(c => c.Name));
                countries.Insert(0, new Country { Id = 0, Name = "" });
                ddlCountry.DataSource = countries;
                ddlCountry.DataTextField = "Name";
                ddlCountry.DataValueField = "Id";
                ddlCountry.DataBind();

                List<NamePrefix> prefixes = new List<NamePrefix>(NamePrefix.All);
                prefixes.Insert(0, new NamePrefix(0, ""));
                ddlPrefix.DataSource = prefixes;
                ddlPrefix.DataTextField = "Name";
                ddlPrefix.DataValueField = "Id";
                ddlPrefix.DataBind();

                string regionCountry = (string)Context.Session["RegionCountry"];
                ListItem regionCountryItem = ddlCountry.Items.FindByText(regionCountry);
                if (regionCountryItem != null)
                {
                    ddlCountry.SelectedValue = regionCountryItem.Value;
                    int countryId = int.Parse(ddlCountry.SelectedValue);
                    OnCountrySelected(countryId);
                }
            }
        }
Beispiel #2
0
        protected void Login1_Authenticate(object sender, System.Web.UI.WebControls.AuthenticateEventArgs e)
        {
            var Login1 = (System.Web.UI.WebControls.Login)sender;
            int associationId = (int)HttpContext.Current.Items["AssociationId"];

            using (TransactionScope scope = new TransactionScope())
            {
                var db = new AssociationsContext();
                var client = (from u in db.AssociationUsers.ObjectSet
                              where u.AssociationId == associationId && u.Email == Login1.UserName
                              select u).SingleOrDefault();

                if (client != null && client.Activated && Membership.ValidateUser(Login1.UserName, Login1.Password))
                {
                    var ticket = new FormsAuthenticationTicket(2, Login1.UserName, DateTime.Now, DateTime.Now.AddMinutes(30), Login1.RememberMeSet, client.Id.ToString(), FormsAuthentication.FormsCookiePath);
                    var encryptedTicket = FormsAuthentication.Encrypt(ticket);
                    var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                    authCookie.HttpOnly = true;
                    authCookie.Path = FormsAuthentication.FormsCookiePath;
                    authCookie.Secure = FormsAuthentication.RequireSSL;
                    if (FormsAuthentication.CookieDomain != null)
                        authCookie.Domain = FormsAuthentication.CookieDomain;
                    if (ticket.IsPersistent)
                        authCookie.Expires = ticket.Expiration;
                    Response.Cookies.Add(authCookie);

                    scope.Complete();

                    Response.RedirectToRoute("myaccount");
                }

                e.Authenticated = false;
            }
        }
        public void Should_Create_NewProfile()
        {
            AssociationsContext _db = new AssociationsContext();

            AssociationUser user = new AssociationUser();

            user.AssociationId = 1;
            user.Country = new Country() { Id = 1 };
            user.Email = "*****@*****.**";

            //name
            user.Prefix = NamePrefix.MR;
            user.FirstName = "Test";
            user.LastName = "Test";
            //phone
            user.OfficePhone = "1";
            user.MobilePhone = "2";
            user.HomePhone = "3";
            user.IsOfficePhoneDefault = true;
            user.CreatedTime = user.LastUpdatedTime = DateTime.UtcNow;
            user.CreatedBy = user.LastUpdatedBy = user.Email;

            _db.AttachUser(user);
            _db.SaveChanges();
        }
Beispiel #4
0
        private void OnCountrySelected(int countryId)
        {
            var context = new AssociationsContext();
            var country = context.Countries.FirstOrDefault(c => c.Id == countryId);
            lblPhoneCode1.Text = lblPhoneCode2.Text = lblPhoneCode3.Text = lblPhoneCode4.Text = country != null ? "+" + country.PhoneCode : "";
            lblCountry.Text = country != null ? country.Name : "";

            bool flag = (country != null && country.HasStates && country.DisplayStates);
            rowState.Visible = flag;
            if (flag)
            {
                var states = new List<State>(context.States.ObjectSet.Include("Country").Where(s => s.Country.Id == countryId).OrderBy(s => s.Name));
                states.Insert(0, new State { Id = 0, Acronym = "" });
                ddlState.DataSource = states;
                ddlState.DataTextField = "ShortName";
                ddlState.DataValueField = "Id";
                ddlState.DataBind();

                if (states.Count > 0)
                    PrepareSuburbContorls(0, 0);
            }
            else
            {
                PrepareSuburbContorls(countryId, 0);
            }
        }
Beispiel #5
0
 protected void lblUserName_Load(object sender, EventArgs e)
 {
     var lblUserName = (Label)sender;
     if (Request.IsAuthenticated)
     {
         AssociationsContext associationsContext = new AssociationsContext();
         int associationId = (int)HttpContext.Current.Items["AssociationId"];
         var user = associationsContext.AssociationUsers.FirstOrDefault(u => u.AssociationId == associationId && u.Email == Context.User.Identity.Name);
         if( user != null )
             lblUserName.Text = user.FullName;
     }
     else
         lblUserName.Text = "";
 }
Beispiel #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                AssociationsContext context = new AssociationsContext();
                int associationId = int.Parse(Membership.ApplicationName.Substring("association_".Length));
                var association = context.Associations.ObjectSet.Include("Country").FirstOrDefault(a => a.Id == associationId);

                lblName.Text = association.Name;

                lblBuilding.Text = association.Building;
                lblAddress1.Text = association.Address1;
                lblAddress2.Text = association.Address2;
                lblSuburb.Text = association.Suburb;
                lblState.Text = association.State;
                lblCode.Text = association.Code;
                lblCountry.Text = association.Country.Name;

                lblPhone1.Text = association.Phone1;
                lblPhone2.Text = association.Phone2;
                lblPhone3.Text = association.Phone3;

                //if (!string.IsNullOrWhiteSpace(association.Phone1))
                //{
                //    lblPhone1Short.Text = string.Format("{0} within {1} only", association.Phone1, association.Country.Name);
                //    lblPhone1Full.Text = string.Format("{0} {1} outside {2}", association.Country.PhoneCode, association.Phone1, association.Country.Name);
                //    lblPhone1Short.Visible = lblPhone1Full.Visible = true;
                //}
                //else
                //    lblPhone1Short.Visible = lblPhone1Full.Visible = false;

                //if (!string.IsNullOrWhiteSpace(association.Phone2))
                //{
                //    lblPhone2Short.Text = string.Format("{0} within {1} only", association.Phone2, association.Country.Name);
                //    lblPhone2Full.Text = string.Format("{0} {1} outside {2}", association.Country.PhoneCode, association.Phone2, association.Country.Name);
                //    lblPhone2Short.Visible = lblPhone1Full.Visible = true;
                //}
                //else
                //    lblPhone2Short.Visible = lblPhone2Full.Visible = false;

                //if (!string.IsNullOrWhiteSpace(association.Phone2))
                //{
                //    lblPhone3Short.Text = string.Format("{0} within {1} only", association.Phone3, association.Country.Name);
                //    lblPhone3Full.Text = string.Format("{0} {1} outside {2}", association.Country.PhoneCode, association.Phone3, association.Country.Name);
                //    lblPhone3Short.Visible = lblPhone1Full.Visible = true;
                //}
                //else
                //    lblPhone3Short.Visible = lblPhone3Full.Visible = false;
            }
        }
Beispiel #7
0
 protected void lblUserName_Load(object sender, EventArgs e)
 {
     var lblUserName = (Label)sender;
     if (Request.IsAuthenticated)
     {
         var db = new AssociationsContext();
         var ticket = ((System.Web.Security.FormsIdentity)(Context.User.Identity)).Ticket;
         int staffUserId = int.Parse(ticket.UserData);
         var user = db.AssociationStaffUsers.FirstOrDefault(u => u.Id == staffUserId);
         if (user != null)
             lblUserName.Text = user.FullName;
         else
             lblUserName.Text = Context.User.Identity.Name;
     }
     else
         lblUserName.Text = "";
 }
Beispiel #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Request.IsAuthenticated)
            {
                Response.RedirectToRoute("default");
                return;
            }

            if (!IsPostBack)
            {
                AssociationsContext context = new AssociationsContext();
                int associationId = (int)HttpContext.Current.Items["AssociationId"];
                var user = context.AssociationUsers.First(u => u.AssociationId == associationId && u.Email == Context.User.Identity.Name);
                lblEmail.Text = user.Email;
                lblFirstName.Text = user.FirstName;
                lblLastName.Text = user.LastName;

                //links
                linkChangePassword.HRef = Page.GetRouteUrl("profilechangepassword", null);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string guidStr = Page.RouteData.Values["guid"] as string;
                Guid guid;
                if (guidStr == null || !Guid.TryParseExact(guidStr, "D", out guid))
                    lblInfo.Text = "Wrong activation guid!";
                else
                {
                    var associationsContext = new AssociationsContext();
                    var activation = associationsContext.AssociationUserTravelAgencyRoleActivations.FirstOrDefault(a => a.Guid == guid);
                    if (activation == null)
                    {
                        lblInfo.Text = "Wrong activation guid!";
                        return;
                    }

                    var role = associationsContext.AssociationUserTravelAgencyRoles.ObjectSet.First(m => m.UserId == activation.UserId);
                    if (DateTime.UtcNow > activation.ExpiryTime)
                    {
                        role.Status = Loms.Modules.Associations.Entities.TravelAgencyStatus.Expired;
                        associationsContext.ObjectStateManager.ChangeObjectState(role, EntityState.Modified);

                        associationsContext.AssociationUserTravelAgencyRoleActivations.Delete(activation);
                        associationsContext.SaveChanges();

#if(DEBUG)
                        lblInfo.Text = "Time period for activation is over. Ask group manager to send new invitation.";
#else
                        lblInfo.Text = "Wrong activation guid!";
#endif

                        return;
                    }

                    try
                    {
                        role.Status = Loms.Modules.Associations.Entities.TravelAgencyStatus.Accepted;
                        associationsContext.ObjectStateManager.ChangeObjectState(role, EntityState.Modified);

                        associationsContext.AssociationUserTravelAgencyRoleActivations.Delete(activation);

                        associationsContext.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        lblInfo2.Visible = true;
                        lblInfo.Text = ex.Message;
                        return;
                    }

                    lblInfo2.Visible = lblInfo21.Visible = lblInfo3.Visible = lblInfo4.Visible = true;
                    lblInfo.Text = string.Format("Congratulations!");
                    lblInfo2.Text = string.Format("Supervisor Activation was completed successfully!");
                    lblInfo21.Text = "";
                    lblInfo3.Text = "";
                    lblInfo4.Text = "";
                }
            }
        }
Beispiel #10
0
        string ResetPassword(string email)
        {
            try
            {
                //int associationId = int.Parse(Membership.ApplicationName.Substring("association_".Length));
                int associationId = (int)HttpContext.Current.Items["AssociationId"];

                AssociationsContext associationsContext = new AssociationsContext();
                var user = associationsContext.AssociationUsers.FirstOrDefault(u => u.AssociationId == associationId && u.Email == email);
                if (user == null)
                    return "Wrong email!";

                if (!user.Activated)
                {
                    var activation = associationsContext.AssociationUserActivations.FirstOrDefault(a => a.AssociationUserId == user.Id);
                    if (DateTime.UtcNow > activation.ExpiryTime)
                    {
                        if (user.CreatedById == 0)
                            associationsContext.AssociationUsers.Delete(user);
                        else
                        {
                            user.Email = null;
                            associationsContext.ObjectStateManager.ChangeObjectState(user, EntityState.Modified);

                            associationsContext.AssociationUserActivations.Delete(activation);
                        }
                        associationsContext.SaveChanges();

                        return "Wrong email!";
                    }
                    else
                        return "Account is not active!";

                }

                var membershipUser = Membership.GetUser(email);
                if (membershipUser == null)
                    return "Wrong email!";

                string pwd = membershipUser.ResetPassword();

                var emailProvider = associationsContext.AssociationEmails.FirstOrDefault(ep => ep.AssociationId == user.AssociationId);
                if (emailProvider != null)
                {
                    AssociationsContext assocContext = new AssociationsContext();
                    var association = assocContext.Associations.FirstOrDefault(a => a.Id == user.AssociationId);

                    var uri = Request.Url;
                    string loginLink = String.Format("{0}://{1}:{2}", uri.Scheme, uri.Host ?? "80", uri.Port);

                    var txtContent = MailTemplateHelper.GetForgotPasswordTxtContent(association.Name.ToUpper(), user.FullName.ToUpper(), user.Email, pwd, loginLink);
                    var htmlContent = MailTemplateHelper.GetForgotPasswordHtmlContent(association.Name, user.FullName, user.Email, pwd, loginLink);
                    var avBody = AlternateView.CreateAlternateViewFromString(htmlContent, null, MediaTypeNames.Text.Html);

                    EmailHelper.SendMail(emailProvider, user.Email, association.Name.ToUpper() + "User Account Details", txtContent, null, avBody, true);
                }

                return null;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
        public void Should_Create_Update_Delete_AssociationUserAddress()
        {
            AssociationUserAddress address;

            //add
            using (var _db = new AssociationsContext())
            {
                address = new AssociationUserAddress();
                address.AssociationUserId = 21;
                address.Type = AddressType.Other;
                address.CountryId = 1;
                _db.AssociationUserAddresses.Add(address);
                _db.SaveChanges();
            }

            //retrieve and check
            using (var _db = new AssociationsContext())
            {
                var query = from a in _db.AssociationUserAddresses.ObjectSet.IncludeAll("Country", "State", "State.Country", "Suburb", "Suburb.Country", "Suburb.State")
                            where a.Id == address.Id
                            select a;

                address = query.SingleOrDefault();
                Assert.AreEqual(1, address.Country.Id);
            }

            //update
            using (var _db = new AssociationsContext())
            {
                address = new AssociationUserAddress() { Id = address.Id };
                address.AssociationUserId = 21;
                address.Type = AddressType.Other;
                address.SuburbId = 42;
                _db.AssociationUserAddresses.Attach(address);
                _db.ObjectStateManager.ChangeObjectState(address, EntityState.Modified);
                _db.SaveChanges();
            }

            //retrieve and check
            using (var _db = new AssociationsContext())
            {
                var query = from a in _db.AssociationUserAddresses.ObjectSet.IncludeAll("Country", "State", "State.Country", "Suburb", "Suburb.Country", "Suburb.State")
                            where a.Id == address.Id
                            select a;

                address = query.SingleOrDefault();
                Assert.AreEqual(42, address.Suburb.Id);
            }

            //delete
            using (var _db = new AssociationsContext())
            {
                address = new AssociationUserAddress() { Id = address.Id };
                _db.AssociationUserAddresses.Attach(address);
                _db.AssociationUserAddresses.Delete(address);
                _db.SaveChanges();
            }

            //retrieve and check
            using (var _db = new AssociationsContext())
            {
                var query = from a in _db.AssociationUserAddresses.ObjectSet.IncludeAll("Country", "State", "State.Country", "Suburb", "Suburb.Country", "Suburb.State")
                            where a.Id == address.Id
                            select a;

                address = query.SingleOrDefault();
                Assert.IsNull(address);
            }
        }
Beispiel #12
0
        private void FillRegionCombo(AssociationsContext context)
        {
            var domains = context.Domains.ObjectSet.IncludeAll("Countries.Country").ToList();
            domains.Sort(new Domain.Comparer());

            ArrayList items = new ArrayList();
            foreach (var domain in domains)
            {
                if (domain.Id != 0)
                    foreach (var domainCountry in domain.Countries.OrderBy(dc => dc.Name))
                        items.Add(new { Code = domainCountry.Abbreviation2.ToLower(), Name = domainCountry.Name.ToUpper(), Region = domain.Name });
                else
                    items.Add(new { Code = "others", Name = "OTHER COUNTRIES", Region = domain.Name });
            }
            ddlCountry.DataSource = items;
            ddlCountry.DataTextField = "Name";
            ddlCountry.DataValueField = "Code";
            ddlCountry.DataGroupField = "Region";
            ddlCountry.DataBind();
        }
Beispiel #13
0
        void PrepareSuburbContorls(int countryId, int stateId)
        {
            if (countryId == 0)
            {
                txtSuburbName.Visible = lblSuburbCode.Visible = txtSuburbCode.Visible = false;
                ddlSuburb.Visible = false;
                return;
            }


            var context = new AssociationsContext();
            IEnumerable<Suburb> query;
            if (stateId == 0)
            {
                query = from s in context.Suburbs.ObjectSet
                        where s.CountryId == countryId
                        orderby s.Name
                        select s;
            }
            else
            {
                query = from s in context.Suburbs.ObjectSet
                        where s.CountryId == countryId && s.StateId == stateId
                        orderby s.Name
                        select s;
            }
            var suburbs = query.ToList();

            if (suburbs.Count > 0)
            {
                suburbs.Insert(0, new Suburb { Id = 0, Name = "" });

                ddlSuburb.DataSource = suburbs;
                ddlSuburb.DataTextField = "FullName";
                ddlSuburb.DataValueField = "Id";
                ddlSuburb.DataBind();

                txtSuburbName.Visible = lblSuburbCode.Visible = txtSuburbCode.Visible = false;
                ddlSuburb.Visible = true;
            }
            else
            {
                txtSuburbName.Visible = lblSuburbCode.Visible = txtSuburbCode.Visible = true;
                ddlSuburb.Visible = false;
            }
        }
Beispiel #14
0
        private bool ValidateEmailTextBox(TextBox txt)
        {
            string email = txt.Text.Trim();
            if (email == "" || !Regex.IsMatch(email, @"[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})"))
            {
                lblEmailNote.Text = "Compulsory field";
                return false;
            }
            else
            {
                var associationContext = new AssociationsContext();

                int associationId = int.Parse(Membership.ApplicationName.Substring("association_".Length));

                //check id user with such email existed already
                var existedUser = (from u in associationContext.AssociationUsers.ObjectSet
                                   where u.AssociationId == associationId && u.Email == email
                                   select u).SingleOrDefault();

                if (existedUser != null)
                {
                    lblEmailNote.Text = "User with such email is already registered!";
                    return false;
                }

                return true;
            }

        }
Beispiel #15
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            //validation 
            bool notValidated = false;
            notValidated |= lblCountryNote.Visible = !ValidateDropDown(ddlCountry);

            notValidated |= lblTitleNote.Visible = (checkTravelAgent.Checked && !ValidateTextBox(txtTitle));
            notValidated |= lblIataNumberNote.Visible = (checkTravelAgent.Checked && !ValidateIataNumberTextBox(txtIataNumber));
            //notValidated |= lblTravelAgencyNameNote.Visible = (checkTravelAgent.Checked && !ValidateTextBox(txtTravelAgencyName));

            notValidated |= lblStateNote.Visible = (checkTravelAgent.Checked && rowState.Visible && !ValidateDropDown(ddlState));
            notValidated |= lblBusinessNameNote.Visible = (checkTravelAgent.Checked && !ValidateTextBox(txtBusinessName));

            notValidated |= lblAddress1Note.Visible = (checkTravelAgent.Checked && !ValidateTextBox(txtAddress1));

            if (txtSuburbName.Visible)
            {
                notValidated |= lblSuburbNote.Visible = (checkTravelAgent.Checked && !ValidateTextBox(txtSuburbName));
                notValidated |= lblSuburbNote.Visible = (checkTravelAgent.Checked && !ValidateTextBox(txtSuburbCode));
            }
            else
                notValidated |= lblSuburbNote.Visible = (checkTravelAgent.Checked && !ValidateDropDown(ddlSuburb));


            notValidated |= lblTermsNote.Visible = !checkTermsConfirmed.Checked;
            notValidated |= lblAgeNote.Visible = !checkAge16Confirmed.Checked;

            if (notValidated)
                return;

            int associationId = int.Parse(Membership.ApplicationName.Substring("association_".Length));
            AssociationsContext assocContext = new AssociationsContext();
            var association = assocContext.Associations.FirstOrDefault(a => a.Id == associationId);

            string error = Register(association);
            if (error == null)
            {
                mvMain.SetActiveView(viewSuccess);
                lblAssociationName.Text = association.Name;
                lblSuccessEmail.Text = txtEmail.Text.ToLower();
            }
            else
            {
                mvMain.SetActiveView(viewError);
                lblError.Text = error;
            }
        }
Beispiel #16
0
        protected void Page_Load(object sender, EventArgs e)
        {
            VirtualDirectory = ConfigurationSettings.VirtualDirectory;
            if (!IsPostBack)
            {
                //linkRegistration.HRef = Page.GetRouteUrl("registration", null);
                //linkForgotPassword.HRef = Page.GetRouteUrl("forgotpassword", null);

                //Login1.Visible = !Request.IsAuthenticated;
                //linkRegistration.Visible = !Request.IsAuthenticated;
                //linkForgotPassword.Visible = !Request.IsAuthenticated;

                AssociationsContext context = new AssociationsContext();

                //fill region combo
                FillRegionCombo(context);

                //select country
                string countryCode = Page.RouteData.Values["countryCode"] as string;
                if (countryCode == null)
                {
                    ddlCountry.SelectedValue = "others";
                    Context.Session["RegionCountry"] = "";
                    Context.Session["RegionCountryCode"] = "";
                }
                else
                {
                    ddlCountry.SelectedValue = countryCode.ToLower();
                    Context.Session["RegionCountry"] = ddlCountry.SelectedItem.Text;
                    Context.Session["RegionCountryCode"] = countryCode;
                }

                //create cookie
                if (Request.Browser.Cookies)
                {
                    HttpCookie regionCountryCookie = new HttpCookie("RegionCountry");
                    regionCountryCookie.Value = ddlCountry.SelectedValue;
                    Response.Cookies.Set(regionCountryCookie);
                }

                //get country, 0 for other
                int countryId = 0;
                if (countryCode != null)
                {
                    Country country = context.Countries.FirstOrDefault(c => StringComparer.InvariantCultureIgnoreCase.Compare(c.Abbreviation2, countryCode) == 0);
                    if (country != null)
                        countryId = country.Id;
                }

                int associationId = (int)HttpContext.Current.Items["AssociationId"];
                var associationBannerGroup = context.AssociationBannerGroups.FirstOrDefault(bg => bg.AssociationId == associationId && bg.CountryId == countryId);
                if (associationBannerGroup != null)
                {
                    imageBanner1.ImageUrl = Path.Combine(ConfigurationSettings.BannerGroupDirectoryPath, associationBannerGroup.BannerGroupId + "_1.jpg");
                    imageBanner2.ImageUrl = Path.Combine(ConfigurationSettings.BannerGroupDirectoryPath, associationBannerGroup.BannerGroupId + "_2.jpg");
                    imageBanner3.ImageUrl = Path.Combine(ConfigurationSettings.BannerGroupDirectoryPath, associationBannerGroup.BannerGroupId + "_3.jpg");
                }
                else
                {
                    var association = context.Associations.ObjectSet.FirstOrDefault(a => a.Id == associationId);
                    imageBanner1.ImageUrl = Path.Combine(ConfigurationSettings.BannerGroupDirectoryPath, association.DefaultBannerGroupId + "_1.jpg");
                    imageBanner2.ImageUrl = Path.Combine(ConfigurationSettings.BannerGroupDirectoryPath, association.DefaultBannerGroupId + "_2.jpg");
                    imageBanner3.ImageUrl = Path.Combine(ConfigurationSettings.BannerGroupDirectoryPath, association.DefaultBannerGroupId + "_3.jpg");
                }
            }
        }
Beispiel #17
0
        string Register(Association association)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    AssociationsContext associationContext = new AssociationsContext();

                    var email = txtEmail.Text.ToLower();

                    //check id user with such email existed already
                    var existedUser = (from u in associationContext.AssociationUsers.ObjectSet
                                       where u.AssociationId == association.Id && u.Email == email
                                       select u).SingleOrDefault();

                    if (existedUser != null)
                        return "User with such email is already registered!";

                    //create user 
                    AssociationUser user = new AssociationUser();

                    user.AssociationId = association.Id;
                    user.Country = new Country() { Id = int.Parse(ddlCountry.SelectedValue) }; ;
                    user.Email = email;

                    //name
                    user.Prefix = NamePrefix.All.FirstOrDefault(p => p.Name == ddlPrefix.SelectedItem.Text);
                    user.FirstName = txtFirstName.Text.ToUpper();
                    user.LastName = txtLastName.Text.ToUpper();
                    //phone
                    user.OfficePhone = txtPhoneOffice.Text;
                    user.MobilePhone = txtPhoneMobile.Text;
                    user.HomePhone = txtPhoneHome.Text;
                    user.IsOfficePhoneDefault = rbDefaultPhoneOffice.Checked;
                    user.IsMobilePhoneDefault = rbDefaultPhoneMobile.Checked;
                    user.IsHomePhoneDefault = rbDefaultPhoneHome.Checked;

                    user.IsTravelAgency = checkTravelAgent.Checked;
                    user.PositionTitle = txtTitle.Text.ToUpper();
                    user.IataNumber = txtIataNumber.Text.ToUpper();

                    user.CreatedTime = user.LastUpdatedTime = DateTime.UtcNow;

                    associationContext.AttachUser(user);
                    associationContext.SaveChanges();

                    //home address
                    AssociationUserAddress homeAddress = new AssociationUserAddress();
                    homeAddress.Nickname = user.FullName + " HOME";
                    homeAddress.AssociationUserId = user.Id;
                    homeAddress.Type = AddressType.Home;
                    homeAddress.CountryId = user.CountryId;

                    //work address
                    AssociationUserAddress workAddress = new AssociationUserAddress();
                    workAddress.Nickname = user.FullName + " WORK";
                    workAddress.AssociationUserId = user.Id;
                    workAddress.CountryId = user.CountryId;
                    workAddress.Type = AddressType.Work;

                    workAddress.BusinessName = txtBusinessName.Text.ToUpper();
                    workAddress.BuildingName = txtBuilding.Text.ToUpper();
                    workAddress.Address1 = txtAddress1.Text.ToUpper();
                    workAddress.Address2 = txtAddress2.Text.ToUpper();
                    if (ddlSuburb.Visible && ddlSuburb.SelectedIndex > 0)
                    {
                        int suburbId = int.Parse(ddlSuburb.SelectedValue);
                        if (suburbId > 0)
                        {
                            workAddress.CountryId = null;
                            workAddress.SuburbId = suburbId;
                        }
                    }
                    else
                    {
                        if (rowState.Visible && ddlState.SelectedIndex > 0)
                        {
                            int stateId = int.Parse(ddlState.SelectedValue);
                            if (stateId > 0)
                            {
                                workAddress.CountryId = null;
                                workAddress.StateId = stateId;
                            }
                        }
                        workAddress.SuburbName = txtSuburbName.Text.ToUpper();
                        workAddress.SuburbCode = txtSuburbCode.Text.ToUpper();
                    }

                    associationContext.AttachUserAddress(homeAddress);
                    associationContext.AttachUserAddress(workAddress);
                    associationContext.SaveChanges();

                    AssociationUserActivation activation = new AssociationUserActivation();
                    activation.AssociationUserId = user.Id;
                    activation.Guid = Guid.NewGuid();
                    activation.ExpiryTime = DateTime.UtcNow.AddHours(2.0);  //expiry
                    associationContext.AssociationUserActivations.Add(activation);
                    associationContext.SaveChanges();

                    var emailProvider = associationContext.AssociationEmails.FirstOrDefault(e => e.AssociationId == association.Id);
                    if (emailProvider != null)
                    {
                        var uri = Request.Url;
                        string baseUrl = String.Format("{0}://{1}:{2}", uri.Scheme, uri.Host ?? "80", uri.Port);
                        string activtionLink = Path.Combine(baseUrl + Page.GetRouteUrl("activation", new { guid = activation.Guid.ToString("D") }));
                        string contactUsLink = Path.Combine(baseUrl + Page.GetRouteUrl("contactus", null));

                        var txtContent = MailTemplateHelper.GetRegistratioTxtContent(association.Name.ToUpper(), user.FullName.ToUpper(), activtionLink, contactUsLink);
                        var htmlContent = MailTemplateHelper.GetRegistratioHtmlContent(association.Name, user.FullName, activtionLink, contactUsLink);
                        var avBody = AlternateView.CreateAlternateViewFromString(htmlContent, null, MediaTypeNames.Text.Html);

                        EmailHelper.SendMail(emailProvider, user.Email, association.Name.ToUpper() + " New User Registration", txtContent, null, avBody, true);
                    }

                    scope.Complete();
                }

                return null;
            }
            catch (Exception ex)
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendLine(ex.Message);
                if (ex.InnerException != null)
                {
                    builder.AppendLine(ex.InnerException.Message);
                    if (ex.InnerException.InnerException != null)
                        builder.AppendLine(ex.InnerException.InnerException.Message);
                }
                return builder.ToString();
            }
        }