コード例 #1
0
        public AssociationsContainerView(AssociationUser associationUser)
        {
            InitializeComponent();

            Manager = associationUser;            

            this.Loaded += new RoutedEventHandler(AssociationsContainerView_Loaded);

            CloseButton = new HyperlinkButton();
            CloseButton.Content = "Close X";
            CloseButton.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            CloseButton.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            CloseButton.Margin = new Thickness(0, 20, 20, 0);

            if (AssociationProfileContainer.Children.Count == 0)
            {
                view = KernelContainer.Kernel.Get<AssociationsView>();
                viewModel = KernelContainer.Kernel.Get<AssociationsViewModel>();
                viewModel.AssociationManagerId = Manager.Id;
                AssociationsViewModel.IsStaffApp = true;
                view.DataContext = viewModel;

                (view.FindName("LayoutRoot") as Grid).Children.Add(CloseButton);

                AssociationProfileContainer.Children.Add(view);
            }
        }
コード例 #2
0
 public void OnProfileSelected(object sender, DataEventArgs<AssociationUser> e)
 {
     if ((sender as ProfilesViewModel).AssociationManagerId == _manager.Id)
     {
         _selectedProfile = e.Value;
     }
 }
コード例 #3
0
ファイル: ProfilesViewModel.cs プロジェクト: felixthehat/Limo
        private void Search()
        {
            var currentAsyncResult = default(IAsyncResult);
            SearchRequest searchRequest = new SearchRequest { SearchFilter = Filter, SearchFilterValue = FilterValue };
            currentAsyncResult = _lastSearchAsyncResult =

            Service.BeginGetProfiles(AssociationManagerId, searchRequest, CreateAsyncCallback(ar => Service.EndGetProfiles(ar), response =>
            {
                if (_lastSearchAsyncResult != currentAsyncResult) return;       // This might be call multiple times, we only care about the last one.

                var profiles = new ObservableCollection<AssociationUser>(response.ManagedProfiles);

                _manager = response.Manager;

                _manager.CurrentManagerId = _manager.Id;
                foreach (AssociationUser user in profiles)
                    user.CurrentManagerId = _manager.Id;

                //_manager.IsManager = true;
                ManagerSelected.Raise(this, _manager);

                profiles.Insert(0, _manager);

                Profiles = profiles;
                SelectedProfile = _manager;
            }), null);

        }
コード例 #4
0
 public void OnManagerSelected(object sender, DataEventArgs<AssociationUser> e)
 {
     if (_manager == null)
     {
         _manager = e.Value;
         OnPropertyChanged(() => Breadcrumbs);
         OnPropertyChanged(() => MyAdminTabVisibility);
     }
 }
コード例 #5
0
        public BookingEngineContainer(AssociationUser creator, AssociationUser primaryPassenger, String breadCrumbs)
        {
            InitializeComponent();

            BookingsView bookingsView = KernelContainer.Kernel.Get<BookingsView>();
            BookingsViewModel bookingsViewModel = KernelContainer.Kernel.Get<BookingsViewModel>();
            bookingsViewModel.InitialCreatorId = creator.Id;
            if (primaryPassenger != null)
                bookingsViewModel.InitialPrimaryPassengerId = primaryPassenger.Id;
            bookingsViewModel.Breadcrumbs = breadCrumbs;

            bookingsView.DataContext = bookingsViewModel;
            LayoutRoot.Children.Add(bookingsView);
        }
コード例 #6
0
         public void OpenSelectedProfile(AssociationUser associationUser)
        {
            if (associationUser == null)
                return;


            //AssociationsViewModel.ManagerId = SelectedAssociationUser.Id;

            AssociationsContainerView container = ClienteleState.AssociationsContainerViews.FirstOrDefault(x => x.Manager.Id == associationUser.Id);
            if (container == null)
            {
                container = new AssociationsContainerView(associationUser);
                ClienteleState.AssociationsContainerViews.Add(container);
                ClienteleState.AssociationUsers.Add(associationUser);
            }

            this.AssociationsProfilePanel.Children.Add(container);
            container.CloseButton.Click += new RoutedEventHandler(CloseButton_Click);

            this.AssociationsProfilePanel.Visibility = System.Windows.Visibility.Visible;
        }
