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)); } }
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 })); } } }
public ActionResult ShowSharingDetail(int?id) { using (SharingManager sharingManager = new SharingManager()) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Sharing share = sharingManager.Find(x => x.Id == id && !x.isDelete); if (share == null) { return(HttpNotFound()); } return(PartialView("_PartialSharingDetail", share)); } }
public ActionResult Insert(Comment comment, int?note_id) { using (SharingManager sharingManager = new SharingManager()) { using (CommentManager commentManager = new CommentManager()) { if (ModelState.IsValid) { if (note_id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Sharing sharing = sharingManager.Find(x => x.Id == note_id && !x.isDelete && !x.isDraft && !x.Owner.isDeleted); if (sharing == null) { return(new HttpNotFoundResult()); } if (comment != null) { comment.Sharing = sharing; comment.Owner = CurrentSession.shareBookUser; if (commentManager.Insert(comment) > 0) { return(Json(new { Result = true }, JsonRequestBehavior.AllowGet)); } } return(Json(new { Result = false }, JsonRequestBehavior.AllowGet)); } return(Json(new { Result = false }, JsonRequestBehavior.AllowGet)); } } }
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)); } } }