Пример #1
0
        public ActionResult AddBookmark(string ID)
        {
            int id = Convert.ToInt16(ID);
            // Get the user name of the current logged in user
            string name = Membership.GetUser().UserName;
            // Get the entire userprofile associated with this user
            UserProfile user = db.UserProfiles.SingleOrDefault(p => p.UserName == name);

            // Check if a bookmark with these credentials exsists in the Db
            Bookmark bookmark = db.Bookmarks.SingleOrDefault(b => b.itemID == id && b.userID == user.UserProfileId && b.bookmarkType == "Patent");

            if (bookmark == null)
            {
                // No Bookmark exsists,  thereforre add this bookmark into the Db
                Bookmark tempBookmark = new Bookmark();
                tempBookmark.itemID = id;
                tempBookmark.bookmarkType = "Patent";
                tempBookmark.userID = user.UserProfileId;
                db.Bookmarks.Add(tempBookmark);
                db.SaveChanges();

                //Adding a notification item to the owner of the patent
                PatentModel patent = db.PatentModels.SingleOrDefault(b => b.ID == tempBookmark.itemID);
                UserProfile updateowner = db.UserProfiles.SingleOrDefault(p => p.UserProfileId == patent.UserProfile.UserProfileId);
                string patentDescription = patent.Title;
                Notification newnoti = new Notification
                {
                    message = user.FirstName + " bookmarked your patent : " + patentDescription,
                    link = "/Profile/Index/" + user.UserProfileId,
                    New = true,
                    imagelink = user.PhotoUrl,
                };

                updateowner.Notifications.Add(newnoti);
                db.Entry(updateowner).State = EntityState.Modified;
                db.SaveChanges();
            }

            return RedirectToAction("Index", "PublicationModel");
        }
        public ActionResult Recommend(int id, string NameId)
        {
            UserProfile user = followPeersDB.UserProfiles.SingleOrDefault(p => p.UserName == name);
            Bookmark model = new Bookmark();

            if (NameId != null && NameId != "")
            {
                int recommendid = Convert.ToInt32(NameId);
                UserProfile invitee = followPeersDB.UserProfiles.SingleOrDefault(p => p.UserProfileId == recommendid);

                try
                {
                    if (user.UserProfileId != recommendid)
                    {
                        model.bookmarkType = "Publication";
                        model.itemID = id;
                        model.userID = recommendid;
                        followPeersDB.Bookmarks.Add(model);
                        followPeersDB.SaveChanges();

                        //Adding a notification item to the recommended person
                        PublicationModel book = followPeersDB.PublicationModels.SingleOrDefault(b => b.publicationID == id);
                        Notification newnoti = new Notification
                        {
                            message = user.FirstName + user.LastName + " has recommeded you a publication : " + book.title,
                            link = "/PublicationModel/Details/" + id,
                            New = true,
                            imagelink = user.PhotoUrl,
                        };

                        invitee.Notifications.Add(newnoti);
                        followPeersDB.Entry(invitee).State = EntityState.Modified;
                        followPeersDB.SaveChanges();
                    }

                }
                catch
                {
                }
            }
            string result = "#";
            return Json(result);
        }