コード例 #7
0
 public PreferedNumberIsRequiredValidator(AssociationUser associationUser)
 {
     _associationUser = associationUser;
 }
コード例 #8
0
 public EmailIsRequiredForTravelAgencies(AssociationUser associationUser)
 {
     _associationUser = associationUser;
 }
コード例 #9
0
     private void FixupManager(AssociationUser previousValue, bool skipKeys = false)
     {
         if (IsDeserializing)
         {
             return;
         }
 
         if (Manager != null)
         {
             ManagerId = Manager.Id;
         }
 
         else if (!skipKeys)
         {
             ManagerId = null;
         }
 
         if (ChangeTracker.ChangeTrackingEnabled)
         {
             if (ChangeTracker.OriginalValues.ContainsKey("Manager")
                 && (ChangeTracker.OriginalValues["Manager"] == Manager))
             {
                 ChangeTracker.OriginalValues.Remove("Manager");
             }
             else
             {
                 ChangeTracker.RecordOriginalValue("Manager", previousValue);
             }
             if (Manager != null && !Manager.ChangeTracker.ChangeTrackingEnabled)
             {
                 Manager.StartTracking();
             }
         }
     }
コード例 #10
0
        public AssociationUser CreateNewManagedUser()
        {
            var profile = new AssociationUser
            {
                ManagerId = this.Id,
                CreatedById = this.Id,
                CreatedBy = this.FullName,
                Country = this.Country,
            };
            if (this.IsTravelAgency)
                profile.CreatedBy += " " + this.TravelAgencyName;

            var homeAddress = new AssociationUserAddress { Country = this.Country, Nickname = "x" };
            var workAddress = new AssociationUserAddress { Country = this.Country, Nickname = "y" };
            homeAddress.AcceptChanges();
            workAddress.AcceptChanges();

            return profile;
        }
コード例 #11
0
 public void OnManagerSelected(object sender, DataEventArgs<AssociationUser> e)
 {
     _manager = e.Value;
     OnPropertyChanged(() => Breadcrumbs);
 }
コード例 #12
0
        public AssociationUser SaveAssociationUser(AssociationUser user)
        {
            if (!Roles.IsUserInRole(RoleName.StaffUser))
                throw new SecurityException();

            using (TransactionScope scope = new TransactionScope())
            using (var db = new LomsContext())
            {
                if (!HasUniqueEmail(user))
                {
                    user.AddError("Error", "The email you have entered is already in use on the system. Please use a unique email address, or call us for assistance.");
                    // TODO: Miguel. Change this based on Andrew's feedback (something like If you think this is an error, please contact)
                    return user;
                }

                user.AssociationId = CurrentAssociationId;
                if (user.Id == 0)
                    user.CreatedTime = user.LastUpdatedTime = DateTime.UtcNow;
                user.LastUpdatedTime = DateTime.UtcNow;

                db.AssociationUsers.ApplyChanges(user);
                db.SaveChanges();

                user = db.AssociationUsers.IncludeAll("Country", "Activation").FirstOrDefault(u => u.Id == user.Id);

                scope.Complete();
            }

            return user;
        }
コード例 #13
0
 public SavedBillingAccountViewModel(AssociationUser profile, ObservableCollection<AssociationBillingAccount> billingAccounts, AssociationUserBillingAccount savedBillingAccount)
 {
     SavedBillingAccount = savedBillingAccount;
     BillingAccounts = billingAccounts;
     Profile = profile;
 }
コード例 #14
0
ファイル: ProfilesViewModel.cs プロジェクト: felixthehat/Limo
        public void AddProfile()
        {
            var profile = new AssociationUser
            {
                ManagerId = _manager.Id,
                CreatedById = _manager.Id,
                CreatedBy = _manager.FullName,
                Country = _manager.Country,
            };
            if (_manager.IsTravelAgency)
                profile.CreatedBy += " " + _manager.TravelAgencyName;

            var homeAddress = new AssociationUserAddress { Country = _manager.Country, Nickname = "x", Type = AddressType.Home };
            var workAddress = new AssociationUserAddress { Country = _manager.Country, Nickname = "y", Type = AddressType.Work };
            //var taxInvoice = new AssociationUserTaxInvoice();
            //homeAddress.AcceptChanges();
            //workAddress.AcceptChanges();
            //taxInvoice.AcceptChanges();
            OpenProfileDetailWindow(profile, homeAddress, workAddress, null, null, true);
        }
