コード例 #1
0
 public JsonResult DeleteComment(int id)
 {
     try
     {
         Product_Rates productrate = db.Product_Rates.Find(id);
         db.Product_Rates.Remove(productrate);
         db.SaveChanges();
         return(Json(id));
     }
     catch
     {
         return(Json(0));
     }
 }
コード例 #2
0
 public JsonResult HideShowComment(int id, bool visible)
 {
     try
     {
         Product_Rates productrate = db.Product_Rates.Find(id);
         productrate.Avaiable        = visible;
         db.Entry(productrate).State = EntityState.Modified;
         db.SaveChanges();
         return(Json(id));
     }
     catch
     {
         return(Json(0));
     }
 }
コード例 #3
0
        public IHttpActionResult RateProduct(int Product_ID)
        {
            string Token   = HttpContext.Current.Request.Form["Token"];
            string Rate    = HttpContext.Current.Request.Form["Rate"];
            string Comment = HttpContext.Current.Request.Form["Comment"];

            User user = db.Users.SingleOrDefault(x => x.Token == Token);

            //Check If User Rate Provider Once And Edit The Rate
            #region Last Rate
            var lastrate = user.Product_Rates.SingleOrDefault(x => x.Product_ID == Product_ID);
            if (lastrate != null)
            {
                if (!string.IsNullOrEmpty(Rate))
                {
                    lastrate.Rate = Convert.ToDouble(Rate);
                }
                if (!string.IsNullOrEmpty(Comment))
                {
                    lastrate.Comment = Comment;
                }
                db.Entry(lastrate).State = EntityState.Modified;
                db.SaveChanges();
                return(Ok(new { key = true, Message = "تم تعديل تقييم هذا المنتج" }));
            }
            #endregion
            //Add New Rate If No Rates
            #region New Rate
            Product_Rates rate = new Product_Rates {
                Product_ID = Product_ID, User_ID = user.ID
            };
            if (!string.IsNullOrEmpty(Rate))
            {
                rate.Rate = Convert.ToDouble(Rate);
            }
            if (!string.IsNullOrEmpty(Comment))
            {
                rate.Comment = Comment;
            }
            db.Product_Rates.Add(rate);
            db.SaveChanges();
            return(Ok(new { key = true, Message = "تم تقييم هذا المنتج " }));

            #endregion
        }