Example #1
0
        /// <summary>
        /// Inserts the job and its respective children (only Company and CompanyJob)
        /// into the database.
        /// </summary>
        /// <param name="job"></param>
        /// <returns>Returns true if the job was inserted, returns false if a job with the same
        ///  uuid (primary key) already exists in the table.</returns>
        public bool InsertJob(Job job)
        {
            System.Diagnostics.Debug.WriteLine("DbJob InsertJob(Job job): initiated");
            if (CheckIfJobExist(job.uuid))
            {
                return(false);
            }

            //Job did not exist, safe to insert.
            DbCompany dbCompany = new DbCompany();

            foreach (Company c in job.companies)
            {
                dbCompany.InsertCompany(c);
            }

            lock (DbContext.locker)
            {
                Db.Insert(job);
                // Db.InsertOrReplaceWithChildren(job, recursive: true);
            }

            // This could perhaps be done in the above foreach loop,
            // but because of lack of concurrency control in SQLite its done in its own loop.
            foreach (Company c in job.companies)
            {
                CompanyJob cp = new CompanyJob();
                cp.JobUuid   = job.uuid;
                cp.CompanyId = c.id;
                lock (DbContext.locker)
                {
                    Db.Insert(cp);
                    // Db.InsertOrReplaceWithChildren(job, recursive: true);
                }
            }
            // Job was successfully inserted
            return(true);
        }
        /// <summary>
        /// Inserts the project and its respective children (only Company and CompanyProject) 
        /// into the database.
        /// </summary>
        /// <param name="project"></param>
        /// <returns>Returns true if the project was inserted, returns false if a project with the same 
        ///  uuid (primary key) already exists in the table.</returns>
        public bool InsertProject(Project project)
        {
            System.Diagnostics.Debug.WriteLine("DbProject InsertProject(Project project): initiated");
            if (CheckIfProjectExist(project.uuid))
            {
                return false;
            }

            //Project did not exist, safe to insert.
            DbCompany dbCompany = new DbCompany();

            foreach (Company c in project.companies)
            {
                dbCompany.InsertCompany(c);
            }

            lock (DbContext.locker)
            {
                Db.Insert(project);
                // Db.InsertOrReplaceWithChildren(project, recursive: true);
            }

            // This could perhaps be done in the above foreach loop, 
            // but because of lack of concurrency control in SQLite its done in its own loop.
            foreach (Company c in project.companies)
            {
                CompanyProject cp = new CompanyProject();
                cp.ProjectUuid = project.uuid;
                cp.CompanyId = c.id;
                lock (DbContext.locker)
                {
                    Db.Insert(cp);
                    // Db.InsertOrReplaceWithChildren(project, recursive: true);
                }
            }
            // Project was successfully inserted
            return true;
        }
Example #3
0
        /// <summary>
        /// Inserts the job and its respective children (only Company and CompanyJob) 
        /// into the database.
        /// </summary>
        /// <param name="job"></param>
        /// <returns>Returns true if the job was inserted, returns false if a job with the same 
        ///  uuid (primary key) already exists in the table.</returns>
        public bool InsertJob(Job job)
        {
            System.Diagnostics.Debug.WriteLine("DbJob InsertJob(Job job): initiated");
            if (CheckIfJobExist(job.uuid))
            {
                return false;
            }

            //Job did not exist, safe to insert.
            DbCompany dbCompany = new DbCompany();

            foreach (Company c in job.companies)
            {
                dbCompany.InsertCompany(c);
            }

            lock (DbContext.locker)
            {
                Db.Insert(job);
                // Db.InsertOrReplaceWithChildren(job, recursive: true);
            }

            // This could perhaps be done in the above foreach loop, 
            // but because of lack of concurrency control in SQLite its done in its own loop.
            foreach (Company c in job.companies)
            {
                CompanyJob cp = new CompanyJob();
                cp.JobUuid = job.uuid;
                cp.CompanyId = c.id;
                lock (DbContext.locker)
                {
                    Db.Insert(cp);
                    // Db.InsertOrReplaceWithChildren(job, recursive: true);
                }
            }
            // Job was successfully inserted
            return true;
        }
Example #4
0
        /// <summary>
        /// Inserts the project and its respective children (only Company and CompanyProject)
        /// into the database.
        /// </summary>
        /// <param name="project"></param>
        /// <returns>Returns true if the project was inserted, returns false if a project with the same
        ///  uuid (primary key) already exists in the table.</returns>
        public bool InsertProject(Project project)
        {
            System.Diagnostics.Debug.WriteLine("DbProject InsertProject(Project project): initiated");
            if (CheckIfProjectExist(project.uuid))
            {
                return(false);
            }

            //Project did not exist, safe to insert.
            DbCompany dbCompany = new DbCompany();

            foreach (Company c in project.companies)
            {
                dbCompany.InsertCompany(c);
            }

            lock (DbContext.locker)
            {
                Db.Insert(project);
                // Db.InsertOrReplaceWithChildren(project, recursive: true);
            }

            // This could perhaps be done in the above foreach loop,
            // but because of lack of concurrency control in SQLite its done in its own loop.
            foreach (Company c in project.companies)
            {
                CompanyProject cp = new CompanyProject();
                cp.ProjectUuid = project.uuid;
                cp.CompanyId   = c.id;
                lock (DbContext.locker)
                {
                    Db.Insert(cp);
                    // Db.InsertOrReplaceWithChildren(project, recursive: true);
                }
            }
            // Project was successfully inserted
            return(true);
        }