コード例 #15
0
        private bool HasUniqueEmail(AssociationUser profile)
        {
            if (String.IsNullOrWhiteSpace(profile.Email))
                return true;

            using (var db = new LomsContext())
            {
                var query = from u in db.AssociationUsers
                            where u.AssociationId == CurrentAssociationId && u.Email == profile.Email && u.Id != profile.Id
                            select u.Id;

                return query.Count() == 0;
            }
        }
コード例 #16
0
        public void RemoveAssociationUser(int userId)
        {
            if (!Roles.IsUserInRole(RoleName.StaffUser))
                throw new SecurityException();

            using (var db = new LomsContext())
            {
                var user = new AssociationUser() { Id = userId };
                db.AssociationUsers.Attach(user);
                db.AssociationUsers.DeleteObject(user);
                db.SaveChanges();
            }
        }
コード例 #17
0
        public AssociationUser SaveAssociationUser(AssociationUser user)
        {
            try
            {
                string email = user.Email != null ? user.Email.ToLower().Trim() : null;

                using (var db = new LomsContext())
                {
                    db.Connection.Open();

                    using (var transaction = db.Connection.BeginTransaction())
                    {
                        if (!string.IsNullOrWhiteSpace(email))
                        {
                            //check id user with such email existed already
                            var existedUser = (from u in db.AssociationUsers
                                               where u.AssociationId == CurrentAssociationId && u.Email == email && (user.Id == 0 || u.Id != user.Id)
                                               select u).SingleOrDefault();

                            if (existedUser != null)
                            {
                                user.AddError("Email", "User with such email is already registered!");
                                return user;
                            }

                            user.Email = email;
                        }
                        else
                            user.Email = null;


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

                        db.AssociationUsers.ApplyChanges(user);
                        db.SaveChanges();

                        if (!string.IsNullOrWhiteSpace(user.Email))
                        {
                            AssociationUserActivation activation = new AssociationUserActivation();
                            activation.UserId = user.Id;
                            activation.Guid = Guid.NewGuid();
                            activation.ExpiryTime = DateTime.UtcNow.AddDays(7.0);  //expiry
                            db.AssociationUserActivations.ApplyChanges(activation);
                            db.SaveChanges();

                            var emailProvider = db.AssociationEmails.FirstOrDefault(e => e.AssociationId == CurrentAssociationId);
                            if (emailProvider != null)
                            {
                                var association = db.Associations.FirstOrDefault(a => a.Id == CurrentAssociationId);

                                var uri = HttpContext.Current.Request.Url;
                                string baseUrl = String.Format("{0}://{1}:{2}", uri.Scheme, uri.Host ?? "80", uri.Port);
                                string activtionLink = Path.Combine(baseUrl + string.Format("/#Activation/{0}", activation.Guid.ToString("D")));
                                string contactUsLink = Path.Combine(baseUrl + "/#Contact");
                                string termAndConditionsLink = Path.Combine(baseUrl + "/terms");

                                var emailTemplate = new EmailTemplate("StaffAdminAddsNewManagedProfileWithEmail");

                                emailTemplate["UserName"] = user.FullName.ToUpper();
                                emailTemplate["AssociationName"] = association.Name.ToUpper();

                                emailTemplate["ActivationLink"] = activtionLink;
                                emailTemplate["ContactUsLink"] = contactUsLink;
                                emailTemplate["TermAndConditionLink"] = termAndConditionsLink;

                                var avBody = AlternateView.CreateAlternateViewFromString(emailTemplate.Html, null, MediaTypeNames.Text.Html);
                                emailProvider.SendMail(user.Email, association.Name + " Account activation", emailTemplate.Txt, null, avBody, true);
                            }
                        }

                        transaction.Commit();
                    }
                }
                using (var db = new LomsContext())
                {
                    var entity = db.AssociationUsers.IncludeAll("Country").Single(u => u.Id == user.Id);
                    return entity;
                }
            }
            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);
                }
                user.AddError("Error", builder.ToString());
                return user;
            }

        }
