Пример #1
0
        public void InsertCourseProject(string courseId, string projectUuid)
        {
            CourseProject cp = new CourseProject();
            cp.CourseId = Hasher.Base64Encode(courseId);
            cp.ProjectUuid = projectUuid;

            lock (DbContext.locker)
            {
                var rowsAffected =
                    Db.Query<CourseProject>("Select * FROM CourseProject WHERE CourseProject.CourseId = ?" +
                                            " AND CourseProject.ProjectUuid = ?", cp.CourseId, cp.ProjectUuid).Count;
                System.Diagnostics.Debug.WriteLine("Deserialize: CourseProject rowsAffected: " +
                                                    rowsAffected);
                if (rowsAffected == 0)
                {
                    // The item does not exists in the database so safe to insert
                    Db.Insert(cp);
                }
            }
        }
        private async void TestInsertProject(object sender, EventArgs e)
        {
            DbContext DbContext = DbContext.GetDbContext;
            SQLiteConnection Db = DbContext.Db;

            System.Diagnostics.Debug.WriteLine("Before insert Project.Count: " +
                                               Db.Query<Project>("Select * from Project").Count());

            ProjectsController jc = new ProjectsController();


            string testUuid = "colemak";
            Project project = new Project()
            {
                uuid = testUuid,
            };

            string companyId = "Ikea";
            Company comp = new Company()
            {
                id = companyId
            };

            string courseId = "sverige";
            Course course = new Course()
            {
                id = courseId
            };

            string sgId = "dykking";
            StudyGroup sg = new StudyGroup()
            {
                id = sgId
            };

            StudyGroupProject sgj = new StudyGroupProject()
            {
                StudyGroupId = sgId,
                ProjectUuid = testUuid
            };

            CourseProject lj = new CourseProject()
            {
                CourseId = courseId,
                ProjectUuid = testUuid
            };

            CompanyProject cp = new CompanyProject()
            {
                CompanyId = companyId,
                ProjectUuid = testUuid
            };

            string jtId = "10aarErfaringEcma6";
            JobType jt = new JobType()
            {
                id = jtId
            };

            JobTypeProject jtp = new JobTypeProject()
            {
                ProjectUuid = testUuid,
                JobTypeId = jtId
            };

            // try catch on tables that will not be affected by a job delete
            try
            {
                Db.Insert(comp);
            }
            catch
            {
            }
            Db.Insert(project);
            try
            {
                Db.Insert(course);
            }
            catch
            {
            }
            try
            {
                Db.Insert(sg);
            }
            catch
            {
            }
            Db.Insert(sgj);
            Db.Insert(lj);
            Db.Insert(cp);
            try
            {
                Db.Insert(jt);
            }
            catch
            {
            }
            Db.Insert(jtp);

            System.Diagnostics.Debug.WriteLine("After insert: Project.Count: " +
                                               Db.Query<Project>("Select * from Project").Count());
        }