コード例 #1
0
ファイル: Account.cs プロジェクト: the31stAuror/HMS_Raisins
        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
ファイル: PaymentRepository.cs プロジェクト: netxph/raisins
        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
ファイル: UserSeed.cs プロジェクト: netxph/raisins
        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
ファイル: UserSeed.cs プロジェクト: netxph/raisins
        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();
            }
        }