/// <summary>
        /// [Delete Product Like
        /// </summary>
        /// <param name="productID">Product ID</param>
        /// <param name="userID">User ID</param>
        /// <returns>True or False</returns>
        public static bool DeleteProductLike(int productID, int userID)
        {
            try
            {
                ProductLike pro = (from ProductLike item in db.ProductLikes
                                   where item.ProductId == productID && item.UserId == userID
                                   select item).FirstOrDefault();
                if (pro != null)
                {
                    Product _pro = db.Products.Find(pro.ProductId);
                    db.ProductLikes.Attach(pro);
                    db.ProductLikes.Remove(pro);

                    if (_pro.TotalLikes != null)
                    {
                        _pro.TotalLikes = _pro.TotalLikes - 1;
                    }
                    db.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
 /// <summary>
 /// Delete Product Like
 /// </summary>
 /// <param name="pro">Object ProductLike</param>
 /// <returns>True or False</returns>
 public static bool DeleteProductLike(ProductLike pro)
 {
     try
     {
         if (pro != null)
         {
             db.ProductLikes.Attach(pro);
             db.ProductLikes.Remove(pro);
             Product _pro = db.Products.Find(pro.ProductId);
             if (_pro.TotalLikes != null)
             {
                 _pro.TotalLikes = _pro.TotalLikes - 1;
             }
             db.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
        /// <summary>
        /// [Add Product Like
        /// </summary>
        /// <param name="productID">Product ID</param>
        /// <param name="userID">User ID</param>
        /// <returns>True or False</returns>
        public static bool AddProductLike(int productID, int userID)
        {
            try
            {
                ProductLike item = new ProductLike();
                item.ProductId = productID;
                item.UserId    = userID;
                db.ProductLikes.Add(item);
                Product pro = db.Products.Find(productID);

                if (pro.TotalLikes != null)
                {
                    pro.TotalLikes = pro.TotalLikes + 1;
                }
                else
                {
                    pro.TotalLikes = 1;
                }
                db.SaveChanges();

                // Publish Message
                bool pubResult = Message_Logic.PublishMessage(
                    userID, Constant.PRONOUN_TYPE_USER,
                    productID, Constant.PRONOUN_TYPE_PRODUCT,
                    Constant.MESSAGE_TYPE_LIKE);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ProductLike productLike = db.ProductLikes.Find(id);

            db.ProductLikes.Remove(productLike);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Id,ProductId,UserId,DateTime,IP")] ProductLike productLike)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productLike).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductId = new SelectList(db.Products, "Id", "Name", productLike.ProductId);
     ViewBag.UserId    = new SelectList(db.Users, "Id", "Name", productLike.UserId);
     return(View(productLike));
 }
        // GET: ProductLike/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductLike productLike = db.ProductLikes.Find(id);

            if (productLike == null)
            {
                return(HttpNotFound());
            }
            return(View(productLike));
        }
Exemplo n.º 7
0
        public ActionResult Edit([Bind(Include = "Id,ProductId,UserId,DateTime,Ip")] ProductLike productlike)
        {
            productlike.Ip       = Request.UserHostAddress;
            productlike.DateTime = DateTime.Now;
            if (ModelState.IsValid)
            {
                db.Entry(productlike).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.ProductId = new SelectList(db.Products.Where(p => p.ProductLikes.Count <= 0), "Id", "Name", productlike.ProductId);

            return(View(productlike));
        }
        // GET: ProductLike/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductLike productLike = db.ProductLikes.Find(id);

            if (productLike == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ProductId = new SelectList(db.Products, "Id", "Name", productLike.ProductId);
            ViewBag.UserId    = new SelectList(db.Users, "Id", "Name", productLike.UserId);
            return(View(productLike));
        }
Exemplo n.º 9
0
        public ActionResult Create([Bind(Include = "Id,ProductId,UserId,DateTime,Ip")] ProductLike productlike)
        {
            productlike.Ip       = Request.UserHostAddress;
            productlike.DateTime = DateTime.Now;
            productlike.UserId   = (int)Session["id"];

            if (ModelState.IsValid)
            {
                db.ProductLikes.Add(productlike);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ProductId = new SelectList(db.Products.Where(p => p.ProductLikes.Count <= 0), "Id", "Name", productlike.ProductId);

            return(View(productlike));
        }
Exemplo n.º 10
0
        // GET: /ProductLike/Delete/5
        public ActionResult Delete(int?id)
        {
            if (Session["type"] == null || Session["type"] == "")
            {
                Session["dv"] = "Delete";
                Session["dc"] = "ProductLike";
                return(RedirectToAction("Login", "Users"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductLike productlike = db.ProductLikes.Find(id);

            if (productlike == null)
            {
                return(HttpNotFound());
            }
            return(View(productlike));
        }
Exemplo n.º 11
0
 /// <summary>
 /// Check Like Product User ID
 /// </summary>
 /// <param name="productID"> product ID</param>
 /// <param name="userID"> user ID </param>
 /// <returns>return True is exsits and Flase is not exsits</returns>
 public static bool CheckLikeProductUserID(int productID, int userID)
 {
     try
     {
         ProductLike pro = (from ProductLike item in db.ProductLikes
                            where item.ProductId == productID && item.UserId == userID
                            select item).FirstOrDefault();
         if (pro != null)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 12
0
 /// <summary>
 /// Add Product Like
 /// </summary>
 /// <param name="item">ProductLike object</param>
 /// <returns>True or False</returns>
 public static bool AddProductLike(ProductLike item)
 {
     try
     {
         db.ProductLikes.Add(item);
         Product pro = db.Products.Find(item.ProductId);
         if (pro.TotalLikes != null)
         {
             pro.TotalLikes = pro.TotalLikes + 1;
         }
         else
         {
             pro.TotalLikes = 1;
         }
         db.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 13
0
        // GET: /ProductLike/Edit/5
        public ActionResult Edit(int?id)
        {
            if (Session["type"] == null || Session["type"] == "")
            {
                Session["dv"] = "Edit";
                Session["dc"] = "ProductLike";
                return(RedirectToAction("Login", "Users"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductLike productlike = db.ProductLikes.Find(id);

            if (productlike == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ProductId = new SelectList(db.Products.Where(p => p.ProductLikes.Count <= 0), "Id", "Name", productlike.ProductId);

            return(View(productlike));
        }