Пример #1
0
        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();
        }
Пример #2
0
        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 = "";
                }
            }
        }
Пример #3
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;
            }
        }
Пример #4
0
        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);
            }
        }
Пример #5
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();
            }
        }