Exemplo n.º 1
0
        public async Task Execute(IJobExecutionContext context)
        {
            //Lấy thời gian
            DateTime aDateTime = DateTime.Now;
            string   date      = "";
            string   day       = aDateTime.Day.ToString();
            string   month     = aDateTime.Month.ToString();
            string   year      = aDateTime.Year.ToString();

            date = day + '-' + month + '-' + year;

            // job thay đổi status của tài liệu thành active và thêm ngày
            DbContext_WebTaiLieu db = new DbContext_WebTaiLieu();
            var    list_docu        = db.tbl_file.Where(x => x.status == 0).ToList();
            int    number_docu      = list_docu.Count();
            Random number_page      = new Random();
            int    num_page         = number_page.Next(3, 6);

            for (int i = 0; i < num_page; i++)
            {
                Random   list_number = new Random();
                int      num         = list_number.Next(0, number_docu - 1);
                tbl_file new_file    = list_docu[num];
                new_file.status  = 1;
                new_file.time_up = date;
                db.SaveChanges();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <CommonResultDto <string> > Delete(string id)
        {
            tbl_file file = await _context.tbl_file.FirstOrDefaultAsync(i => i.Id == id);

            _context.tbl_file.Remove(file);

            if (File.Exists(file.Path))
            {
                File.Delete(file.Path);
            }
            await _context.SaveChangesAsync();

            return(new CommonResultDto <string>
            {
                Msg = "删除成功",
                Success = true,
                Response = ""
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public async Task <CommonResultDto <string> > Upload(IFormFile file)
        {
            var path = Directory.GetCurrentDirectory() + "\\wwwroot" + _configuration["FilePath"];

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            var fileName = DateTime.UtcNow.ToString("yyyyMMddHHmmss") + new Random().Next(1000, 10000).ToString() + Path.GetExtension(file.FileName);
            var filePath = path + fileName;

            using (var stream = File.Create(filePath))
            {
                file.CopyTo(stream);
            }

            tbl_file tbl = new tbl_file
            {
                Id   = Guid.NewGuid().ToString(),
                Name = file.FileName,
                //Path = filePath,
                Path     = _configuration["FilePath"] + fileName,
                ExtName  = Path.GetExtension(file.FileName),
                Size     = file.Length,
                UploadAt = DateTime.Now,
                Type     = '1'
            };

            await _context.tbl_file.AddAsync(tbl);

            await _context.SaveChangesAsync();

            return(new CommonResultDto <string>
            {
                Msg = "上传成功",
                Success = true,
                Response = _configuration["FilePath"] + fileName
            });
        }
Exemplo n.º 4
0
        private tbl_file saveFileToDatabase(HttpPostedFileBase postedfile, string filename)
        {
            Stream       stream = postedfile.InputStream;
            BinaryReader br     = new BinaryReader(stream);

            byte[] bytes   = br.ReadBytes((int)stream.Length);
            var    newFile = new tbl_file
            {
                name = filename,
                file = bytes,
            };

            //save file to database
            try
            {
                _unit.GetRepositoryInstance <tbl_file>().Add(newFile);
                return(_unit.GetRepositoryInstance <tbl_file>().GetFirstorDefaultByParameter(e => e.file.Equals(bytes) && e.name.Equals(filename)));
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemplo n.º 5
0
        public ActionResult Index(HttpPostedFileBase[] file, string folderName, string cate)
        {
            //GoogleDriveAPIHelper.CreateFolder(folderName);
            string id = GoogleDriveAPIHelper.GetLinkFolder(folderName);

            if (id == "")
            {
                GoogleDriveAPIHelper.CreateFolder(folderName);
                id = GoogleDriveAPIHelper.GetLinkFolder(folderName);
            }
            //GoogleDriveAPIHelper.UplaodFileOnDrive(file);

            foreach (var item in file)
            {
                try
                {
                    //GoogleDriveAPIHelper.UplaodFileOnDrive(item);
                    GoogleDriveAPIHelper.FileUploadInFolder(id, item);
                }
                catch
                {
                    ViewBag.Success  = "File Upload fail on Google Drive";
                    ViewBag.listLink = new List <string>();
                    ViewBag.fileName = new List <string>();
                    return(View());
                }
            }

            var lnk      = GoogleDriveAPIHelper.linkDrive;
            var fileName = GoogleDriveAPIHelper.fileName;

            ViewBag.Success = "File Uploaded on Google Drive";
            //List<String> list_link = new List<String>();
            //foreach (var item in lnk)
            //{
            //    string[] temp = item.ToString().Split(' ');
            //    list_link.Add(temp[0]);
            //}
            //ViewBag.list_link = list_link;
            ViewBag.listLink = lnk;
            ViewBag.fileName = fileName;
            GoogleDriveAPIHelper.DeleteFolder();
            int count = lnk.Count();

            //ViewBag.count = count;sau đó thêm sản phẩm vào  danh mục ý
            // Ý tưởng viết tiếp
            //cho chọn danh mục
            for (int i = 0; i < count; i++)
            {
                tbl_file new_file = new tbl_file();
                new_file.file_name  = fileName[i];
                new_file.id_cate    = Convert.ToInt32(cate);
                new_file.link_drive = lnk[i];
                new_file.status     = 0;
                db.tbl_file.Add(new_file);
                db.SaveChanges();
            }
            var category = db.tbl_category.ToList();

            ViewBag.category = category;

            return(View());
        }
Exemplo n.º 6
0
 public void AddTotbl_file(tbl_file tbl_file)
 {
     base.AddObject("tbl_file", tbl_file);
 }
Exemplo n.º 7
0
 public static tbl_file Createtbl_file(long id, int fileUserID)
 {
     tbl_file tbl_file = new tbl_file();
     tbl_file.ID = id;
     tbl_file.FileUserID = fileUserID;
     return tbl_file;
 }