Пример #1
0
        public ClaimsPrincipal CreateIdentity(Entity.Account account)
        {
            var claims = new List <Claim> {
                new Claim(ClaimTypes.Name, account.FullName, ClaimValueTypes.String),
                new Claim(ClaimTypes.NameIdentifier, account.Id.ToString(), ClaimValueTypes.String),
                new Claim(ClaimTypes.Email, account.Email, ClaimValueTypes.String),
                new Claim(ClaimTypes.Role, account.Role, ClaimValueTypes.String)
            };

            return(new ClaimsPrincipal(new ClaimsIdentity(claims, "Cookies", "User", "Role")));
        }
Пример #2
0
        public void Setup()
        {
            Repository = new TransactionRepository(Context, new AccountRepository(Context), new CategoryRepository(Context), new SubCategoryRepository(Context), new TransactionTypeRepository(Context));

            var user = new Entity.User()
            {
                FirstName = "test", LastName = "test", Email = "*****@*****.**", Phone = "123-123-1234"
            };

            Context.Users.Add(user);
            Context.SaveChanges();

            var account = new Entity.Account()
            {
                User = user.ID, Name = "test", Description = "test"
            };

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

            var category = new Entity.Category()
            {
                User = user.ID, Name = "test", Description = "test"
            };

            Context.Categories.Add(category);
            Context.SaveChanges();

            var subCategory = new Entity.SubCategory()
            {
                User = user.ID, Category = category.ID, Name = "test", Description = "test"
            };

            Context.SubCategories.Add(subCategory);
            Context.SaveChanges();

            var type = new Entity.TransactionType()
            {
                Name = "test", Description = "test"
            };

            Context.TransactionTypes.Add(type);
            Context.SaveChanges();

            UserId            = user.ID;
            AccountId         = account.ID;
            CategoryId        = category.ID;
            SubCategoryId     = subCategory.ID;
            TransactionTypeId = type.ID;
        }
        public Entity.Account GetByUsernamePassword(string username, string password)
        {
            string        query  = string.Format("SELECT UserTypeID FROM Account WHERE UserName='******' AND Password='******'", username, password);
            SqlDataReader reader = DataAccess.GetData(query);

            reader.Read();

            Entity.Account account = null;
            if (reader.HasRows)
            {
                account            = new Entity.Account();
                account.UserTypeID = reader["UserTypeID"].ToString();
            }
            else
            {
                MessageBox.Show("Wrong Username or Password!");
                Application.Exit();
            }
            return(account);
        }
Пример #4
0
        public async Task <int> CreateAccount(int user, string name, string description)
        {
            var result = 0;

            var entity = new Entity.Account()
            {
                User        = user,
                Name        = name,
                Description = description
            };

            Context.Accounts.Add(entity);

            if (await Context.SaveChangesAsync() > 0)
            {
                result = entity.ID;
            }

            return(result);
        }
        public List <Entity.Account> GetAll()
        {
            string        query  = "SELECT AccountId, UserName, Password, FirstName, LastName, UserTypeID, Salary, JoinDate FROM Account";
            SqlDataReader reader = DataAccess.GetData(query);

            Entity.Account        account     = null;
            List <Entity.Account> accountList = new List <Entity.Account>();

            while (reader.Read())
            {
                account            = new Entity.Account(reader["AccountId"].ToString());
                account.Username   = reader["UserName"].ToString();
                account.Password   = reader["Password"].ToString();
                account.FirstName  = reader["FirstName"].ToString();
                account.LastName   = reader["LastName"].ToString();;
                account.UserTypeID = reader["UserTypeID"].ToString();
                account.Salary     = Convert.ToDouble(reader["UserTypeID"]);
                account.JoinDate   = Convert.ToDateTime(reader["UserTypeID"]);

                accountList.Add(account);
            }
            return(accountList);
        }
        public int Edit(Entity.Account account)
        {
            string query = string.Format("UPDATE Account SET UserName='******', Password='******', FirstName='" + account.FirstName + "', LastName='" + account.LastName + "', UserTypeID='" + account.UserTypeID + "', Salary='" + account.Salary + "', JoinDate='" + account.JoinDate + "' WHERE AccountId='{0}'", account.AccountID);

            return(DataAccess.ExecuteQuery(query));
        }
        public int Add(Entity.Account account)
        {
            string query = string.Format("INSERT INTO Account(AccountId, UserName, Password, FirstName, LastName, UserTypeID, Salary, JoinDate) VALUES('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', {6}, '{7}')", account.AccountID, account.Username, account.Password, account.FirstName, account.LastName, account.UserTypeID, account.Salary, account.JoinDate);

            return(DataAccess.ExecuteQuery(query));
        }
 public int Edit(Entity.Account account)
 {
     return(AccountService.accountDataAccess.Edit(account));
 }
 public int Add(Entity.Account account)
 {
     return(AccountService.accountDataAccess.Add(account));
 }
Пример #10
0
        // 确定事件
        private void confirm_Click(object sender, RoutedEventArgs e)
        {
            //MessageBox.Show(time.Text);
            if (inout.Text == "" || acctype.Text == "" || time.Text == "" || money.Text == "" || content.Text == "")
            {
                MessageBox.Show("填写信息不完全,请完善!!!");
                return;
            }

            int inoutValue;
            int acctypeValue;
            string timeValue;
            double moneyValue;
            string contentValue;

            // 可能存在输入数据的错误
            try
            {
                inoutValue = Convert.ToInt32(inout.SelectedValue);
                acctypeValue = Convert.ToInt32(acctype.SelectedValue);
                timeValue = time.Text;
                moneyValue = Convert.ToDouble(money.Text);
                contentValue = Convert.ToString(content.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("输入数据有错,请检查!!!");
                return;
            }
            string[] tmp = timeValue.Split('-');
            DateTime dat = new DateTime(Int32.Parse(tmp[0]), Int32.Parse(tmp[1]), Int32.Parse(tmp[2]));

            Entity.Account acc = new Entity.Account(helper.getUserId(currentUser), acctypeValue,
                inoutValue, moneyValue, contentValue, dat);
            if (helper.addAccountData(acc) == 1)
            {
                MessageBox.Show("插入成功!!!");
                this.Close();
            }
            else
            {
                MessageBox.Show("插入失败!!!");
            }

        }