示例#1
0
        public static Account CreateUser(string userName, string password, List<Role> roles, AccountProfile profile)
        {
            using (var db = ObjectProvider.CreateDB())
            {
                var salt = Helper.CreateSalt();

                Account account = new Account() { UserName = userName, Salt = salt, Password = GetHash(password, salt), Roles = roles, Profile = profile };

                roles.SetState(db, EntityState.Modified);
                profile.Beneficiaries.SetState(db, EntityState.Modified);
                profile.Currencies.SetState(db, EntityState.Modified);

                db.Accounts.Add(account);
                db.SaveChanges();

                return db.Accounts.FirstOrDefault(a => a.UserName == userName);
            }
        }
示例#2
0
        public IEnumerable<Payment> GetPayment(Account currentAccount)
        {
            var beneficiaryIds = currentAccount.Profile.Beneficiaries.Select(b => b.ID).ToArray();

            IEnumerable<Payment> payments = null;

            //convert to activity
            if (currentAccount.Roles.Exists(r => r.Name == "User"))
            {
                payments = GetPaymentByBeneficiary(beneficiaryIds).Where(p => p.CreatedByID == currentAccount.ID);
            }
            else if (currentAccount.Roles.Exists(r => r.Name == "Accountant"))
            {
                payments = GetPaymentByBeneficiary(beneficiaryIds);
            }
            else
            {
                payments = GetAll();
            }

            return payments;
        }
示例#3
0
        private void AddUser(
           string userName,
           string password,
           string name,
           int beneficiaryId,
           int currencyId)
        {
            if (!_unitOfWork.Accounts.Any(userName))
            {
                var role = _unitOfWork.Roles.Get("User");
                var beneficiary = _unitOfWork.Beneficiaries.Find(beneficiaryId);
                var currency = _unitOfWork.Currencies.Find(currencyId);

                Account account = new Account
                {
                    UserName = userName,
                    Password = password,
                    Roles = new List<Role>() { role },
                    Profile = new AccountProfile
                    {
                        Name = name,
                        Beneficiaries = new List<Beneficiary>() { beneficiary },
                        Currencies = new List<Currency>() { currency }
                    }

                };
                _unitOfWork.Accounts.Add(account);

                //roles.SetState(db, EntityState.Modified);
                //profile.Beneficiaries.SetState(db, EntityState.Modified);
                //profile.Currencies.SetState(db, EntityState.Modified);

                _unitOfWork.Complete();
            }
        }
示例#4
0
        private void AddAdmin(
            string userName,
            string password,
            string name)
        {
            if (!_unitOfWork.Accounts.Any(userName))
            {
                var role = _unitOfWork.Roles.Get("Administrator");
                var beneficiaries = _unitOfWork.Beneficiaries.GetAll();
                var currencies = _unitOfWork.Currencies.GetAll();

                Account account = new Account
                {
                    UserName = userName,
                    Password = password,
                    Roles = new List<Role>() { role },
                    Profile = new AccountProfile
                    {
                        Name = name,
                        Beneficiaries = beneficiaries.ToList(),
                        Currencies = currencies.ToList()
                    }

                };
                _unitOfWork.Accounts.Add(account);

                //roles.SetState(db, EntityState.Modified);
                //profile.Beneficiaries.SetState(db, EntityState.Modified);
                //profile.Currencies.SetState(db, EntityState.Modified);

                _unitOfWork.Complete();
            }
        }