Esempio n. 1
0
 public void AddTag(Tag model)
 {
     myprofile = db.UserProfiles.SingleOrDefault(p => p.UserName == name);
     if (ModelState.IsValid)
     {
         // Add only if tag doesn't already exist
         Tag Check = db.Tags.FirstOrDefault(p => p.TagName == model.TagName);
         if (Check == null)
         {
             db.Tags.Add(model);
             db.Entry(model).State = EntityState.Modified;
             db.SaveChanges();
         }
         return;
     }
 }
Esempio n. 2
0
        public void AddTag(string TagName)
        {
            myprofile = db.UserProfiles.SingleOrDefault(p => p.UserName == name);
            if (ModelState.IsValid)
            {
                Tag Check = db.Tags.FirstOrDefault(p => p.TagName == TagName);
                if (Check == null)
                {
                    Tag item = new Tag();
                    item.TagName = TagName;

                    db.Tags.Add(item);
                    db.Entry(item).State = EntityState.Modified;
                    db.SaveChanges();
                }
                return;
            }
        }
Esempio n. 3
0
        public ActionResult Create(PatentModel patentmodel)
        {
            if (ModelState.IsValid)
            {
                string name = Membership.GetUser().UserName;
                UserProfile user = db.UserProfiles.SingleOrDefault(p => p.UserName == name);
                patentmodel.UserProfile = user;
                user.Patent.Add(patentmodel);
                //db.PatentModels.Add(patentmodel);
                //Create an update for patents
                CreateUpdates("Published a new patent titled " + patentmodel.Title, "/PatentModel/Details/" + patentmodel.ID, 7, user.UserProfileId, patentmodel.Keyword);

                //Adding Tags
                //To keep track of tags being added
                List<Tag> AddedTags = new List<Tag>();

                //Adding the Tag
                if (patentmodel.Keyword != null&&patentmodel.Keyword!="")
                {
                    string keyword = patentmodel.Keyword;
                    //If written new tag
                    string[] Tags = keyword.Split(';');
                    foreach (string tagname in Tags)
                    {
                        string Trimtagname = tagname.Trim();
                        Tag Item = db.Tags.FirstOrDefault(p => p.TagName.ToLower() == Trimtagname.ToLower());
                        if (Item != null)
                        {
                            if (AddedTags.Contains(Item) != true && !(Item.Patents.Any(p => p.ID == patentmodel.ID)))
                            {
                                Item.TagLinkedItems += 1;
                                patentmodel.Tags.Add(Item);
                                Item.Patents.Add(patentmodel);
                                AddedTags.Add(Item);
                            }
                        }
                        else //If (Item == null)
                        {
                            //Create a New Tag
                            Tag NewItem = new Tag();
                            NewItem.TagName = Trimtagname;
                            NewItem.TagLinkedItems = 1;
                            db.Tags.Add(NewItem);
                            patentmodel.Tags.Add(NewItem);
                            NewItem.Patents.Add(patentmodel);
                            AddedTags.Add(NewItem);
                        }
                    }
                }
                //-----------End of Adding Tags

                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                if (Sidebarnumber == 2)
                {
                    Sidebarnumber = 1;
                    return RedirectToAction("Create", "Jobs", new { id = 2 });
                }
                else
                return RedirectToAction("MyPatent");
            }

            else
            {
                return View(patentmodel);
            }
        }
        public ActionResult Create(PublicationModel publicationmodel, string[] keywordsId, string keyword)
        {
            if (ModelState.IsValid)
            {
                if (publicationmodel.author == null)
                {
                    publicationmodel.author = "default";
                }
                if (publicationmodel.conference == null)
                {
                    publicationmodel.conference = "default";
                }
                if (publicationmodel.description == null)
                {
                    publicationmodel.description = "default";
                }
                if (publicationmodel.issue == null)
                {
                    publicationmodel.issue = "default";
                }
                if (publicationmodel.journal == null)
                {
                    publicationmodel.journal = "default";
                }
                if (publicationmodel.keyword == null)
                {
                    publicationmodel.keyword = "default";
                }
                if (publicationmodel.page == null)
                {
                    publicationmodel.page = "default";
                }
                if (publicationmodel.publisher == null)
                {
                    publicationmodel.publisher = "default";
                }
                if (publicationmodel.referenceID == null)
                {
                    publicationmodel.referenceID = "Singapore";
                }
                if (publicationmodel.status == null)
                {
                    publicationmodel.status = "default";
                }
                if (publicationmodel.title == null)
                {
                    publicationmodel.title = "default";
                }
                if (publicationmodel.type == null)
                {
                    publicationmodel.type = "default";
                }
                if (publicationmodel.university == null)
                {
                    publicationmodel.university = "default";
                }
                if (publicationmodel.volume == null)
                {
                    publicationmodel.volume = "default";
                }
                if (publicationmodel.year == null)
                {
                    publicationmodel.year = 2012;
                }
                if (publicationmodel.viewCount == 0)
                {
                    publicationmodel.viewCount = 0;
                }
                if (publicationmodel.specialisation == null)
                {
                    publicationmodel.specialisation = "Physics";
                }
                publicationmodel.timestamp = DateTime.Now.ToString();
                if (Pubfilename != "")
                {
                    publicationmodel.filename = Pubfilename;
                    Pubfilename = "";
                }
                if (Imagename != "")
                {
                    publicationmodel.imagename = Imagename;
                    Imagename = "";
                }

                //Adding Tags
                //To keep track of tags being added
                List<Tag> AddedTags = new List<Tag>();

                //Adding the Tag
                if (keywordsId != null)
                {
                    //Selected Existing Tags
                    foreach (string tag in keywordsId)
                    {
                        int TagId = Convert.ToInt32(tag);
                        Tag Item = followPeersDB.Tags.FirstOrDefault(p => p.TagId == TagId);
                        if (Item != null && !(Item.Publications.Any(p => p.publicationID == publicationmodel.publicationID)))
                        {
                            AddedTags.Add(Item);
                            //When Tag Linked to Item, incremented to keep count
                            Item.TagLinkedItems += 1;
                            publicationmodel.Tags.Add(Item);
                            Item.Publications.Add(publicationmodel);
                        }
                    }
                }
                if (keyword != null)
                {
                    //If written new tag
                    string[] Tags = keyword.Split(';');
                    foreach (string tagname in Tags)
                    {
                        string Trimtagname = tagname.Trim();
                        Tag Item = followPeersDB.Tags.FirstOrDefault(p => p.TagName.ToLower() == Trimtagname.ToLower());
                        if (Item != null)
                        {
                            if (AddedTags.Contains(Item) != true && !(Item.Publications.Any(p => p.publicationID == publicationmodel.publicationID)))
                            {
                                Item.TagLinkedItems += 1;
                                publicationmodel.Tags.Add(Item);
                                Item.Publications.Add(publicationmodel);
                                AddedTags.Add(Item);
                            }
                        }
                        else //If (Item == null)
                        {
                            //Create a New Tag
                            Tag NewItem = new Tag();
                            NewItem.TagName = Trimtagname;
                            NewItem.TagLinkedItems = 1;
                            followPeersDB.Tags.Add(NewItem);
                            publicationmodel.Tags.Add(NewItem);
                            NewItem.Publications.Add(publicationmodel);
                            AddedTags.Add(NewItem);
                        }
                    }
                }
                //-----------End of Adding Tags

                string name = Membership.GetUser().UserName;
                UserProfile user = followPeersDB.UserProfiles.SingleOrDefault(p => p.UserName == name);
                publicationmodel.UserProfile = user;
                user.Publication.Add(publicationmodel);

                int publicationmodelid = followPeersDB.PublicationModels.Count() + 1;

                CreateUpdates("Published a new publication titled " + publicationmodel.title, "/PublicationModel/Details/" + publicationmodelid, 6, user.UserProfileId, publicationmodel.keyword);

                //followPeersDB.PublicationModels.Add(publicationmodel);
                followPeersDB.Entry(user).State = EntityState.Modified;
                followPeersDB.SaveChanges();
                if (Sidebarnumber == 2)
                {
                    Sidebarnumber = 1;
                    return RedirectToAction("Create", "PatentModel", new { id = 2 });
                }
                return RedirectToAction("Index");
            }

            return View(publicationmodel);
        }
