示例#1
0
		/// <summary>
		/// Inserts a project in the database
		/// </summary>
		/// <param name="project"></param>
		public void InsertProject(Project project)
		{
			var currentDatabase = db;

			if (project == null)
			{
				throw new ArgumentNullException("project must not be null");
			}

			if (currentDatabase == null)
			{
				return;
			}
			try
			{
				
				currentDatabase.BeginTransaction();
				SQLiteCommand cmd = currentDatabase.CreateCommand(SQL_PROJECT_INSERT,
													 project.Name, project.Description);
				int numberOfRowsAffected = cmd.ExecuteNonQuery();
				currentDatabase.CommitTransaction();
			}
			catch (SQLiteException ex)
			{
				if (currentDatabase.TransactionOpened)
					currentDatabase.RollbackTransaction();
				throw ex;
			}
		}
		/// <summary>
		/// Inserts a project in the database
		/// </summary>
		/// <param name="project"></param>
		public void InsertProjectAndSync(Project project)
		{
			ProjectDataContext.InsertProjectAndSync(project);
		}
		/// <summary>
		/// Inserts a project in the database
		/// </summary>
		/// <param name="project"></param>
		public void InsertProject(Project project)
		{
			ProjectDataContext.InsertProject(project);
		}
		/// <summary>
		/// Delete project from the database
		/// </summary>
		/// <param name="project"></param>
		public void DeleteProject(Project project)
		{
			ProjectDataContext.DeleteProject(project);
		}
		public void InsertOrUpdateProject(Project project)
		{
			ProjectDataContext.InsertOrUpdateProject(project);
		}
		/// <summary>
		/// Update project in the database
		/// </summary>
		/// <param name="project"></param>
		public void UpdateProject(Project project)
		{
			ProjectDataContext.UpdateProject(project);
		}
示例#7
0
		/// <summary>
		/// Inserts a project in the database
		/// </summary>
		/// <param name="project"></param>
		public void InsertProjectAndSync(Project project)
		{
			var currentDatabase = db;

			if (project == null)
			{
				throw new ArgumentNullException("project must not be null");
			}

			if (currentDatabase == null)
			{
				return;
			}
			try
			{
				
				currentDatabase.BeginTransaction();
				//save new project
				SQLiteCommand cmd = currentDatabase.CreateCommand(SQL_PROJECT_INSERT,
													 project.Name, 
													 project.Description
													 );
				int numberOfRowsAffected = cmd.ExecuteNonQuery();
				
				//load new inserted project
				SQLiteCommand cmdLoad = currentDatabase.CreateCommand(SQL_SELECT_LAST_INSERT_ID);
				var lastRowIdResult = cmdLoad.ExecuteQuery<ScalarIdColumn>();
				var lastRowId = lastRowIdResult.FirstOrDefault();

				int lastId = lastRowId.Id;

				//set new values
				project.ProjectId = lastId;
				currentDatabase.CommitTransaction();
			}
			catch (SQLiteException ex)
			{
				if (currentDatabase.TransactionOpened)
					currentDatabase.RollbackTransaction();
				throw ex;
			}
		}
示例#8
0
		/// <summary>
		/// Delete project from the database
		/// </summary>
		/// <param name="project"></param>
		public void DeleteProject(Project project)
		{
			if (project == null)
			{
				throw new ArgumentNullException("project must not be null");
			}

			int projectId = project.ProjectId;

			this.DeleteProjectById(projectId);
		}
示例#9
0
		public void InsertOrUpdateProject(Project project)
		{
			if (project == null)
			{
				throw new ArgumentNullException("project must not be null");
			}

			int projectId = project.ProjectId;
			if (projectId == 0)
			{
				this.InsertProjectAndSync(project);
			}
			else
			{
				this.UpdateProject(project);
			}
		}
示例#10
0
		/// <summary>
		/// Update project in the database
		/// </summary>
		/// <param name="project"></param>
		public void UpdateProject(Project project)
		{
			if (project == null)
			{
				throw new ArgumentNullException("project must not be null");
			}

			if (db == null)
			{
				return;
			}
			try
			{
				db.BeginTransaction();
				SQLiteCommand cmd = db.CreateCommand(SQL_PROJECT_UPDATE,
													  project.Name,
													  project.Description,
													  project.ProjectId);
				int numberOfRowsAffected = cmd.ExecuteNonQuery();
				db.CommitTransaction();
			}
			catch (SQLiteException ex)
			{
				if (db.TransactionOpened)
					db.RollbackTransaction();
				throw ex;
			}
		}