Example #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();
        }
Example #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);
        }
Example #3
0
        public void AddBeneficiary(D.Account superAccount, D.Beneficiary beneficiary)
        {
            var superAccountBeneficiary = superAccount.Profile.Beneficiaries.FirstOrDefault(b => b.Name == beneficiary.Name);

            if (superAccountBeneficiary == null)
            {
                AddBeneficiaryToSuper(superAccount, beneficiary);
            }
        }
Example #4
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();
            }
        }
Example #5
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));
        }
Example #6
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)));
        }
Example #7
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));
        }
Example #8
0
        protected virtual void AddBeneficiaryToSuper(D.Account superAccount, D.Beneficiary beneficiary)
        {
            var acc = _context.Accounts.FirstOrDefault(a => a.UserName == superAccount.UserName);

            //_context.Accounts.Remove(acc);
            //_context.SaveChanges();

            var bene = _context.Beneficiaries.FirstOrDefault(b => b.Name == beneficiary.Name);

            //_context.Accounts.Add(acc);
            //_context.SaveChanges();

            acc.Profile.Beneficiaries.Add(bene);
            _context.SaveChanges();
        }
 public void Edit(AM.Account account, AM.AccountProfile profile)
 {
     throw new NotImplementedException();
 }