Esempio n. 5
0
        public ActionResult Create(Course course)
        {
            string name = Membership.GetUser().UserName;
            UserProfile user = db.UserProfiles.SingleOrDefault(p => p.UserName == name);
            if (ModelState.IsValid)
            {
                user.Courses.Add(course);
                db.Entry(user).State = EntityState.Modified;

                //db.Courses.Add(course);
                CreateUpdates(course, course.CourseDescription);

                //Adding the Tag
                //To keep track of tags being added
                List<Tag> AddedTags = new List<Tag>();

                if (course.CourseDescription != null && course.CourseDescription != "")
                {
                    string keyword = course.CourseDescription;
                    //If written new tag
                    string[] Tags = keyword.Split(';');
                    foreach (string tagname in Tags)
                    {
                        string Trimtagname = tagname.Trim();
                        Tag Item = db.Tags.FirstOrDefault(p => p.TagName.ToLower() == Trimtagname.ToLower());
                        if (Item != null)
                        {
                            if (AddedTags.Contains(Item) != true && !(Item.Courses.Any(p => p.CourseId== course.CourseId)))
                            {
                                Item.TagLinkedItems += 1;
                                course.Tags.Add(Item);
                                Item.Courses.Add(course);
                                AddedTags.Add(Item);
                            }
                        }
                        else //If (Item == null)
                        {
                            //Create a New Tag
                            Tag NewItem = new Tag();
                            NewItem.TagName = Trimtagname;
                            NewItem.TagLinkedItems = 1;
                            db.Tags.Add(NewItem);
                            course.Tags.Add(NewItem);
                            NewItem.Courses.Add(course);
                            AddedTags.Add(NewItem);
                        }
                    }
                }
                //-----------End of Adding Tags
                db.SaveChanges();
                return RedirectToAction("Mine");
            }

            return View(course);
        }
