Пример #1
0
        public JsonModel DislikePost(LikeDislike likeDislike)
        {
            JsonModel jsonModel = new JsonModel();

            try
            {
                var result = 0;
                var data   = DbContext.LikeDislikes.Where(x => x.CommentUniqueCode == likeDislike.CommentUniqueCode).FirstOrDefault();
                if (data != null)
                {
                    data.CmntDislike = data.CmntDislike + 1;;
                    DbContext.Entry(likeDislike).State = EntityState.Modified;
                    result = DbContext.SaveChanges();
                }
                else
                {
                    likeDislike.CmntDislike = 1;
                    DbContext.LikeDislikes.Add(likeDislike);
                    result = DbContext.SaveChanges();
                }

                if (result > 0)
                {
                    jsonModel.Status  = true;
                    jsonModel.Message = "Successful";
                    jsonModel.Data    = likeDislike;
                }
                else
                {
                    jsonModel.Status  = false;
                    jsonModel.Message = "Failed";
                    jsonModel.Data    = null;
                }
            }
            catch (Exception ex)
            {
                jsonModel.Status  = false;
                jsonModel.Message = ex.Message;
                jsonModel.Data    = null;
            }
            return(jsonModel);
        }
Пример #2
0
 public ActionResult Delete(int id, FeedBack feedBack)
 {
     try
     {
         using (var db = new FeedBackEntities())
         {
             db.Entry(feedBack).State = EntityState.Deleted;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch
     {
         return(View());
     }
 }