Пример #1
0
        public ActionResult DeleteShare(int id)
        {
            using (SharingManager sharingManager = new SharingManager())
            {
                var v = sharingManager.ListQueryable().Where(a => a.Id == id).FirstOrDefault();


                v.isDelete = true;
                var    oldPhoto          = string.Empty;
                var    oldPhotoRes       = sharingManager.Find(x => x.Id == id).ImageUrl;
                string defaultShareImage = oldPhotoRes.Split('/')[3];
                if (defaultShareImage != "sitelogo.png")
                {
                    oldPhoto = HttpContext.Server.MapPath("~" + oldPhotoRes);
                }


                if (System.IO.File.Exists(oldPhoto))
                {
                    System.IO.File.Delete(oldPhoto);
                }



                if (sharingManager.Update(v) > 0)
                {
                    return(Json(new { Result = true }, JsonRequestBehavior.AllowGet));
                }

                return(Json(new { Result = false }, JsonRequestBehavior.AllowGet));
            }
        }
Пример #2
0
        public ActionResult SetLikeState(int noteid, bool liked)
        {
            using (LikedManager likedManager = new LikedManager())
            {
                using (SharingManager sharingManager = new SharingManager())
                {
                    int     result = 0;
                    Liked   like   = likedManager.Find(x => x.Shareing.Id == noteid && x.likedUser.Id == CurrentSession.shareBookUser.Id && !x.likedUser.isDeleted && !x.Shareing.isDelete);
                    Sharing share  = sharingManager.Find(x => x.Id == noteid && !x.Owner.isDeleted && !x.isDelete && !x.Owner.isDeleted);


                    if (like != null && liked == false)
                    {
                        result = likedManager.Delete(like);
                    }
                    else if (like == null && liked == true)
                    {
                        result = likedManager.Insert(new Liked()
                        {
                            likedUser = CurrentSession.shareBookUser,
                            Shareing  = share
                        });
                    }

                    if (result > 0)
                    {
                        if (liked)
                        {
                            share.LikeCount++;
                        }
                        else
                        {
                            share.LikeCount--;
                        }
                        sharingManager.Update(share);

                        return(Json(new { hasError = false, errorMessage = string.Empty, result = share.Likes.Where(x => !x.likedUser.isDeleted).ToList().Count }));
                    }


                    return(Json(new { hasError = true, errorMessage = "Beğenme işlemi gerçekleştirilemedi", result = share.Likes.Where(x => !x.likedUser.isDeleted).ToList().Count }));
                }
            }
        }
Пример #3
0
 // Pumps the network message loop
 public void Update()
 {
     SharingManager?.Update();
 }
Пример #4
0
        public ActionResult SaveDataInDatabase(Sharing sharing, HttpPostedFileBase file)
        {
            using (SharingManager sharingManager = new SharingManager())
            {
                int result = -1;
                if (ModelState.IsValid)
                {
                    if (sharing.Id > 0)
                    {
                        var currShare = sharingManager.ListQueryable().Where(a => a.Id == sharing.Id && !a.isDelete).Include(x => x.Category).FirstOrDefault();
                        if (currShare != null)
                        {
                            string oldPhoto = string.Empty;


                            var oldPhotoRes = sharingManager.Find(x => x.Id == sharing.Id).ImageUrl;
                            // oldPhoto = HttpContext.Server.MapPath("~" + oldPhotoRes);
                            string defaultShareImage = oldPhotoRes.Split('/')[3];
                            if (defaultShareImage != "sitelogo.png")
                            {
                                oldPhoto = HttpContext.Server.MapPath("~" + oldPhotoRes);
                            }
                            if (file != null)
                            {
                                if (System.IO.File.Exists(oldPhoto))
                                {
                                    System.IO.File.Delete(oldPhoto);
                                }

                                FileHelper fileHelper = new FileHelper();
                                var        imgPath    = Server.MapPath("~/Images/SharingImage");

                                currShare.ImageUrl = fileHelper.SaveImage(file, imgPath, "/Images/SharingImage");
                            }
                            currShare.isDraft      = sharing.isDraft;
                            currShare.CategoryId   = sharing.CategoryId;
                            currShare.ShareContent = sharing.ShareContent;
                            currShare.Title        = sharing.Title;
                            sharingManager.Update(currShare);
                            result = 1;
                        }
                    }
                    else
                    {
                        if (file != null)
                        {
                            FileHelper fileHelper = new FileHelper();
                            var        imgPath    = Server.MapPath("~/Images/SharingImage");

                            sharing.ImageUrl = fileHelper.SaveImage(file, imgPath, "/Images/SharingImage");
                        }
                        else
                        {
                            sharing.ImageUrl = "/Images/SharingImage/sitelogo.png";
                        }
                        sharing.Owner = CurrentSession.shareBookUser;
                        sharingManager.Insert(sharing);

                        result = 2;
                    }

                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(View(sharing));
                }
            }
        }
Пример #5
0
 private void NetworkUpdate(object sender, object e)
 {
     SharingMgr.Update();
 }