public void AddAModToNewWiki(Wiki wk ,string mod)
        {
            try
            {
                if ( wk !=null && CommonTools.isEmpty(mod)==false )
                {

                    if (wk.Moderators != null)
                    {
                        WikiMods wm = new WikiMods();
                        wm.Moderator = mod;
                        wm.Wiki = wk;
                        if ( wk.Moderators.FirstOrDefault(x=>x.Moderator==mod && x.Wiki.Name==wk.Name)==null)
                        {
                            wk.Moderators.Add(wm);
                        }

                    }
                    else
                    {
                        wk.Moderators = new List<WikiMods>();
                        WikiMods wm = new WikiMods();
                        wm.Moderator = mod;
                        wm.Wiki = wk;
                        if (wk.Moderators.FirstOrDefault(x => x.Moderator == mod && x.Wiki.Name == wk.Name) == null)
                        {
                            wk.Moderators.Add(wm);
                        }

                    }

                }

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

                CommonTools.ErrorReporting(ex);
                //return null;
            }
        }
Exemple #2
0
        public Wiki ExportToModel()
        {
            try
            {
                Wiki ap = new Wiki();
                    //ApplicationUser user = CommonTools.usrmng.GetUserbyID(md.Administrator);

                      //  ap.id = this.id;

                        ap.Files = this.Files;
                        ap.Categories = Categories;
                        ap.Content = Content;
                        ap.Description = Description;
                        ap.Name = Name;
                        ap.Titles = Titles;
                        ap.UpdatedAt = UpdatedAt;
                        ap.WikiTitle = WikiTitle;
                if (Administrator != null)
                {
                    ap.Administrator = Administrator.Id;
                }
                if ( Files==null)
                {
                    ap.Files = new List<WikiFile>();
                }
                 if ( Categories== null)
                {
                    ap.Categories = new List<WikiCategory>();
                }
                        if (Moderators != null)
                        {
                            //List<string> mods = new List<string>();
                    ap.Moderators = new List<WikiMods>();

                            foreach (var m in this.Moderators)
                            {

                        //mods.Add(m.Id);
                        WikiMods wm = new WikiMods();
                        wm.Wiki = ap;
                        wm.Moderator = m.Id;
                        ap.Moderators.Add(wm);

                            }

                        }

                return ap;

            }
            catch (Exception ex)
            {

                CommonTools.ErrorReporting(ex);
                return null;

            }
        }
        public void Create(Project project,string  user)
        {
            try
            {
                if (usrmng == null)
                {
                    usrmng = new ProjectUserManager();
                }

                if (project != null && CommonTools.isEmpty(user) == false
                   && usrmng.UserExists(user) == true)
                {

                    ApplicationUser admin = usrmng.GetUser(user);
                    if (admin != null)
                    {

                        Wiki wk = new Wiki();
                        wk.Name = project.Name;
                        wk.WikiTitle = project.Name;
                        wk.Administrator = admin.Id;
                        wk.Moderators = new List<WikiMods>();
                        WikiMods wkm = new WikiMods();
                        wkm.Moderator = admin.Id;
                        wkm.Wiki = wk;
                        wk.Moderators.Add(wkm);
                        wkmngr.CreateWiki(wk,user);

                        //project.Admininstrator = admin;
                        //project.AdmininstratorId = admin.Id;
                        ApplicationUser owner = new ApplicationUser();

                        //owner.Claims = admin.Claims;
                        owner = admin.Clone();

                        project.WikiName = project.Name;
                       project.News = new List<ProjectNews>();
                        //List<FileReleases> filelst= new List<FileReleases>();
                        //project.Releases = filelst;
                        project.Members = new List<ProjectMember>();
                        if (db == null)
                        {
                            db = new ApplicationDbContext();
                        }
                        //ProjectUser projusr = new ProjectUser();
                        //   project.Admininstrator = owner;

                       project.Admininstrator = admin.Id;
                       //   db.Configuration.ValidateOnSaveEnabled = false;
                       // db.Configuration.LazyLoadingEnabled = true;
                        //Statics.usersprojmngr.AddNewProjectToUser(admin, project);
                        db.Projects.Add(project);

                        db.SaveChanges();
                        string plugrelpath= plugmanger.GetPluginFilesRelativeDir("Projects");
                        string path = Path.Combine(plugrelpath, project.Name);
                        FileManager.CreateDirectory(path);

                    }
                }

            }
            catch (Exception ex)
            {
                CommonTools.ErrorReporting(ex);

            }
        }