public ActionResult Edit(PatentModel patentmodel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(patentmodel).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("MyPatent");
     }
     return View(patentmodel);
 }
        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(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);
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("MyPatent");
            }

            return View(patentmodel);
        }