public async Task <ActionResult <string> > AddComment([FromBody] FnbComment c) { var fnb = await dbHelper.GetFnbByIdAsync(c.FnbId); if (fnb == null) { return("FnB Not found"); } var r = await dbHelper.AddFnbCommentAsync(c.FnbId, c.CommenterId, c.Comment, c.Rating, c.BaseRating); return(r.Message); }
public async Task <List <FnbComment> > ListAllFnbCommentAsync(int fnbId) { try { List <FnbComment> fnbCommentList = new List <FnbComment>(); string sql = $"SELECT * FROM fnb_comment WHERE fnb_id = '{fnbId}';"; using (MySqlConnection connection = new MySqlConnection(dbConString)) { await connection.OpenAsync(); using (MySqlCommand cmd = new MySqlCommand(sql, connection)) { using (var reader = await cmd.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { var fnbComment = new FnbComment { Id = int.Parse(GetStringValue(reader["id"])), FnbId = int.Parse(GetStringValue(reader["fnb_id"])), CommenterId = int.Parse(GetStringValue(reader["commenter_id"])), Comment = GetStringValue(reader["comment"]), Rating = int.Parse(GetStringValue(reader["rating"])), BaseRating = (BaseRating)int.Parse(GetStringValue(reader["base_rating"])), CreatedTime = GetDateTimeValue(reader["created_time"]).Value.ToLocalTime(), }; fnbCommentList.Add(fnbComment); } } } } return(fnbCommentList); } catch (Exception ex) { //LOGGER.LogDbException(ex); return(new List <FnbComment>()); } }
public async Task <string> AddFnbCommentAsync(int fnbId, string comment, int rating, int commenterId) { try { FnbComment fnbComment = new FnbComment { FnbId = fnbId, Comment = comment, Rating = rating, CommenterId = commenterId, BaseRating = BaseRating.Ten }; var resp = await client.PostAsJsonAsync($"api/fnb-comment/add", fnbComment); return(await resp.Content.ReadAsStringAsync()); } catch (Exception ex) { return(ex.Message); } }