コード例 #18
0
        public EntityResponse<AssociationUser> CreateManagedUser(AssociationUser user)
        {
            try
            {
                var email = user.Email.ToLower().Trim();

                using (var scope = new TransactionScope())
                using (var db = new LomsContext())
                {
                    if (!string.IsNullOrWhiteSpace(email))
                    {
                        //check id user with such email existed already
                        var existedUser = (from u in db.AssociationUsers
                                           where u.AssociationId == CurrentAssociationId && u.Email == email
                                           select u).SingleOrDefault();

                        if (existedUser != null)
                            return new EntityResponse<AssociationUser>("User with such email is already registered!");
                        user.Email = email;
                    }
                    else
                        user.Email = null;


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

                    var manager = db.AssociationUsers.FirstOrDefault(u => u.Id == user.ManagerId);
                    if (manager.IsTravelAgency)
                    {
                        user.IsTravelAgency = true;
                        user.IataNumber = manager.IataNumber;
                    }

                    db.AssociationUsers.ApplyChanges(user);
                    db.SaveChanges();

                    AssociationUserActivation activation = new AssociationUserActivation();
                    activation.UserId = user.Id;
                    activation.Guid = Guid.NewGuid();
                    activation.ExpiryTime = DateTime.UtcNow.AddDays(7.0);  //expiry
                    db.AssociationUserActivations.ApplyChanges(activation);
                    db.SaveChanges();

                    var emailProvider = db.AssociationEmails.FirstOrDefault(e => e.AssociationId == CurrentAssociationId);
                    if (emailProvider != null)
                    {
                        var association = db.Associations.FirstOrDefault(a => a.Id == CurrentAssociationId);

                        var uri = HttpContext.Current.Request.Url;
                        string baseUrl = String.Format("{0}://{1}:{2}", uri.Scheme, uri.Host ?? "80", uri.Port);
                        string activtionLink = Path.Combine(baseUrl + string.Format("/#Activation/{0}", activation.Guid.ToString("D")));
                        string contactUsLink = Path.Combine(baseUrl + "/#Contact");
                        string termAndConditionsLink = Path.Combine(baseUrl + "/terms");

                        EmailTemplate emailTemplate;
                        if (manager.IsTravelAgency)
                        {
                            emailTemplate = new EmailTemplate("NewProfileByTravelAgent");

                            var travelAgencyName = (from a in db.AssociationUserAddresses
                                                    where a.AssociationUserId == manager.Id && a.TypeId == (int)AddressType.Work
                                                    select a.BusinessName).SingleOrDefault();

                            emailTemplate["TravelAgencyName"] = travelAgencyName.ToUpper();
                        }
                        else
                            emailTemplate = new EmailTemplate("NewProfileByGeneralUser");

                        emailTemplate["UserName"] = user.FullName.ToUpper();
                        emailTemplate["AssociationName"] = association.Name.ToUpper();

                        emailTemplate["ManagerName"] = manager.FullName.ToUpper();
                        emailTemplate["ManagerEmail"] = manager.Email.ToLower();

                        emailTemplate["ActivationLink"] = activtionLink;
                        emailTemplate["ContactUsLink"] = contactUsLink;
                        emailTemplate["TermAndConditionLink"] = termAndConditionsLink;

                        var avBody = AlternateView.CreateAlternateViewFromString(emailTemplate.Html, null, MediaTypeNames.Text.Html);
                        emailProvider.SendMail(user.Email, association.Name + " Account activation", emailTemplate.Txt, null, avBody, true);
                    }

                    scope.Complete();

                }

                using (var db = new LomsContext())
                {
                    var entity = db.AssociationUsers.IncludeAll("Country").Single(u => u.Id == user.Id);
                    return new EntityResponse<AssociationUser>() { Entity = entity };
                }
            }
            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 new EntityResponse<AssociationUser>(builder.ToString());
            }
        }
