public ActionResult SelectCategory(int?id) { using (SharingManager sharingManager = new SharingManager()) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } List <SharingViewModel> sharing = sharingManager.ListQueryable().Where(x => x.Category.Id == id && !x.isDelete && !x.isDraft && !x.Owner.isDeleted).Select(x => new SharingViewModel() { Category = x.Category, Comments = x.Comments, Likes = x.Likes, Title = x.Title, ImageUrl = x.ImageUrl, ShareContent = x.ShareContent, Owner = x.Owner, ModifiedOn = x.ModifiedOn, CreatedOn = x.CreatedOn, ModifiedBy = x.ModifiedBy, Id = x.Id, CategoryId = x.CategoryId, isDraft = x.isDraft, isDelete = x.isDelete, LikeCount = x.LikeCount, }).OrderByDescending(x => x.ModifiedOn).ToList(); return(View("Index", sharing)); } }
// GET: Home public ActionResult Index() { using (SharingManager sharingManager = new SharingManager()) { List <SharingViewModel> model = sharingManager.ListQueryable().Where(x => !x.isDelete && !x.isDraft && !x.Owner.isDeleted).Select(x => new SharingViewModel() { Category = x.Category, Comments = x.Comments, Likes = x.Likes, Title = x.Title, ImageUrl = x.ImageUrl, ShareContent = x.ShareContent, Owner = x.Owner, ModifiedOn = x.ModifiedOn, CreatedOn = x.CreatedOn, ModifiedBy = x.ModifiedBy, Id = x.Id, CategoryId = x.CategoryId, isDraft = x.isDraft, isDelete = x.isDelete, LikeCount = x.LikeCount, }).OrderByDescending(x => x.ModifiedOn).ToList(); return(View(model)); } }
public JsonResult GetShareById(int id) { using (SharingManager sharingManager = new SharingManager()) { string value = string.Empty; var model = sharingManager.ListQueryable().Where(x => x.Id == id && !x.isDelete).SingleOrDefault(); return(Json(new Sharing() { Id = model.Id, Title = model.Title, ShareContent = model.ShareContent, ImageUrl = model.ImageUrl, isDraft = model.isDraft, //ModifiedOn = model.ModifiedOn, //Category = model.Category, CategoryId = model.CategoryId, //Comments = model.Comments, CreatedOn = model.CreatedOn, isDelete = model.isDelete, //Likes = model.Likes, ModifiedBy = model.ModifiedBy, //Owner = model.Owner, }, JsonRequestBehavior.AllowGet)); } }
public ActionResult SharingList() { using (SharingManager sharingManager = new SharingManager()) { List <SharingViewModel> sharings = sharingManager.ListQueryable().Where(x => x.Owner.Id == CurrentSession.shareBookUser.Id && !x.isDelete).Select(p => new SharingViewModel { Id = p.Id, CategoryTitle = p.Category.Title, Title = p.Title, ShareContent = p.ShareContent, LikeCount = p.Likes.Where(x => !x.likedUser.isDeleted).ToList().Count, CommentCount = p.Comments.Where(x => !x.isDelete && !x.Owner.isDeleted).ToList().Count, ImageUrl = p.ImageUrl, isDraft = p.isDraft, ModifiedOn = p.ModifiedOn, CategoryId = p.CategoryId, //Category=p.Category, //CategoryId = p.CategoryId, //isDelete = p.isDelete }).ToList(); return(Json(sharings, JsonRequestBehavior.AllowGet)); } }
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)); } }
// GET: Comment public ActionResult ShowCommentsandLikes(int?id) { using (SharingManager sharingManager = new SharingManager()) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Sharing share = sharingManager.ListQueryable().Include(x => x.Comments).Where(x => x.Id == id && !x.isDelete && !x.isDraft && !x.Owner.isDeleted).FirstOrDefault(); if (share == null) { return(HttpNotFound()); } var modelComments = share.Comments.Where(x => !x.isDelete && !x.Owner.isDeleted).ToList(); var modelLikes = share.Likes.Where(x => !x.likedUser.isDeleted).ToList(); return(PartialView("_PartialComments", new LikeCommentViewModel <List <Liked>, List <Comment> >() { Comments = modelComments, Likes = modelLikes })); } }
public ActionResult Search(string search) { using (SharingManager sharingManager = new SharingManager()) { using (SharebookUserManager sharebookUserManager = new SharebookUserManager()) { if (!string.IsNullOrEmpty(search)) { if (search.Length >= 3) { List <SharingViewModel> share = sharingManager.ListQueryable().Where(x => (x.ShareContent.Contains(search) || x.Title.Contains(search)) && !x.isDelete && !x.isDraft && !x.Owner.isDeleted || x.Owner.Username.Contains(search) || x.Owner.Name.Contains(search) || x.Owner.Surname.Contains(search)).Select(x => new SharingViewModel() { Title = x.Title, ShareContent = x.ShareContent, Owner = x.Owner, Category = x.Category, Comments = x.Comments, ModifiedOn = x.ModifiedOn, CreatedOn = x.CreatedOn, ImageUrl = x.ImageUrl, ModifiedBy = x.ModifiedBy, Likes = x.Likes, CategoryId = x.CategoryId, Id = x.Id }).ToList(); List <ShareBookUserViewModel> user = sharebookUserManager.ListQueryable().Where(x => (x.Username.Contains(search) || x.Name.Contains(search) || x.Surname.Contains(search)) && !x.isDeleted).Select(x => new ShareBookUserViewModel() { Comments = x.Comments, activatedGuid = x.activatedGuid, Email = x.Email, Name = x.Name, Username = x.Username, Notes = x.Notes, Password = x.Password, ProfilPhoto = x.ProfilPhoto, Surname = x.Surname, Id = x.Id, isActive = x.isActive, CreatedOn = x.CreatedOn, isAdmin = x.isAdmin, ModifiedOn = x.ModifiedOn, ModifiedBy = x.ModifiedBy, isDeleted = x.isDeleted, Likes = x.Likes }).ToList(); return(View(new SharingUserViewModel <List <ShareBookUserViewModel>, List <SharingViewModel> >() { s = share, sbu = user })); } return(RedirectToAction("Index", "Home")); } else { return(RedirectToAction("Index", "Home")); } } } }
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)); } } }