public List<Event> getAllItems() { var connector = DbConnector.Instance; if (!connector.Connected()) connector.Connect(); //Create a list to store the result var results = new List<Event>(); string query = "SELECT * FROM events"; //Create Command MySqlCommand cmd = new MySqlCommand(query, connector.Connection()); MySqlDataReader dataReader = cmd.ExecuteReader(); //Read the data and store them in the list while (dataReader.Read()) { var new_event = new Event((int)dataReader["id"], dataReader["name"].ToString(), (DateTime)dataReader["datetime"], (int)dataReader["location_id"], null, dataReader["description"].ToString()); results.Add(new_event); } //close Data Reader dataReader.Close(); //return list to be displayed return results; }
public EventModel Create(Event e) { return new EventModel() { parent_url = GetRootUrl(), url = GetUrlByApi("EventApi", e.id), //id = e.id, name = e.name, description = e.description, date = e.datetime.ToShortDateString(), time = e.datetime.ToShortTimeString(), teacher_urls = e.teachers.Select(t => this.CreateSummary(t).url).ToList(), location_url = this.CreateSummary(e.location).url, }; }
public BaseModel CreateSummary(Event e) { return new BaseModel() { parent_url = GetRootUrl(), url = GetUrlByApi("EventApi", e.id), name = e.name }; }