/// <summary> /// Insert /// </summary> /// <param name="reader"></param> /// <param name="project"></param> public static void DBFill(SqliteDataReader reader, Project project) { project.ProjectID = Convert.ToInt32(reader["project_id"]); project.ProjectName = reader["project_name"].ToString(); project.ProjectDescription = reader["project_description"].ToString(); project.ProjectHtml = reader["project_html"].ToString(); if (reader ["parent_id"] != DBNull.Value) { project.ParentID = Convert.ToInt32 (reader ["parent_id"]); } if (reader["project_added_by"] != null) { project.ProjectAddedById = Convert.ToInt32(reader["project_added_by"]); } if (reader["project_photo_id"] != null) { project.ProjectImageID = Convert.ToInt32(reader["project_photo_id"]); } project.ProjectHide = Convert.ToBoolean(reader["project_hide"]); }
/// <summary> /// Gets as single project by id /// </summary> /// <param name="projectId"></param> /// <returns></returns> public static Project GetById(int projectId) { Project project = new Project(); string query = "SELECT * FROM kk_project WHERE project_id = @project_id;"; // get database connection using (SqliteConnection conn = new SqliteConnection(connectionString)) { conn.Open(); // execute cmd using (SqliteCommand cmd = new SqliteCommand(query, conn)) { cmd.Parameters.Add("@project_id", System.Data.DbType.Int32).Value = projectId; // user reader to fill data using (SqliteDataReader reader = cmd.ExecuteReader()) { reader.Read(); Project.DBFill(reader, project); } } } return project; }
private static List<Project> GetList(string query, List<SqliteParameter> parameters = null) { List<Project> projects = new List<Project>(); // get database connection using (SqliteConnection conn = new SqliteConnection(connectionString)) { conn.Open(); // execute cmd using (SqliteCommand cmd = new SqliteCommand(query, conn)) { if (parameters != null) { foreach (SqliteParameter param in parameters) { cmd.Parameters.Add (param); } } // user reader to fill data using (SqliteDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { Project project = new Project(); Project.DBFill(reader, project); projects.Add(project); } } } } return projects; }
public ContentResult Save(int? project_id, string proj_name, bool? proj_display, int? photo_id, string proj_html, int? parent_id) { Session.Remove("temp_image_data"); Project project = new Project(); if (project_id != null) { project = Project.GetById(Convert.ToInt32(project_id)); } project.ParentID = parent_id; project.ProjectName = proj_name; project.ProjectHtml = proj_html; project.ProjectHide = proj_display == null ? false : Convert.ToBoolean(proj_display); if (photo_id != null) { project.ProjectImageID = Convert.ToInt32(photo_id); } project.Save(); string result = string.Format("{{ result : 'success', data : {{ project_id :{0} }}", project.ProjectID); return new ContentResult { Content = result }; }