public ActionResult Unlike(int id) { PublicationModel publicationmodel = followPeersDB.PublicationModels.Find(id); if (publicationmodel.Likes != 0) { publicationmodel.Likes = publicationmodel.Likes - 1; } string name = Membership.GetUser().UserName; int userID; UserProfile user = followPeersDB.UserProfiles.SingleOrDefault(p => p.UserName == name); userID = user.UserProfileId; AchievementLike achievementmodel = followPeersDB.AchievementLikes.SingleOrDefault(p => p.AchievementId == id && p.UserProfileId == userID); try { followPeersDB.AchievementLikes.Remove(achievementmodel); } catch { } followPeersDB.SaveChanges(); return(RedirectToAction("Details", "PublicationModel", new { id = id })); }
public ActionResult Unlike(int id, int pubId, string NameId) { PublicationModel publicationmodel = followPeersDB.PublicationModels.Find(pubId); publicationmodel.Likes = publicationmodel.Likes - 1; AchievementLike achievementmodel = followPeersDB.AchievementLikes.Find(id); followPeersDB.AchievementLikes.Remove(achievementmodel); followPeersDB.SaveChanges(); return(Json(id)); }
public ActionResult Like(int id, string NameId) { PublicationModel publicationmodel = followPeersDB.PublicationModels.Find(id); publicationmodel.Likes = publicationmodel.Likes + 1; string name = Membership.GetUser().UserName; int userID; UserProfile user = followPeersDB.UserProfiles.SingleOrDefault(p => p.UserName == name); userID = user.UserProfileId; AchievementLike achievement = new AchievementLike(); achievement.Type = 6; achievement.UserProfileId = userID; achievement.AchievementId = id; achievement.UserProfile = user; user.AchievementLikes.Add(achievement); followPeersDB.SaveChanges(); return(Json(id)); }