public Comment InsertComment(Comment comment) { using (var conn = GetConnection()) { _logger.AddInfoLog("Establishing connection to database"); try { conn.Open(); var cmd = new MySqlCommand($"insert into comments values({comment.ToString()})", conn); _logger.AddInfoLog("Inserting new comment into database"); cmd.ExecuteNonQuery(); }catch (Exception e) { _logger.AddErrorLog("Error while inserting comennt into database" + e.Message); } } return(comment); }
public User AddUser(User user) { using (var conn = GetConnection()) { try { _logger.AddInfoLog("Establishing connection with database"); conn.Open(); _logger.AddInfoLog($"Inserting new user: {user.ToString()} to database"); var cmd = new MySqlCommand($"insert into users values({user.ToString()})", conn); cmd.ExecuteNonQuery(); } catch (Exception e) { _logger.AddErrorLog($"Error while inserting new user: {user.ToString()}" + e.Message); } } return(user); }
public Restaurant InsertRestaurant(Restaurant restaurant) { using (var conn = GetConnection()) { _logger.AddInfoLog("Establishing connection to dabatase"); try { _logger.AddInfoLog(""); conn.Open(); var cmd = new MySqlCommand($"insert into restaurants values({restaurant.ToString()})", conn); cmd.ExecuteNonQuery(); } catch (Exception e) { _logger.AddErrorLog($"Error while inserting new restaurant: {restaurant.Name}" + e.Message); } } return(restaurant); }
public ActionResult <IEnumerable <Restaurant> > GetAllRestaurants() { _logger.AddInfoLog("Received http get request to get all restaurants"); return(Ok(_service.GetAll())); }