Ejemplo n.º 1
0
    public static void UpdateFile(string fileName, string filePath, string attrString)
    {
        filePath = GetAbsolutePath(filePath);


        try
        {
            FileInfo file = new FileInfo(filePath);
            /// Checking if file exists
            if (file.Exists)
            {
                ///get the folder path
                filePath = filePath.Substring(0, filePath.LastIndexOf("/") + 1);
                filePath = filePath + fileName;
                file.MoveTo(filePath);
                //FileManagerController.UpdateFile(fileId, fileName);
                FileManagerHelper.SetFileAttributes(filePath, attrString);
                //CacheHelper.Clear("FileManagerFileList");
            }
        }
        catch (Exception ex)
        {
            fb.ProcessException(ex);
        }
    }
        public async Task <IActionResult> Create(Event eventModel)
        {
            ViewBag.Categories = await _context.Categories.ToListAsync();

            ViewBag.Tags = await _context.Tags.ToListAsync();

            ViewBag.Teachers = await _context.Teachers.ToListAsync();

            if (await _context.Events.AnyAsync(x => x.Title.ToLower() == eventModel.Title.Trim().ToLower()))
            {
                ModelState.AddModelError("Title", "Course already exists!");
                return(View());
            }

            if (!await _context.Categories.AnyAsync(c => c.Id == eventModel.CategoryId))
            {
                ModelState.AddModelError("CategoryId", "Category already exists!");
                return(View());
            }



            if (!ModelState.IsValid)
            {
                return(View());
            }

            eventModel.EventTags = await _createEventTags(eventModel.TagIds);

            if (eventModel.File != null)
            {
                #region CheckPhotoLength
                if (eventModel.File.Length > 3 * (1024 * 1024))
                {
                    ModelState.AddModelError("File", "Cannot be more than 3MB");
                    return(View());
                }
                #endregion
                #region CheckPhotoContentType
                if (eventModel.File.ContentType != "image/png" && eventModel.File.ContentType != "image/jpeg")
                {
                    ModelState.AddModelError("File", "Only jpeg and png files accepted");
                    return(View());
                }
                #endregion

                string filename = FileManagerHelper.Save(_env.WebRootPath, "uploads/events", eventModel.File);

                eventModel.Photo = filename;
            }

            eventModel.CreatedAt  = DateTime.UtcNow;
            eventModel.ModifiedAt = DateTime.UtcNow;
            await _context.Events.AddAsync(eventModel);

            await _context.SaveChangesAsync();


            return(RedirectToAction("index"));
        }
Ejemplo n.º 3
0
    public static void MoveFile(string filePath, string fromPath, string toPath)
    {
        string fullFilePath = GetAbsolutePath(filePath);
        string fullFromPath = GetAbsolutePath(fromPath);
        string fullToPath   = GetAbsolutePath(toPath);

        FileManagerHelper.TransferFile(filePath, toPath, (int)Action.MOVE, (int)TransferMode.NORMALTONORMAL, fullFilePath, fullFromPath, fullToPath);
    }
Ejemplo n.º 4
0
        private void OnSerializeViewModelState()
        {
            var filePath = FileManagerHelper.GetFileNameToSave();

            if (String.IsNullOrWhiteSpace(filePath))
            {
                return;
            }

            _viewModelStateSerializer.SaveViewModelState(this, filePath);
        }
Ejemplo n.º 5
0
    public static void CopyFile(string filePath, string fromPath, string toPath)
    {
        string fullFilePath = GetAbsolutePath(filePath);
        string fullFromPath = GetAbsolutePath(fromPath);
        string fullToPath   = GetAbsolutePath(toPath);



        try
        {
            //public static void TransferFile(string filePath, string toPath, int action, int mode, string fullFilePath, string fullFromPath, string fullToPath)
            FileManagerHelper.TransferFile(filePath, toPath, (int)Action.COPY, (int)TransferMode.NORMALTONORMAL, fullFilePath, fullFromPath, fullToPath);
        }
        catch (Exception ex)
        {
            fb.ProcessException(ex);
        }
    }
        private void BindTree()
        {
            TreeView1.Nodes.Clear();
            string   rootFolder = BaseDir;
            TreeNode rootNode   = new TreeNode();

            string relativePath = FileManagerHelper.ReplaceBackSlash(Request.PhysicalApplicationPath.ToString());

            relativePath = relativePath.Substring(0, relativePath.LastIndexOf("/"));
            string root = Request.ApplicationPath.ToString();

            rootNode.Text     = Path.Combine(BaseDir.Replace(relativePath, ""), root);
            rootNode.Expanded = true;
            rootNode.Value    = rootFolder.Replace("\\", "~").Replace(" ", "|");
            TreeView1.Nodes.Add(rootNode);
            TreeView1.ShowLines = true;
            BuildTreeDirectory(rootFolder, rootNode);
        }
Ejemplo n.º 7
0
        public IResult Update(IFormFile file, CarImage carImage)
        {
            var result = BusinessRules.Run(CheckIfFileIsEmpty(file), CheckIfExtensionsAreAllowed(file));

            if (result != null)
            {
                return(result);
            }

            var updatedImage = _carImageDal.Get(c => c.Id == carImage.Id);

            updatedImage.CarId = carImage.CarId;
            var existingPath = ExistingPath(updatedImage.ImagePath);

            updatedImage.ImagePath = FileManagerHelper.Update(file, existingPath);
            updatedImage.Date      = DateTime.Now;

            _carImageDal.Update(updatedImage);
            return(new SuccessResult(Messages.Success));
        }
Ejemplo n.º 8
0
    public void AddFileToDatabase(string fileName, string extension, string folder, int folderId, bool isDatabase, int saveMode)
    {
        string newFileName = fileName;

        if (saveMode == 1)
        {
            newFileName = fileName + ".resources";
        }
        FileInfo file = new FileInfo(GetAbsolutePath(folder + newFileName));
        ATTFile  obj  = new ATTFile();

        obj.PortalId        = fb.GetPortalID;
        obj.UniqueId        = Guid.NewGuid();
        obj.VersionGuid     = Guid.NewGuid();
        obj.FileName        = fileName;
        obj.Extension       = extension;
        obj.Size            = int.Parse(file.Length.ToString());
        obj.ContentType     = FileManagerHelper.ReturnExtension(extension);
        obj.Folder          = folder;
        obj.FolderId        = folderId;
        obj.IsActive        = 1;
        obj.StorageLocation = saveMode;
        obj.AddedBy         = fb.GetUsername;
        if (isDatabase)
        {
            byte[] _fileContent = FileManagerHelper.FileToByteArray(GetAbsolutePath(folder + fileName));
            obj.Content = _fileContent;
        }
        try
        {
            FileManagerController.AddFile(obj);
            if (saveMode == 2)
            {
                file.Delete();
            }
        }
        catch (Exception ex)
        {
            fb.ProcessException(ex);
        }
    }
Ejemplo n.º 9
0
        public IResult Add(IFormFile file, CarImage carImage)
        {
            var result = BusinessRules.Run(CheckIfFileIsEmpty(file), CheckIfCarImagesCountLimit(carImage.CarId), CheckIfExtensionsAreAllowed(file));

            if (result != null)
            {
                return(result);
            }

            var addedImage = new CarImage
            {
                CarId     = carImage.CarId,
                Date      = DateTime.Now,
                ImagePath = FileManagerHelper.Create(file)
            };

            //var resultImage=_fileManager.UploadImage(file, carImage);
            _carImageDal.Add(addedImage);

            return(new SuccessResult(Messages.Success));
        }