public ActionResult EditMenuComment(int ID) { Model model = new Model(); try { MenuComment menuComment = model.SELECTMenuComment_WHEREID(ID); if (menuComment != null) { List <Menu> menuList = model.SELECTMenu((Session["User"] as User).ID); //List<MenuComment> menuCommentList = model.SELECTMenuComment_WHERECommentText(menuComment.CommentText, (Session["User"] as User).ID); model.Close(); //return View(Tuple.Create(menuComment, menuList, menuCommentList)); return(View(Tuple.Create(menuComment, menuList))); } else { model.Close(); return(RedirectToAction("Error", "Admin")); } } catch (Exception) { model.Close(); return(RedirectToAction("Error", "Admin")); } }
public ActionResult DeleteConfirmed(int id) { MenuComment menuComment = db.MenuComments.Find(id); db.MenuComments.Remove(menuComment); db.SaveChanges(); return(RedirectToAction("Index")); }
protected void btn_comentar_Click(object sender, EventArgs e) { try { string comentario = txt_comentario.Text.Trim(); if (comentario.Length <= 3) { throw new Exception("Comentário inválido"); } if (Request.Cookies["estrelas"] == null) { throw new Exception("Número de estrelas inválido"); } if (int.Parse(Request.Cookies["estrelas"].Value) <= 0 || int.Parse(Request.Cookies["estrelas"].Value) > 5) { throw new Exception("Número de estrelas inválido"); } int id_menu = int.Parse(Request["id"].ToString()); int estrelas = int.Parse(Request.Cookies["estrelas"].Value); if (Session["id_user"] == null) { throw new Exception("Não estás logado."); } int id_user = int.Parse(Session["id_user"].ToString()); if (Models.Menu.UserOwnsMenu(id_user, id_menu)) { throw new Exception("Não podes comentar num Menu que te pertence."); } MenuComment menuComment = new MenuComment(); menuComment.user = id_user; menuComment.menu = id_menu; menuComment.comment = comentario; menuComment.stars = estrelas; menuComment.Adicionar(); lb_erro_comentario.Visible = false; txt_comentario.Text = ""; LoadComments(); LoadMenuInfo(); } catch (Exception erro) { /*lb_erro_comentario.Text = erro.Message; * lb_erro_comentario.Visible = true;*/ ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "MostrarNotificação", "ShowNotification('Erro','" + erro.Message + "', 'error',4000)", true); return; } }
public ActionResult Edit([Bind(Include = "ID,OrderID,Username,Rating,Text")] MenuComment menuComment) { if (ModelState.IsValid) { db.Entry(menuComment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(menuComment)); }
public ActionResult Create([Bind(Include = "ID,OrderID,Username,Rating,Text")] MenuComment menuComment) { if (ModelState.IsValid) { db.MenuComments.Add(menuComment); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(menuComment)); }
// GET: MenuComments/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MenuComment menuComment = db.MenuComments.Find(id); if (menuComment == null) { return(HttpNotFound()); } return(View(menuComment)); }
public string AddSongMenuComment([FromBody] object json) { JObject j = JObject.Parse(json.ToString()); //获取评论内容 string mid = j["mid"].ToString(); string pid = j["pid"].ToString(); string content = j["content"].ToString(); string from = j["from"].ToString(); string to = j["to"].ToString(); MenuComment c = new MenuComment(); if (mid != "") { c.SM_Menu = int.Parse(mid); } else { return("参数不完整"); } if (pid != "") { c.SM_Pid = int.Parse(pid); } if (content != "") { c.SM_Content = content; } else { return("参数不完整"); } if (from != "") { c.SM_From_User = int.Parse(from); } else { return("参数不完整"); } if (to != "") { c.SM_To_User = int.Parse(to); } else { c.SM_To_User = int.Parse(from); } c.SM_UpTime = DateTime.Now; return(SongMenuService.AddSongMenuComment(c)); }
/// <summary> /// 发布评论 /// </summary> /// <param name="c"></param> /// <returns></returns> internal static string AddSongMenuComment(MenuComment c) { using (YoungMusicEntities db = new YoungMusicEntities()) { db.MenuComment.Add(c); if (db.SaveChanges() > 0) { return("发布成功"); } else { return("发布失败"); } } }
private void LoadComments() { div_comentarios_content.InnerHtml = ""; int id_menu = int.Parse(Request["id"].ToString()); DataTable dados = MenuComment.LoadComments(id_menu); // comment // stars // name // CreateDate foreach (DataRow item in dados.Rows) { string comentario = item["comment"].ToString(); int estrelas = int.Parse(item["stars"].ToString()); string utilizador = item["name"].ToString(); DateTime data = DateTime.Parse(item["CreateDate"].ToString()); string estrelasHtml = ""; for (int i = 1; i < 6; i++) { if (i <= estrelas) { estrelasHtml += "<i class='fas fa-star text-warning'></i>"; } else { estrelasHtml += "<i class='far fa-star text-warning'></i>"; } } div_comentarios_content.InnerHtml += $@" <div class='comentario border p-3 bg-white mt-3'> <div class='d-flex align-items-center justify-content-between'> <span style= ""font-family: 'Roboto', sans-serif !important; font-weight: bold; font-size: 18px;""> {utilizador}</span> <span>{estrelasHtml}</span> </div> <div> <small class='text-muted'>{data}</small> </div> <div class='mt-3'> <span>{comentario}</span> </div> </div>"; } }
public static UserCommentModel GetBlankCommentModel(MenuOrder menuOrder) { List <OrderItem> orderItems = OrderUtils.GetOrderDetails(menuOrder.OrderList); UserCommentModel commentModel = new UserCommentModel(); commentModel.menuOrder = menuOrder; commentModel.menuComments = new List <MenuComment>(); ApplicationDbContext db = new ApplicationDbContext(); foreach (OrderItem orderItem in orderItems) { MenuComment menuComment = new MenuComment(); menuComment.CommentDate = DateTime.Now; menuComment.ItemID = orderItem.ItemID; menuComment.MenuItem = db.MenuItems.FirstOrDefault(item => item.ID == orderItem.ItemID).Name; menuComment.OrderID = menuOrder.ID; menuComment.Username = menuOrder.Username; commentModel.menuComments.Add(menuComment); } return(commentModel); }
public ActionResult UpdateMenuComment(MenuComment menuComment) { int errorCode = InputControl.UpdateMenuCommentControl(menuComment); return(Json(new { result = errorCode })); }
public ActionResult SaveMenuComment(MenuComment menuComment, List <int> menuIDList) { int errorCode = InputControl.SaveMenuCommentControl(menuComment, menuIDList); return(Json(new { result = errorCode })); }
private void AtualizarGrid() { int id_restaurante = -1; if (Request["id"] == null || !int.TryParse(Request["id"].ToString(), out id_restaurante)) { Response.Redirect("~/index.aspx"); } DataTable dados = MenuComment.LoadComments(id_restaurante); dgv_comentarios.Columns.Clear(); dgv_comentarios.DataSource = null; dgv_comentarios.DataBind(); dgv_comentarios.DataSource = dados; dgv_comentarios.AutoGenerateColumns = false; // id // comment // stars // name // CreateDate BoundField bfID = new BoundField(); bfID.HeaderText = "ID"; bfID.DataField = "id"; dgv_comentarios.Columns.Add(bfID); BoundField bfComentario = new BoundField(); bfComentario.HeaderText = "Comentário"; bfComentario.DataField = "comment"; dgv_comentarios.Columns.Add(bfComentario); BoundField bfStars = new BoundField(); bfStars.HeaderText = "Estrelas"; bfStars.DataField = "stars"; dgv_comentarios.Columns.Add(bfStars); BoundField bfUtilizador = new BoundField(); bfUtilizador.HeaderText = "Utilizador"; bfUtilizador.DataField = "name"; dgv_comentarios.Columns.Add(bfUtilizador); BoundField bfCreateDate = new BoundField(); bfCreateDate.HeaderText = "Data"; bfCreateDate.DataField = "CreateDate"; dgv_comentarios.Columns.Add(bfCreateDate); ButtonField dcOpcoes = new ButtonField(); dcOpcoes.HeaderText = "Opções"; dcOpcoes.ButtonType = ButtonType.Link; dgv_comentarios.Columns.Add(dcOpcoes); dgv_comentarios.DataBind(); }
public void UPDATEMenuComment_WHEREID(MenuComment menuComment) { connection.Execute("UPDATE netgarson.dbo.[MenuComment] SET CommentText = @CommentText, Plus = @Plus, Cons = @Cons, IsNew = @IsNew, Active = @Active, Menu_ID = @Menu_ID, User_ID = @User_ID WHERE ID = @ID", new { menuComment.CommentText, menuComment.Plus, menuComment.Cons, menuComment.IsNew, menuComment.Active, menuComment.Menu_ID, menuComment.User_ID, menuComment.ID }); }
public void INSERTMenuComment(MenuComment menuComment) { connection.Execute("INSERT INTO netgarson.dbo.[MenuComment]([CommentText], [Plus], [Cons], [RecordDate], [IsNew], [Active], [Menu_ID], [User_ID]) VALUES (@CommentText, @Plus, @Cons, @RecordDate, @IsNew, @Active, @Menu_ID, @User_ID)", new { menuComment.CommentText, menuComment.Plus, menuComment.Cons, menuComment.RecordDate, menuComment.IsNew, menuComment.Active, menuComment.Menu_ID, menuComment.User_ID }); }