Пример #1
0
        public void Edit(D.Account account, D.AccountProfile profile)
        {
            EF.Account efAccount = ConvertToEFwithID(account, profile);

            //START
            var tempAccount = _context.Accounts.Single(a => a.AccountID == efAccount.AccountID);

            tempAccount.RoleID = efAccount.RoleID;

            var tempProfile = _context.Profiles.Single(p => p.ProfileID == efAccount.ProfileID);

            //remove beneficary
            foreach (var ben in tempProfile.Beneficiaries.ToArray())
            {
                if (!efAccount.Profile.Beneficiaries.Any(b => b.BeneficiaryID == ben.BeneficiaryID))
                {
                    tempProfile.Beneficiaries.Remove(ben);
                }
            }
            //add beneficary
            foreach (var ben in efAccount.Profile.Beneficiaries)
            {
                if (!tempProfile.Beneficiaries.Any(b => b.BeneficiaryID == ben.BeneficiaryID))
                {
                    tempProfile.Beneficiaries.Add(ben);
                }
            }

            _context.SaveChanges();
        }
Пример #2
0
        public void Add(D.Account account, D.AccountProfile profile)
        {
            account.AddSalt();
            _context.Accounts.Add(ConvertToEF(account, profile));
            _context.SaveChanges();
            var x = _context.Accounts.FirstOrDefault(a => a.UserName == account.UserName);

            Debug.WriteLine(x.UserName);
        }
Пример #3
0
        public void Add(D.Account account, D.AccountProfile profile)
        {
            if (account.UserName != null || profile.Name != null)
            {
                account.AddSalt();

                _context.Accounts.Add(ConvertToEF(account, profile));
                _context.SaveChanges();
            }
        }
Пример #4
0
        protected virtual EF.AccountProfile BuildAccountProfile(D.AccountProfile profile)
        {
            List <EF.Beneficiary> efBeneficiaries = new List <EF.Beneficiary>();

            foreach (var beneficiary in profile.Beneficiaries)
            {
                efBeneficiaries.Add(_context.Beneficiaries.FirstOrDefault(b => b.Name == beneficiary.Name));
            }

            return(new EF.AccountProfile(profile.Name, efBeneficiaries));
        }
Пример #5
0
        private EF.AccountProfile ConvertProfileToEF(D.AccountProfile profile)
        {
            List <EF.Beneficiary> efBeneficiaries = new List <EF.Beneficiary>();

            foreach (var beneficiary in profile.Beneficiaries)
            {
                efBeneficiaries.Add(_context.Beneficiaries.FirstOrDefault(b => b.Name == beneficiary.Name));
            }
            int profileID = _context.Profiles.FirstOrDefault(a => a.Name == profile.Name).ProfileID;

            return(new EF.AccountProfile(profileID, profile.Name, efBeneficiaries, profile.IsLocal));
        }
Пример #6
0
        private EF.Account ConvertToEF(D.Account account, D.AccountProfile profile)
        {
            int roleID = _context.Roles.FirstOrDefault(r => r.Name == account.Role.Name).RoleID;
            List <EF.Beneficiary> efBeneficiaries = new List <EF.Beneficiary>();

            foreach (var beneficiary in profile.Beneficiaries)
            {
                efBeneficiaries.Add(_context.Beneficiaries.FirstOrDefault(b => b.Name == beneficiary.Name));
            }
            EF.AccountProfile efProfile = new EF.AccountProfile(profile.Name, efBeneficiaries);
            return(new EF.Account(account.UserName, GetHash(account.Password, account.Salt), account.Salt, roleID, efProfile));
        }
Пример #7
0
        protected EF.Account ConvertToEF(D.Account account, D.AccountProfile profile)
        {
            int roleID = _context.Roles.FirstOrDefault(r => r.Name == account.Role.Name).RoleID;

            return(new EF.Account(
                       account.UserName,
                       GetHash(account.Password,
                               account.Salt),
                       account.Salt,
                       roleID,
                       BuildAccountProfile(profile)));
        }
Пример #8
0
        private EF.Account ConvertToEFwithID(D.Account account, D.AccountProfile profile)
        {
            EF.Role role = _context.Roles.FirstOrDefault(r => r.Name == account.Role.Name);
            List <EF.Beneficiary> efBeneficiaries = new List <EF.Beneficiary>();

            foreach (var beneficiary in profile.Beneficiaries)
            {
                efBeneficiaries.Add(_context.Beneficiaries.FirstOrDefault(b => b.Name == beneficiary.Name));
            }
            EF.Account current   = _context.Accounts.FirstOrDefault(a => a.UserName == account.UserName);
            int        profileID = _context.Profiles.FirstOrDefault(a => a.Name == profile.Name).ProfileID;

            EF.AccountProfile efProfile = new EF.AccountProfile(profileID, profile.Name, efBeneficiaries, profile.IsLocal);
            return(new EF.Account(current.AccountID, account.UserName, current.Password, current.Salt, role.RoleID, role, efProfile.ProfileID, efProfile));
        }
Пример #9
0
        private D.Account ConvertToDomain(EF.Account efAccount)
        {
            EF.Role              efRole        = _context.Roles.FirstOrDefault(r => r.RoleID == efAccount.RoleID);
            EF.AccountProfile    efProfile     = _context.Profiles.FirstOrDefault(r => r.ProfileID == efAccount.Profile.ProfileID);
            List <D.Beneficiary> beneficiaries = new List <D.Beneficiary>();

            foreach (var beneficiary in efProfile.Beneficiaries)
            {
                beneficiaries.Add(new D.Beneficiary(beneficiary.Name));
            }

            D.Role           role    = new D.Role(efRole.Name, efRole.Permissions);
            D.AccountProfile profile = new D.AccountProfile(efProfile.Name, beneficiaries);

            return(new D.Account(efAccount.UserName, efAccount.Password, efAccount.Salt, role, profile));
        }
Пример #10
0
        public Account(string userName, Role role, AccountProfile profile)
        {
            if (string.IsNullOrEmpty(userName))
            {
                throw new ArgumentNullException("Account:userName");
            }

            UserName = userName;

            if (role == null)
            {
                throw new ArgumentNullException("Account:role");
            }

            Role = role;
            if (profile == null)
            {
                throw new ArgumentNullException("Account:profile");
            }

            Profile = profile;
        }
Пример #11
0
        public Account(string userName, string passwordHash, string salt, Role role, AccountProfile profile)
        {
            if (string.IsNullOrEmpty(userName))
            {
                throw new ArgumentNullException("Account:userName");
            }

            UserName = userName;

            if (role == null)
            {
                throw new ArgumentNullException("Account:role");
            }

            Role = role;
            if (profile == null)
            {
                throw new ArgumentNullException("Account:profile");
            }

            Profile = profile;

            if (string.IsNullOrEmpty(salt))
            {
                throw new ArgumentNullException("Account:salt");
            }

            Salt = salt;

            if (string.IsNullOrEmpty(passwordHash))
            {
                throw new ArgumentNullException("Account:passwordHash");
            }

            Password = passwordHash;
        }
 public void Edit(AM.Account account, AM.AccountProfile profile)
 {
     throw new NotImplementedException();
 }