Ejemplo n.º 1
0
        public void CreateBlog(Blog bl, string username)
        {
            try
            {
                ApplicationUser usr = null;

                if (bl != null && CommonTools.isEmpty(username) == false)
                {
                    usr = CommonTools.usrmng.GetUser(username);
                    if (usr != null)
                    {
                        bl.Administrator = usr.Id; //.Clone();
                                                   //bl.AdministratorId = bl.Administrator.Id;



                        //  bl.Moderators = new List<BlogMods>();
                        //  BlogMods wm = new BlogMods();
                        // wm.Blog = bl;
                        // wm.Moderator = usr.Id;
                        //bl.Moderators.Add(wm);
                        db.Add(bl);
                        db.SaveChanges();


                        string blpath;

                        //if (CommonTools.isEmpty(blrotfold ))
                        //{
                        //    blrotfold = "Blogfiles";
                        //}
                        // blpath = "~/" + AppDataDir + "/" + blrotfold + "/" + bl.Name;
                        blpath = FileSystemManager.GetBlogRootDataFolderAbsolutePath(bl.Name);
                        if (FileSystemManager.DirectoryExists(blpath) == false)
                        {
                            FileSystemManager.CreateDirectory(blpath);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CommonTools.ErrorReporting(ex);
                //return null;
            }
        }
Ejemplo n.º 2
0
        //public FileRecordManager(SlimeDbContext tdb)
        //{
        //    db = tdb;
        //    postManager = new PostManager(db);
        //}
        public async Task <string> Create(int?BlogId, int?postid, Files filemodel, IFormFile filedata, string user)
        {
            try
            { string ap = null;
              if ((filedata != null) && (filemodel != null) && (!CommonTools.isEmpty(user)))
              {
                  var blog = await blogmngr.GetBlogByIdAsync(BlogId);

                  var post = await postManager.Details(postid);

                  ApplicationUser usr = (ApplicationUser)db.Users.First(m => m.UserName == user);
                  if ((blog != null))
                  {
                      var    blogpath = FileSystemManager.GetBlogRootDataFolderAbsolutePath(blog.Name);
                      string abspath  = await FileSystemManager.CreateFile(blogpath, filedata);

                      if (!CommonTools.isEmpty(abspath))
                      {
                          ap = FileSystemManager.GetBlogRootDataFolderRelativePath(blog.Name) + "/" + Path.GetFileName(abspath);
                          filemodel.FileName     = Path.GetFileName(abspath);
                          filemodel.Path         = abspath;
                          filemodel.RelativePath = ap;

                          filemodel.Owner = usr.UserName;
                          //filemodel.PostId =(int) postid;

                          db.Files.Add(filemodel);
                          await db.SaveChangesAsync();

                          FilesPostBlog filesPost = new FilesPostBlog();
                          filesPost.BlogId = blog.Id;
                          filesPost.FileId = filemodel.Id;
                          filesPost.PostId = (int)postid;
                          db.FilesPostsBlog.Add(filesPost);
                          await db.SaveChangesAsync();
                      }
                  }
              }
              return(ap); }
            catch (Exception ex)
            {
                CommonTools.ErrorReporting(ex);
                return(null);
            }
        }
Ejemplo n.º 3
0
        public async Task DeleteBlogAsync(string Blogname)
        {
            try
            {
                Blog ap = null;
                if (!CommonTools.isEmpty(Blogname))
                {
                    string       path    = FileSystemManager.GetBlogRootDataFolderRelativePath(Blogname);
                    List <Files> blfiles = (await this.GetBlogAsync(Blogname)).Files;
                    //if (blfiles != null)
                    //{
                    //    foreach (Files f in blfiles)
                    //    {
                    //        FileSystemManager.DeleteFile(f.RelativePath);
                    //    }
                    //    FileSystemManager.DeleteDirectory(path);
                    //}
                    //if (blfiles != null)
                    //{
                    //    db.Files.RemoveRange(blfiles);
                    //}

                    Blog blog = await this.GetBlogAsync(Blogname);

                    this.fileRecordManager.DeleteByBlog(Blogname);
                    PostManager postManager = new PostManager();
                    await postManager.DeleteByBlogId(blog.Id);

                    FileSystemManager.DeleteDirectory(path);
                    db.Blogs.Remove(blog);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                CommonTools.ErrorReporting(ex);
            }
        }