コード例 #1
0
 private void addService()
 {
     using (var db = new BancoContext())
     {
         Service nuevoServicio = new Service();
         nuevoServicio.addService(txtName.Text, textDescription.Text, Convert.ToInt64(txtHours.Text), txtSchedule.Text, comboBoxType.Text, 1, Convert.ToInt32(comboBoxCategory.Text));
         db.Services.Add(nuevoServicio);
         db.SaveChanges();
     }
 }
コード例 #2
0
        private void updateAccount()
        {
            using (var db = new BancoContext())
            {
                var currentAccount = from account in db.Accounts where account.User_Id == userID select account;

                foreach (var account in currentAccount)
                {
                    account.updateAccount();
                }
                db.SaveChanges();
            }
        }
コード例 #3
0
 private void listMovements(int accountId)
 {
     listViewMovements.Items.Clear();
     using (var db = new BancoContext())
     {
         var query = from movement in db.Movements where movement.Account_Id == accountId
                     select movement;
         foreach (var item in query)
         {
             ListViewItem listItem = listViewMovements.Items.Add(item.Date.ToString());
             listItem.SubItems.Add(item.Hours.ToString());
             listItem.SubItems.Add(item.Service_Id.ToString());
             listItem.SubItems.Add(item.FromUser_Id.ToString());
         }
     }
 }
コード例 #4
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //CREATE AN USER AN ITS ACCOUNT AND STORE IN DATA BASE

            /*using (var db = new BancoContext())
             * {
             *  var user = new User
             *  {
             *      Name = "Miguel",
             *      Email = "pomikelor@gmaiom",
             *      Password = "******",
             *      Phone = 654654654
             *  };
             *  var accountMiguel = new Account(user_id);
             *  db.Accounts.Add(accountMiguel);
             *  db.Users.Add(user);
             *  db.SaveChanges();
             * }*/

            //Get user´s name from data base and show in principal form when logged in
            int userId = 2;

            using (var db = new BancoContext())
            {
                var currentUser = from user in db.Users where user.Id == userId select user;

                foreach (var user in currentUser)
                {
                    labelSaludo.Text = "¡Hola " + user.Name + "!";
                }

                var currentAccount = from account in db.Accounts where account.User_Id == userId select account;

                foreach (var account in currentAccount)
                {
                    //List current user's account movements
                    listMovements(account.Id);
                    account.updateAccount();
                    txtBalance.Text = account.Balance.ToString();
                }
                db.SaveChanges();
            }

            // List all services
            listServices();
        }
コード例 #5
0
 private void listServices()
 {
     listViewServices.Items.Clear();
     using (var db = new BancoContext())
     {
         var query = from service in db.Services
                     select service;
         foreach (var item in query)
         {
             ListViewItem listItem = listViewServices.Items.Add(item.Name);
             listItem.SubItems.Add(item.User_Id.ToString());
             listItem.SubItems.Add(item.Type);
             listItem.SubItems.Add(item.Hours.ToString());
             listItem.SubItems.Add(item.Description);
             listItem.SubItems.Add(item.Schedule);
             listItem.SubItems.Add(item.Category_Id.ToString());
         }
     }
 }
コード例 #6
0
        private void addMovement()
        {
            int fromUserAccountID = 1;

            using (var db = new BancoContext())
            {
                Movement newMovementToUser = new Movement();
                newMovementToUser.addMovement(Convert.ToDateTime(dateMovement.Text), -Convert.ToInt64(txtHours.Text), Convert.ToInt32(txtService.Text), Convert.ToInt32(txtFromUser.Text), accountID);
                db.Movements.Add(newMovementToUser);

                Movement newMovementFromUser = new Movement();
                int      fromUserID          = Convert.ToInt32(txtFromUser.Text);
                var      fromUserAccount     = from account in db.Accounts where account.User_Id == fromUserID select account;
                foreach (var account in fromUserAccount)
                {
                    fromUserAccountID = account.Id;
                }
                newMovementFromUser.addMovement(Convert.ToDateTime(dateMovement.Text), Convert.ToInt64(txtHours.Text), Convert.ToInt32(txtService.Text), Convert.ToInt32(txtFromUser.Text), fromUserAccountID);
                db.Movements.Add(newMovementFromUser);
                db.SaveChanges();
            }
        }