public courseClass courseInfo(string course, string user) { courseClass response = new courseClass(); SqlConnection con = new SqlConnection(data); SqlCommand cmd = new SqlCommand("SELECT * FROM courseData WHERE courseId = @courseId", con); cmd.Parameters.AddWithValue("@courseId", new Guid(course)); SqlDataReader Dr; con.Open(); Dr = cmd.ExecuteReader(); if (Dr.Read()) { response.courseId = new Guid(Dr["courseId"].ToString()); response.name = Dr["courseName"].ToString(); response.creator = new Guid(Dr["creator"].ToString()); response.company = new Guid(Dr["company"].ToString()); response.created = DateTime.Parse(Dr["created"].ToString()); response.status = Dr["status"].ToString(); response.information = Dr[""].ToString(); response.img = Dr["img"].ToString(); response.price = Convert.ToInt32(Dr["price"]); response.currency = Dr["currency"].ToString(); response.duration = Convert.ToInt32(Dr["duration"]); response.durationUnit = Dr["durationUnit"].ToString(); } Dr.Close(); con.Close(); return(response); }
public IEnumerable <courseClass> courseInfo(string courseId) { IcourseClient client = new IcourseClient(); courseClass cou = client.courseInfo(courseId, new Guid().ToString());; List <courseClass> response = new List <courseClass>(); response.Add(cou); return(response); }
public string courseUpdate(courseClass list) { courseUpdate update = new courseUpdate(); IcourseClient client = new IcourseClient(); string response = "Error"; try { update.status = list.status; update.information = list.information; update.price = list.price; update.currency = list.currency; update.duration = list.duration; update.durationUnit = list.durationUnit; response = client.updateString(list.courseId.ToString(), update); } catch { // Error } return(response); }
public List <courseClass> fetchCourses(int fetch, int jump) { fetch = fetch <= 0 ? 20 : fetch; jump = jump < 0 ? 0 : jump; List <courseClass> response = new List <courseClass>(); try { SqlConnection con = new SqlConnection(data); SqlCommand cmd = new SqlCommand("SELECT * FROM courseData ORDER BY created DESC", con); SqlDataReader Dr; con.Open(); Dr = cmd.ExecuteReader(); while (Dr.Read()) { try { courseClass reader = new courseClass(); //reader.courseId = Dr.GetGuid(0); //reader.name = Dr.GetString(1) == null ? "GeneralName" : Dr.GetString(1); //reader.creator = Dr.GetGuid(2); //reader.company = Dr.GetGuid(3); //reader.status = Dr.GetString(4) == null ? "GeneralName" : Dr.GetString(4); //reader.information = Dr.GetString(5) == null ? "GeneralName" : Dr.GetString(5); //reader.price = Dr.GetInt32(7).ToString() == null ? 0 : Dr.GetInt32(7); //reader.currency = Dr.GetString(8) == null ? "GeneralName" : Dr.GetString(8); //reader.duration = Dr.GetInt32(9).ToString() == null ? 0 : Dr.GetInt32(9); //reader.durationUnit = Dr.GetString(10) == null ? "GeneralName" : Dr.GetString(10); // Experimental reader.courseId = Dr.GetGuid(0); if (Dr.GetString(1) != null) { reader.name = Dr.GetString(1); } if (Dr.GetGuid(2) != null) { reader.creator = Dr.GetGuid(2); } //if (Dr.GetGuid(3) != null) { reader.company = Dr.GetGuid(3); } reader.created = Dr.GetDateTime(4); if (Dr.GetString(5) != null) { reader.status = Dr.GetString(5); } if (Dr.GetString(6) != null) { reader.information = Dr.GetString(6); } reader.price = 49; reader.currency = "EUR"; reader.duration = 6; reader.durationUnit = "DAY"; response.Add(reader); } catch (Exception ex) { courseClass reader = new courseClass(); reader.status = ex.ToString(); response.Add(reader); continue; } } Dr.Close(); con.Close(); if (response.Count <= 0) { for (int i = 0; i < 5; i++) { courseClass reader = new courseClass(); reader.name = "MyCourse" + i; reader.information = "My new Course is about something cool"; response.Add(reader); } } return(response); } catch (SqlException ex) { courseClass reader = new courseClass(); reader.courseId = new Guid(); reader.name = ""; reader.creator = new Guid(); reader.company = new Guid(); reader.created = DateTime.Now; reader.status = ""; reader.information = ex.ToString(); reader.img = ""; reader.price = 0; reader.currency = ""; reader.duration = 0; reader.durationUnit = ""; response.Add(reader); } catch (Exception e) { // Add error reporting courseClass reader = new courseClass(); reader.courseId = new Guid(); reader.name = ""; reader.creator = new Guid(); reader.company = new Guid(); reader.created = DateTime.Now; reader.status = ""; reader.information = e.ToString(); reader.img = ""; reader.price = 1; reader.currency = ""; reader.duration = 1; reader.durationUnit = ""; response.Add(reader); } return(response); }