コード例 #19
0
     private void FixupUser(AssociationUser previousValue)
     {
         if (IsDeserializing)
         {
             return;
         }
 
         if (User != null)
         {
             UserId = User.Id;
         }
 
         if (ChangeTracker.ChangeTrackingEnabled)
         {
             if (ChangeTracker.OriginalValues.ContainsKey("User")
                 && (ChangeTracker.OriginalValues["User"] == User))
             {
                 ChangeTracker.OriginalValues.Remove("User");
             }
             else
             {
                 ChangeTracker.RecordOriginalValue("User", previousValue);
             }
             if (User != null && !User.ChangeTracker.ChangeTrackingEnabled)
             {
                 User.StartTracking();
             }
         }
     }
コード例 #20
0
        public string RegisterClient(ClientRegistrationRequest request)
        {
            try
            {
                using (var scope = new TransactionScope())
                using (var db = new LomsContext())
                {
                    var email = request.Email.Trim().ToLower();

                    //check id user with such email existed already
                    var count = (from u in db.AssociationUsers
                                 where u.AssociationId == CurrentAssociationId && u.Email == email
                                 select u).Count();

                    if (count != 0)
                        return "User with such email is already registered!";

                    //create membership
                    MembershipCreateStatus status;
                    var userMembership = Membership.CreateUser(email, request.Password, email, "Am i client?", "Yes", false, out status);
                    switch (status)
                    {
                        case MembershipCreateStatus.Success:
                            break;
                        //case MembershipCreateStatus.InvalidPassword:
                        //    throw new ApplicationException("Invalid password.");
                        default:
                            throw new ApplicationException("Cannot create user account.", new ApplicationException(status.ToString()));
                    }
                    Guid aspNetUserId = (Guid)userMembership.ProviderUserKey;


                    //add role
                    if (!Roles.RoleExists(RoleName.Client))
                        Roles.CreateRole(RoleName.Client);
                    Roles.AddUserToRole(email, RoleName.Client);

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

                    user.AssociationId = CurrentAssociationId;
                    user.CountryId = request.CountryId;
                    user.Email = email;

                    //name
                    user.Prefix = NamePrefix.All.FirstOrDefault(p => p.Id == request.NamePrefixId);
                    user.FirstName = request.FirstName.ToUpper();
                    user.LastName = request.LastName.ToUpper();
                    //phone
                    user.OfficePhone = request.OfficePhone;
                    user.MobilePhone = request.MobilePhone;
                    user.HomePhone = request.HomePhone;
                    user.DefaultPhoneType = request.DefaultPhoneType;

                    user.IsTravelAgency = request.IsTravelAgency;
                    user.PositionTitle = request.Position;

                    if (user.IsTravelAgency)
                        user.IataNumber = request.IataNumber.ToUpper();

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

                    user.AspNetUserId = aspNetUserId;

                    db.AssociationUsers.ApplyChanges(user);
                    db.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 = request.BusinessName.ToUpper();
                    workAddress.BuildingName = request.BuildingName.ToUpper();
                    workAddress.Address1 = request.Address1.ToUpper();
                    workAddress.Address2 = request.Address2.ToUpper();

                    if (request.SuburbId != 0)
                    {
                        workAddress.CountryId = null;
                        workAddress.StateId = null;
                        workAddress.SuburbId = request.SuburbId;
                    }
                    else
                    {
                        if (request.StateId != 0)
                        {
                            workAddress.CountryId = null;
                            workAddress.StateId = request.StateId;
                            workAddress.SuburbId = null;
                        }

                        workAddress.SuburbName = request.SuburbName.ToUpper();
                        workAddress.SuburbCode = request.SuburbCode.ToUpper();
                    }

                    db.AssociationUserAddresses.ApplyChanges(homeAddress);
                    db.AssociationUserAddresses.ApplyChanges(workAddress);
                    db.SaveChanges();

                    AssociationUserActivation activation = new AssociationUserActivation();
                    activation.UserId = user.Id;
                    activation.Guid = Guid.NewGuid();
                    activation.ExpiryTime = DateTime.UtcNow.AddHours(2.0);  //expiry
                    db.AssociationUserActivations.ApplyChanges(activation);
                    db.SaveChanges();

                    var emailProvider = db.AssociationEmails.FirstOrDefault(e => e.AssociationId == CurrentAssociationId);
                    if (emailProvider != null)
                    {
                        var association = db.Associations.FirstOrDefault(a => a.Id == CurrentAssociationId);

                        var uri = HttpContext.Current.Request.Url;

                        string baseUrl = String.Format("{0}://{1}:{2}", uri.Scheme, uri.Host ?? "80", uri.Port);
                        string activtionLink = Path.Combine(baseUrl + string.Format("/#Activation/{0}", activation.Guid.ToString("D")));
                        string contactUsLink = Path.Combine(baseUrl + "/#Contact");

                        var emailTemplate = new EmailTemplate("OnlineRegistrationActivation");
                        emailTemplate["UserName"] = user.FullName.ToUpper();
                        emailTemplate["AssociationName"] = association.Name.ToUpper();
                        emailTemplate["ActivationLink"] = activtionLink;
                        emailTemplate["ContactUsLink"] = contactUsLink;

                        var avBody = AlternateView.CreateAlternateViewFromString(emailTemplate.Html, null, MediaTypeNames.Text.Html);
                        emailProvider.SendMail(user.Email, association.Name + " Account activation", emailTemplate.Txt, 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();
            }
        }
コード例 #21
0
ファイル: AssociationUser.cs プロジェクト: felixthehat/Limo
     public bool Equals(AssociationUser other)
     {
         if (ReferenceEquals(null, other)) return false;
         if (ReferenceEquals(this, other)) return true;
 		if (other.Id == 0 && Id == 0)
 			return false;
 		else
 			return other.Id == Id;
     }
コード例 #22
0
ファイル: HistoryViewModel.cs プロジェクト: felixthehat/Limo
 public void OnManagerSelected(object sender, DataEventArgs<AssociationUser> e)
 {
     if (_manager == null)
         _manager = e.Value;
 }
コード例 #23
0
        public AssociationUser SaveProfile(AssociationUser profile)
        {
            using (TransactionScope scope = new TransactionScope())
            using (var db = new LomsContext())
            {
                if (!HasUniqueEmail(profile))
                {
                    profile.AddError("Error", "The email you have entered is already in use on the system. Please use a unique email address, or call us for assistance.");
                    // TODO: Miguel. Change this based on Andrew's feedback (something like If you think this is an error, please contact)
                    return profile;
                }

                bool isManager = profile.TravelAgencyRole != null;

                if (profile.Id == 0)
                {
                    profile.AssociationId = CurrentAssociationId;
                    profile.CreatedTime = profile.LastUpdatedTime = DateTime.UtcNow;
                }
                if (profile.Email != null)
                    profile.Email = profile.Email.Trim();


                profile.LastUpdatedTime = DateTime.UtcNow;

                db.AssociationUsers.ApplyChanges(profile);
                db.SaveChanges();

                if (isManager)
                    profile = db.AssociationUsers.IncludeAll("Country", "Activation", "TravelAgencyRole", "TravelAgencyRole.TravelAgency", "TravelAgencyRole.TravelAgency.Country", "TravelAgencyRole.TravelAgency.State", "TravelAgencyRole.TravelAgency.State.Country", "TravelAgencyRole.TravelAgency.Suburb", "TravelAgencyRole.TravelAgency.Suburb.Country", "TravelAgencyRole.TravelAgency.Suburb.State", "TravelAgencyRole.TravelAgency.Suburb.State.Country").FirstOrDefault(u => u.Id == profile.Id);
                else
                    profile = db.AssociationUsers.IncludeAll("Country", "Activation").FirstOrDefault(u => u.Id == profile.Id);

                //onlie access
                if (profile != null && !string.IsNullOrWhiteSpace(profile.Email) && profile.Activation == null && !profile.HasOnlineAccess)
                {
                    //start activation process
                    AssociationUserActivation activation = new AssociationUserActivation();
                    activation.UserId = profile.Id;
                    activation.Guid = Guid.NewGuid();
                    activation.ExpiryTime = DateTime.UtcNow.AddDays(7.0);  //expiry
                    db.AssociationUserActivations.ApplyChanges(activation);
                    db.SaveChanges();

                    //send email
                    var emailProvider = db.AssociationEmails.FirstOrDefault(e => e.AssociationId == profile.AssociationId);
                    if (emailProvider != null)
                    {
                        var association = db.Associations.FirstOrDefault(a => a.Id == profile.AssociationId);

                        var request = HttpContext.Current.Request;
                        var uri = request.Url;
                        string baseUrl = String.Format("{0}://{1}:{2}", uri.Scheme, uri.Host ?? "80", uri.Port);
                        string activtionLink = Path.Combine(baseUrl + string.Format("/#Activation/{0}", activation.Guid.ToString("D")));
                        string contactUsLink = Path.Combine(baseUrl + "/#Contact");
                        string termAndConditionsLink = Path.Combine(baseUrl + "/terms");

                        var manager = db.AssociationUsers.FirstOrDefault(u => u.Id == profile.ManagerId);

                        if (profile.IataNumber != null)
                        {
                            var travelAgencyName = (from a in db.AssociationUserAddresses
                                                    where a.AssociationUserId == profile.Id && a.TypeId == (int)AddressType.Work
                                                    select a.BusinessName).SingleOrDefault();


                            var txtContent = MailTemplateHelper.GetByTravelAgentRegistrationActivationTxtContent(association.Name.ToUpper(), profile.FullName.ToUpper(), activtionLink, contactUsLink, manager.FullName, manager.Email, termAndConditionsLink, travelAgencyName);
                            var htmlContent = MailTemplateHelper.GetByTravelAgentRegistrationActivationHtmlContent(association.Name, profile.FullName, activtionLink, contactUsLink, manager.FullName, manager.Email, termAndConditionsLink, travelAgencyName);
                            var avBody = AlternateView.CreateAlternateViewFromString(htmlContent, null, MediaTypeNames.Text.Html);

                            emailProvider.SendMail(profile.Email, association.Name.ToUpper() + " Account activation", txtContent, null, avBody, true);
                        }
                        else
                        {
                            var txtContent = MailTemplateHelper.GetByGeneralUserRegistrationActivationTxtContent(association.Name.ToUpper(), profile.FullName.ToUpper(), activtionLink, contactUsLink, manager.FullName, manager.Email, termAndConditionsLink);
                            var htmlContent = MailTemplateHelper.GetByGeneralUserRegistrationActivationHtmlContent(association.Name, profile.FullName, activtionLink, contactUsLink, manager.FullName, manager.Email, termAndConditionsLink);
                            var avBody = AlternateView.CreateAlternateViewFromString(htmlContent, null, MediaTypeNames.Text.Html);

                            try
                            {
                                emailProvider.SendMail(profile.Email, association.Name.ToUpper() + " Account activation", txtContent, null, avBody, true);
                            }
                            catch
                            {
                            }
                        }
                    }
                }
                scope.Complete();
            }

            profile.AcceptChanges();
            return profile;
        }
コード例 #24
0
ファイル: ProfilesViewModel.cs プロジェクト: felixthehat/Limo
        private void OpenProfileDetailWindow(AssociationUser profile, AssociationUserAddress homeAddress, AssociationUserAddress workAddress, AssociationUserCreditCard creditCard, AssociationUserBillingAccount billingAccount, bool isAdd)
        {
            var view = Kernel.Get<ProfileDetailChildWindow>();
            var viewModel = Kernel.Get<ProfileDetailChildWindowViewModel>();
            viewModel.Profile = profile;
            viewModel.Manager = _manager;
            viewModel.ProfileHomeAddress = homeAddress != null ? homeAddress : new AssociationUserAddress { Country = _manager.Country, Nickname = "Home", Type = AddressType.Home };
            viewModel.ProfileWorkAddress = workAddress != null ? workAddress : new AssociationUserAddress { Country = _manager.Country, Nickname = "Work", Type = AddressType.Work };
            viewModel.ProfileDefaultCreditCard = creditCard;
            viewModel.ProfileDefaultBillingAccount = billingAccount;
            viewModel.IsAdd = isAdd;

            view.DataContext = viewModel;

            viewModel.Completed += (o, e) =>
            {
                view.DialogResult = true;
                e.Value.CurrentManagerId = _manager.Id;
                Profiles.Replace(e.Value);
                SelectedProfile = e.Value;
            };

            viewModel.Cancelled += (o, e) =>
                {
                    //if (e.Value.Id == _managerId)
                    //    e.Value.IsManager = true;
                    e.Value.CurrentManagerId = _manager.Id;
                    Profiles.Replace(e.Value);
                    SelectedProfile = e.Value;
                };

            view.Show();
        }
コード例 #25
0
        private bool HasUniqueEmail(AssociationUser profile)
        {
            if (String.IsNullOrWhiteSpace(profile.Email))
                return true;

            using (var db = new LomsContext())
            {
                var query = from u in db.AssociationUsers
                            where u.AssociationId == CurrentAssociationId && u.Email == profile.Email && u.Id != profile.Id
                            select u.Id;

                return query.Count() == 0;
            }
            //var db = new AssociationsContext();     // TODO: Alex. I had to create another object because this query was loading all the objects in the ObjectSet and causing issues when Attaching an Existing AssUser. 
            //return db.AssociationUsers.FirstOrDefault(u =>
            //    u.Email == profile.Email &&
            //    u.AssociationId == CurrentAssociationId &&
            //    u.Id != profile.Id) == null;
        }
コード例 #26
0
     private void FixupAssociationUser(AssociationUser previousValue)
     {
         // This is the dependent end in an association that performs cascade deletes.
         // Update the principal's event listener to refer to the new dependent.
         // This is a unidirectional relationship from the dependent to the principal, so the dependent end is
         // responsible for managing the cascade delete event handler. In all other cases the principal end will manage it.
         if (previousValue != null)
         {
             previousValue.ChangeTracker.ObjectStateChanging -= HandleCascadeDelete;
         }
 
         if (AssociationUser != null)
         {
             AssociationUser.ChangeTracker.ObjectStateChanging += HandleCascadeDelete;
         }
 
         if (IsDeserializing)
         {
             return;
         }
 
         if (AssociationUser != null)
         {
             UserId = AssociationUser.Id;
         }
 
         if (ChangeTracker.ChangeTrackingEnabled)
         {
             if (ChangeTracker.OriginalValues.ContainsKey("AssociationUser")
                 && (ChangeTracker.OriginalValues["AssociationUser"] == AssociationUser))
             {
                 ChangeTracker.OriginalValues.Remove("AssociationUser");
             }
             else
             {
                 ChangeTracker.RecordOriginalValue("AssociationUser", previousValue);
                 // This is the dependent end of an identifying association, so it must be deleted when the relationship is
                 // removed. If the current state is Added, the relationship can be changed without causing the dependent to be deleted.
                 // This is a unidirectional relationship from the dependent to the principal, so the dependent end is
                 // responsible for cascading the delete. In all other cases the principal end will manage it.
                 if (previousValue != null && ChangeTracker.State != ObjectState.Added)
                 {
                     this.MarkAsDeleted();
                 }
             }
             if (AssociationUser != null && !AssociationUser.ChangeTracker.ChangeTrackingEnabled)
             {
                 AssociationUser.StartTracking();
             }
         }
     }
コード例 #27
0
        private void UpdateContactPhone(AssociationUser user)
        {
            if (user == null)
                return;

            if (SelectedPassengerContactType == PassengerContactType.FirstAdult)
                _booking.PassengerInfo.ContactPhone = user.DefaultPhone;
        }
コード例 #28
0
 public void OnProfileSelected(object sender, DataEventArgs<AssociationUser> e)
 {
     Profile = e.Value;
 }
コード例 #29
0
     private void FixupUser(AssociationUser previousValue)
     {
         if (IsDeserializing)
         {
             return;
         }
 
         if (previousValue != null && ReferenceEquals(previousValue.TravelAgencyRole, this))
         {
             previousValue.TravelAgencyRole = null;
         }
 
         if (User != null)
         {
             User.TravelAgencyRole = this;
             UserId = User.Id;
         }
 
         if (ChangeTracker.ChangeTrackingEnabled)
         {
             if (ChangeTracker.OriginalValues.ContainsKey("User")
                 && (ChangeTracker.OriginalValues["User"] == User))
             {
                 ChangeTracker.OriginalValues.Remove("User");
             }
             else
             {
                 ChangeTracker.RecordOriginalValue("User", previousValue);
             }
             if (User != null && !User.ChangeTracker.ChangeTrackingEnabled)
             {
                 User.StartTracking();
             }
         }
     }