public void AddToTypesOfOffices()
        {
            using (var context = new BusinessCodingModelContex())
            {
                TypesOfOffices tmp = new TypesOfOffices();

                tmp.Capacity = 10;
                tmp.CostOfHiring = 10;
                tmp.Name = "testUnit";

                context.TypesOfOffices.Add(tmp);
            }
        }
        public void AddToTypesOfEmployees()
        {
            using (var context = new BusinessCodingModelContex())
            {
                TypesOfEmployees tmp = new TypesOfEmployees();

                tmp.Codity = 10;
                tmp.Name = "testUnit";
                tmp.Salary = 10;

                context.TypesOfEmployees.Add(tmp);
            }
        }
        public void AddToDescriptions()
        {
            using (var contex = new BusinessCodingModelContex())
            {
                Descriptions tmp = new Descriptions();

                tmp.String = "testUnit";

                var restult = from x in contex.Projects where x.Name == "Nowy iOS" select x;
                tmp.ProjectsProjectID = restult.First().ProjectID;

                contex.Descriptions.Add(tmp);
            }
        }
        /// <summary>
        /// Dodanie rekordu do tabeli Companies.
        /// </summary>
        /// <param name="entryForm">okno z którego pobieramy dane</param>
        private void AddRecordToCompanies(object entry)
        {
            Companies newCompany = (Companies)entry;
            using (var db = new BusinessCodingModelContex())
            {

                try
                {
                    newCompany.CompanyID = db.Companies.Max(x => x.CompanyID) + 1;
                }
                catch
                {
                    newCompany.CompanyID = 1;
                }
                db.Companies.Add(newCompany);

                try
                {
                    db.SaveChanges();
                }
                catch
                {
                    MessageBox.Show("You have to add a good reference.");
                    return;
                }

                Thread newThread = new Thread(DisplayAllRecordsFromCompanies);
                newThread.Start();
            }
        }
        private void ModyfingUsersInNewThread()
        {
            using (var db = new BusinessCodingModelContex())
            {
                db.Users.Attach(selectedUser);
                var entry = db.Entry(selectedUser);

                entry.Property(x => x.ActivationDate).IsModified = true;
                entry.Property(x => x.Email).IsModified = true;
                entry.Property(x => x.LastLogin).IsModified = true;
                entry.Property(x => x.Login).IsModified = true;
                entry.Property(x => x.Password).IsModified = true;

                db.SaveChanges();
            }
            Thread newThread = new Thread(DisplayAllRecordsFromUsers);
            newThread.Start();
        }
        private void ModyfingProjectsInNewThread()
        {
            using (var db = new BusinessCodingModelContex())
            {
                db.Projects.Attach(selectedProject);
                var entry = db.Entry(selectedProject);

                entry.Property(x => x.CompaniesCompanyID).IsModified = true;
                entry.Property(x => x.Complexity).IsModified = true;
                entry.Property(x => x.Gratification).IsModified = true;
                entry.Property(x => x.MinCodity).IsModified = true;
                entry.Property(x => x.MinRespect).IsModified = true;
                entry.Property(x => x.Name).IsModified = true;
                entry.Property(x => x.TimeRounds).IsModified = true;
                entry.Property(x => x.TimeToEnd).IsModified = true;
                try
                {
                    db.SaveChanges();
                }
                catch
                {
                    MessageBox.Show("You have to give a reference to existing record.");
                }
            }
            Thread newThread = new Thread(DisplayAllRecordsFromProjects);
            newThread.Start();
        }
 public void TestAddTOoUsers()
 {
     using (var context = new BusinessCodingModelContex())
     {
         context.Users.Add(new Users()
         {
             UserID = 100,
             Login = "******",
             Password = "******",
             Email = "*****@*****.**",
             ActivationDate = DateTime.Parse("2013-11-05 22:12:28.990"),
             LastLogin = DateTime.Parse("2013-11-05 22:12:28.990")
         });
     }
 }
        /// <summary>
        /// Usuwanie zaznaczonego elementu z tabeli "Users"
        /// </summary>
        private void DeleteRecordFromUsers()
        {
            using (var db = new BusinessCodingModelContex())
            {
                try
                {
                    db.Users.Attach(selectedUser);
                    db.Users.Remove(selectedUser);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error!");
                    return;
                }
                try
                {
                    db.SaveChanges();
                }
                catch
                {
                    MessageBox.Show("Cannot delete a record to which reference is.");
                    return;
                }

                Thread newThread = new Thread(DisplayAllRecordsFromUsers);
                newThread.Start();
            }
        }
        /// <summary>
        /// Dodanie rekordu do tabeli Users.
        /// </summary>
        /// <param name="entryForm">okno z którego pobieramy dane</param>
        private void AddRecordToUsers(object entry)
        {
            Users newUser = (Users)entry;
            using (var db = new BusinessCodingModelContex())
            {
                try
                {
                    newUser.UserID = db.Users.Max(x => x.UserID) + 1;
                }
                catch
                {
                    newUser.UserID = 1;
                }

                db.Users.Add(newUser);

                db.SaveChanges();

                Thread newThread = new Thread(DisplayAllRecordsFromUsers);
                newThread.Start();
            }
        }
        /// <summary>
        /// Dodanie rekordu do tabeli Projects.
        /// </summary>
        /// <param name="entryForm">okno z którego pobieramy dane</param>
        private void AddRecordToProjects(object entry)
        {
            Projects newProject = (Projects)entry;
            using (var db = new BusinessCodingModelContex())
            {
                try
                {
                    newProject.ProjectID = db.Projects.Max(x => x.ProjectID) + 1;
                }
                catch
                {
                    newProject.ProjectID = 1;
                }

                db.Projects.Add(newProject);

                try
                {
                    db.SaveChanges();
                }
                catch
                {
                    MessageBox.Show("You have to add a good reference.");
                    return;
                }

                Thread newThread = new Thread(DisplayAllRecordsFromProjects);
                newThread.Start();
            }
        }
        public void TestAddToCompanies()
        {
            using (var context = new BusinessCodingModelContex())
            {
                Companies tmp = new Companies();
                tmp.CostOfLiving = 12;
                tmp.Money = 3242;
                tmp.Name = "testUnit";
                tmp.Respect = 12;
                var result1 = from x in context.TypesOfOffices where x.Name == "Duże biuro" select x;
                tmp.TypesOfOfficesTOOfficeID = result1.First().TOOfficeID;

                var result2 = from x in context.Users where x.Login == "test3" select x;
                tmp.UsersUserID = result2.First().UserID;

                context.Companies.Add(tmp);
            }
        }
        public void Initialize()
        {
            DbConnection connection = Effort.DbConnectionFactory.CreateTransient();

            _context = new BusinessCodingModelContex(connection);
        }
        public void TestAddToProject()
        {
            using (var context = new BusinessCodingModelContex())
            {
                Projects tmp = new Projects();

                var result1 = from x in context.Companies where x.Name == "Apple Inc." select x;
                tmp.CompaniesCompanyID = result1.First().CompanyID;
                tmp.Complexity = 10;
                tmp.Gratification = 10000;
                tmp.MinCodity = 10;
                tmp.MinRespect = 10;
                tmp.Name = "testUnit";
                tmp.TimeRounds = 10;
                tmp.TimeToEnd = 10;

                context.Projects.Add(tmp);
            }
        }
        /// <summary>
        /// Dodanie rekordu do tabeli Descriptions.
        /// </summary>
        /// <param name="entryForm">okno z którego pobieramy dane</param>
        private void AddRecordToDescriptions(object entry)
        {
            Descriptions newDescription = (Descriptions)entry;
            using (var db = new BusinessCodingModelContex())
            {
                try
                {
                    newDescription.DescriptionID = db.Descriptions.Max(x => x.DescriptionID) + 1;
                }
                catch
                {
                    newDescription.DescriptionID = 1;
                }

                db.Descriptions.Add(newDescription);

                try
                {
                    db.SaveChanges();
                }
                catch
                {
                    MessageBox.Show("You have to add a good reference.");
                    return;
                }

                Thread newThread = new Thread(DisplayAllRecordsFromDescriptions);
                newThread.Start();
            }
        }
        private void ModifyingCompaniesInNewThread()
        {
            using (var db = new BusinessCodingModelContex())
            {
                db.Companies.Attach(selectedCompany);
                var entry = db.Entry(selectedCompany);

                entry.Property(x => x.CostOfLiving).IsModified = true;
                entry.Property(x => x.Money).IsModified = true;
                entry.Property(x => x.Name).IsModified = true;
                entry.Property(x => x.Respect).IsModified = true;
                entry.Property(x => x.TypesOfOfficesTOOfficeID).IsModified = true;
                entry.Property(x => x.UsersUserID).IsModified = true;
                try
                {
                    db.SaveChanges();
                }
                catch
                {
                    MessageBox.Show("You have to give a reference to existing record.");
                }
            }
            Thread newThread = new Thread(DisplayAllRecordsFromCompanies);
            newThread.Start();
        }
        /// <summary>
        /// Dodanie rekordu do tabeli Employees.
        /// </summary>
        /// <param name="entryForm">okno z którego pobieramy dane</param>
        private void AddRecordToEmployees(object entry)
        {
            Empolyees newEmployee = (Empolyees)entry;
            using (var db = new BusinessCodingModelContex())
            {

                try
                {
                    newEmployee.EmployeeID = db.Empolyees.Max(x => x.EmployeeID) + 1;
                }
                catch
                {
                    newEmployee.EmployeeID = 1;
                }
                db.Empolyees.Add(newEmployee);

                try
                {
                    db.SaveChanges();
                }
                catch
                {
                    MessageBox.Show("You have to add a good reference.");
                    return;
                }

                Thread newThread = new Thread(DisplayAllRecordsFromEmployees);
                newThread.Start();
            }
        }
        private void ModifyingDescriptionsInNewThread()
        {
            using (var db = new BusinessCodingModelContex())
            {
                db.Descriptions.Attach(selectedDesciption);
                var entry = db.Entry(selectedDesciption);

                entry.Property(x => x.ProjectsProjectID).IsModified = true;
                entry.Property(x => x.String).IsModified = true;
                try
                {
                    db.SaveChanges();
                }
                catch
                {
                    MessageBox.Show("You have to give a reference to existing record.");
                }
            }
            Thread newThread = new Thread(DisplayAllRecordsFromDescriptions);
            newThread.Start();
        }
        /// <summary>
        /// Dodanie rekordu do tabeli TypesOfOffices.
        /// </summary>
        /// <param name="entryForm">okno z którego pobieramy dane</param>
        private void AddRecordToTypesOfOffices(object entry)
        {
            TypesOfOffices too = (TypesOfOffices)entry;
            using (var db = new BusinessCodingModelContex())
            {
                try
                {
                    too.TOOfficeID = db.TypesOfOffices.Max(x => x.TOOfficeID) + 1;
                }
                catch
                {
                    too.TOOfficeID = 1;
                }

                db.TypesOfOffices.Add(too);

                db.SaveChanges();

                Thread newThread = new Thread(DisplayAllRecordsFromTypesOfOffices);
                newThread.Start();
            }
        }
        private void ModifyingTypeOfOfficesInNewThread()
        {
            using (var db = new BusinessCodingModelContex())
            {
                db.TypesOfOffices.Attach(selectedTypesOfOffice);
                var entry = db.Entry(selectedTypesOfOffice);

                entry.Property(x => x.Capacity).IsModified = true;
                entry.Property(x => x.CostOfHiring).IsModified = true;
                entry.Property(x => x.Name).IsModified = true;

                db.SaveChanges();
            }
            Thread newThread = new Thread(DisplayAllRecordsFromTypesOfOffices);
            newThread.Start();
        }
        /// <summary>
        /// Obsługa przycisku "Execute"
        /// </summary>
        private void buttonExecute_Click(object sender, RoutedEventArgs e)
        {
            int result;
            using (var db = new BusinessCodingModelContex())
            {
                string query = richTextBoxQuery();
                try
                {
                    result = db.Database.ExecuteSqlCommand(query);
                }
                catch
                {
                    MessageBox.Show("Wrong query");
                    return;
                }
                if (result < 0)
                {
                    result = 0;
                }
                MessageBox.Show(string.Format("Result: {0} row(s) affected", result));

                db.SaveChanges();
            }
        }
        private void ModifyingTypesOfEmployeesInNewThread()
        {
            using (var db = new BusinessCodingModelContex())
            {
                db.TypesOfEmployees.Attach(selectedTypesOfEmployee);
                var entry = db.Entry(selectedTypesOfEmployee);

                entry.Property(x => x.Codity).IsModified = true;
                entry.Property(x => x.Name).IsModified = true;
                entry.Property(x => x.Salary).IsModified = true;

                try
                {
                    db.SaveChanges();
                }
                catch
                {
                    MessageBox.Show("You have to give a reference to existing record.");
                }
            }
            Thread newThread = new Thread(DisplayAllRecordsFromTypesOfEmployees);
            newThread.Start();
        }
 /// <summary>
 /// Wyświetlanie wszystkich rekordó z tabeli "Descriptions"
 /// </summary>
 private void DisplayAllRecordsFromDescriptions()
 {
     using (var db = new BusinessCodingModelContex())
     {
         var query = from x in db.Descriptions select x;
         var result = query.ToList();
         dataGrid.InvokeIfRequired((value) => dataGrid.ItemsSource = value, result);
     }
 }
        public void TestAddToEmployee()
        {
            using (var context = new BusinessCodingModelContex())
            {
                Empolyees tmp = new Empolyees();
                tmp.DateOfHiring = DateTime.Parse("2013-11-05 22:12:28.990");

                var result = from x in context.TypesOfEmployees where x.Name == "Senior Developer" select x;
                tmp.TypesOfEmployeesTOEmployeeID = result.First().TOEmployeeID;

                context.Empolyees.Add(tmp);
            }
        }