public ActionResult DeleteConfirmed(int id)
        {
            RestaurantComment restaurantComment = db.RestaurantComments.Find(id);

            db.RestaurantComments.Remove(restaurantComment);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        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_restaurante = int.Parse(Request["id"].ToString());
                int id_user        = int.Parse(Session["id_user"].ToString());
                if (Session["id_user"] == null)
                {
                    throw new Exception("Não estás logado.");
                }

                if (Restaurant.UserOwnsRestaurant(id_restaurante, id_user))
                {
                    throw new Exception("Não podes comentar no teu próprio restaurante");
                }

                int estrelas = int.Parse(Request.Cookies["estrelas"].Value);

                Request.Cookies["estrelas"].Expires = DateTime.Now.AddDays(-1);

                RestaurantComment restaurantComment = new RestaurantComment();
                restaurantComment.user       = id_user;
                restaurantComment.restaurant = id_restaurante;
                restaurantComment.comment    = comentario;
                restaurantComment.stars      = estrelas;

                restaurantComment.Adicionar();

                lb_erro_comentario.Visible = false;
                txt_comentario.Text        = "";
                LoadComments();
            }
            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;
            }
        }
Exemplo n.º 3
0
        public JsonResult DeleteComment(int deleteid)
        {
            RestaurantComment delComment = db.RestaurantComments.Find(deleteid);

            db.RestaurantComments.Remove(delComment);
            db.SaveChanges();

            return(Json(2));
        }
 public ActionResult Edit([Bind(Include = "CommentId,Content,UserId,RestaurantId")] RestaurantComment restaurantComment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(restaurantComment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.RestaurantId = new SelectList(db.Restaurants, "RestaurantId", "RestaurantName", restaurantComment.RestaurantId);
     ViewBag.UserId       = new SelectList(db.Users, "UserId", "NameSurname", restaurantComment.UserId);
     return(View(restaurantComment));
 }
        // GET: Panel/RestaurantComments/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RestaurantComment restaurantComment = db.RestaurantComments.Find(id);

            if (restaurantComment == null)
            {
                return(HttpNotFound());
            }
            return(View(restaurantComment));
        }
        // GET: Panel/RestaurantComments/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RestaurantComment restaurantComment = db.RestaurantComments.Find(id);

            if (restaurantComment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.RestaurantId = new SelectList(db.Restaurants, "RestaurantId", "RestaurantName", restaurantComment.RestaurantId);
            ViewBag.UserId       = new SelectList(db.Users, "UserId", "NameSurname", restaurantComment.UserId);
            return(View(restaurantComment));
        }
Exemplo n.º 7
0
        private void LoadComments()
        {
            div_comentarios_content.InnerHtml = "";
            int id_restaurante = int.Parse(Request["id"].ToString());

            DataTable dados = RestaurantComment.LoadComments(id_restaurante);

            // 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>";
            }
        }
Exemplo n.º 8
0
        public ActionResult RestaurantDetail(string Content, int id)
        {
            RestaurantComment rComment = new RestaurantComment();

            rComment.Content      = Content;
            rComment.RestaurantId = id;
            int idUser = Convert.ToInt32(Session["EnterID"]);

            rComment.User = db.Users.Find(idUser);

            db.RestaurantComments.Add(rComment);
            db.SaveChanges();

            Restaurant rest = (from r in db.Restaurants where r.RestaurantId == id select r).FirstOrDefault();

            ViewBag.Comment = db.RestaurantComments.Where(x => x.RestaurantId == id).ToList();

            return(View(rest));
        }
        private void AtualizarGrid()
        {
            int id_restaurante = -1;

            if (Request["restaurante"] == null || !int.TryParse(Request["restaurante"].ToString(), out id_restaurante))
            {
                Response.Redirect("~/index.aspx");
            }

            DataTable dados = RestaurantComment.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();
        }