Esempio n. 6
0
        public ActionResult Create(Jobs jobmodel, string[] TagsId, string tag)
        {
            if (ModelState.IsValid)
            {
                string name = Membership.GetUser().UserName;
                UserProfile user = followPeersDB.UserProfiles.SingleOrDefault(p => p.UserName == name);
                if (jobmodel.Enddate == null)
                {
                    jobmodel.Enddate = DateTime.Now;
                }
                if (jobmodel.publishDate == null)
                {
                    jobmodel.publishDate = DateTime.Now;
                }
                jobmodel.ownerID = user.UserProfileId;

                int jobid = followPeersDB.Jobs.Count() + 1;

                //Adding the Tag
                //To keep track of tags being added
                List<Tag> AddedTags = new List<Tag>();

                if (jobmodel.Description != null && jobmodel.Description != "")
                {
                    string keyword = jobmodel.Description;
                    //If written new tag
                    string[] Tags = keyword.Split(';');
                    foreach (string tagname in Tags)
                    {
                        string Trimtagname = tagname.Trim();
                        Tag Item = followPeersDB.Tags.FirstOrDefault(p => p.TagName.ToLower() == Trimtagname.ToLower());
                        if (Item != null)
                        {
                            if (AddedTags.Contains(Item) != true && !(Item.Jobs.Any(p => p.JobId == jobmodel.JobId)))
                            {
                                Item.TagLinkedItems += 1;
                                jobmodel.Tags.Add(Item);
                                Item.Jobs.Add(jobmodel);
                                AddedTags.Add(Item);
                            }
                        }
                        else //If (Item == null)
                        {
                            //Create a New Tag
                            Tag NewItem = new Tag();
                            NewItem.TagName = Trimtagname;
                            NewItem.TagLinkedItems = 1;
                            followPeersDB.Tags.Add(NewItem);
                            jobmodel.Tags.Add(NewItem);
                            NewItem.Jobs.Add(jobmodel);
                            AddedTags.Add(NewItem);
                        }
                    }
                }
                //-----------End of Adding Tags

                user.Jobs.Add(jobmodel);
                CreateUpdates("Published a new job titled " + jobmodel.Title, "/Jobs/Details/" + jobid, 6, user.UserProfileId, jobmodel.Description);
                //followPeersDB.Entry(user).State = EntityState.Modified;
                followPeersDB.SaveChanges();
                if (Sidebarnumber == 2)
                {
                    Sidebarnumber = 1;
                    return RedirectToAction("Mine", "Course");
                }
                return RedirectToAction("Index");
            }
            return View(jobmodel);
        }