public void EditCatrgory(string wikiname,int id , WikiCategory cat)
        {
            try
            {
                if (CommonTools.isEmpty(wikiname) == false && id >0 && cat !=null)
                {
                    this.rp.EditCategory(id, wikiname, cat);
                }
            }
            catch (Exception ex)
            {

                CommonTools.ErrorReporting(ex);

            }
        }
        public void Add(WikiCategory cat)
        {
            try
            {

                if ( cat !=null)
                {
                    rp.CreateCategory(cat);

                }

            }
            catch (Exception ex)
            {

                CommonTools.ErrorReporting(ex);
               // return null;
            }
        }
        public void EditCategory(int id ,string wikiname,WikiCategory cat)
        {
            try
            {

                if (!CommonTools.isEmpty(wikiname) && this.WikiExists(wikiname) &&
                    cat !=null)
                {
                    WikiCategory od = this.GetCategorybyId(id);
                    Wiki wk = this.GetWiki(wikiname);
                     if ( od !=null && wk !=null)
                    {
                        this.db.Entry(od).CurrentValues.SetValues(cat);
                        this.db.SaveChanges();
                        this.MarkWikiAsUpdated(wk);

                    }
                }

            }
            catch (ValidationException ex) { CommonTools.ValidationErrorReporting(ex); }
            catch (Exception ex)
            {

                CommonTools.ErrorReporting(ex);

            }
        }
        public void CreateCategory(WikiCategory cat)
        {
            try
            {

                if ( cat != null)
                {
                    if (this.CategoryExistsinWiki(cat.Title,cat.Wiki.Name) == false)
                    {    Wiki  wk= this.GetWiki(cat.Wiki.Name);
                        if (wk != null)
                        {  if ( wk.Categories == null )
                            {
                                wk.Categories = new List<WikiCategory>();
                            }
                            wk.Categories.Add(cat);
                            this.db.Categories.Add(cat);
                            this.MarkWikiAsUpdated(wk);
                            this.db.SaveChanges();

                        }
                    }
                }

            }
            catch (ValidationException ex) { CommonTools.ValidationErrorReporting(ex); }
            catch (Exception ex)
            {

                CommonTools.ErrorReporting(ex);

            }
        }
        public WikiTitle AddContentTitle(string wikiname, WikiTitle title , WikiContent cont,WikiCategory cat,ApplicationUser usr)
        {
            try
            {
                WikiTitle ap = null;
                if (wikiname != null && title !=null && cont != null && cat!=null)
                {
                  var  a=this.CategoryExistsinWiki(cat.Title, wikiname);
                    Wiki wk = this.GetWiki(wikiname);
                   // if (wk != null &&a ==true)
                    {
                        //  cont.Id = id;

                        title.Categories = new List<WikiCategory>();
                        if (cat != null)
                        {
                            title.Categories.Add(cat);
                        }
                        title.Wiki = wk;
                        title.WrittenBy = usr.Id;
                        title.Slug = title.Name.Replace(" ", "_");

                        cont.Title = title;
                        cont.TitleId = title.TitleId;
                        cont.Version = 1;
                        cont.Wiki = wk;
                        cont.WrittenBy = usr.Id;
                        cont.VersionDate = DateTime.Now;
                       cont.ContentId = this.db.Content.Count() + 1;
                        title.Content = cont;
                        if (wk.Content == null)
                        {
                            wk.Content = new List<Core.Data.Models.WikiContent>();
                        }
                        wk.Content.Add(cont);
                        if (wk.Titles == null)
                        {
                            wk.Titles = new List<WikiTitle>();
                        }
                        wk.Titles.Add(title);
                        db.Content.Add(cont);
                        db.Title.Add(title);

                      //  this.db.Configuration.ValidateOnSaveEnabled = false;
                        db.SaveChanges();
                        this.MarkWikiAsUpdated(wk);
                        ap = title;

                    }
                }
                return ap;

            }
            catch (ValidationException ex) { CommonTools.ValidationErrorReporting(ex); return null; }
            catch (Exception ex)
            {

                CommonTools.ErrorReporting(ex);
                return null;
            }
        }
        public ActionResult EditCategory(WikiCategory cat, string wikiname, int id)
        {
            try
            {

                if (cat != null)
                {
                    this.catmngr.EditCatrgory(wikiname, id, cat);
                    RouteValueDictionary vals = new RouteValueDictionary();
                    vals.Add("wikiname", wikiname);
                    vals.Add("id", id);

                    return RedirectToAction("Details", vals);
                }

                return View(cat);
            }
            catch (Exception ex)
            {

                CommonTools.ErrorReporting(ex);
                return new HttpStatusCodeResult(System.Net.HttpStatusCode.InternalServerError);
            }
        }