Example #1
0
        public bool SaveFile(HttpPostedFileBase uploadedFile, string folderPath, out string fileName,
            string oldFileName = null)
        {
            if (!Directory.Exists(folderPath))
                Directory.CreateDirectory(folderPath);

            if (!string.IsNullOrEmpty(oldFileName) && !(oldFileName.Trim().ToLower().Equals("avatar.jpg")))
                _generalHelper.DeleteFile(oldFileName, folderPath);

            //saving the file given to us...
            if (uploadedFile == null)
            {
                fileName = null;
                return false;
            }

            if (uploadedFile.ContentLength <= 0)
            {
                fileName = null;
                return false;
            }

            if (!Directory.Exists(folderPath))
            {
                // If it doesn't exist, create the directory
                Directory.CreateDirectory(folderPath);
            }

            fileName = Path.GetFileName(DateTime.Now.ToString("yyyyMMddHHmmssfff") + "_" + uploadedFile.FileName);
            string path = Path.Combine(folderPath, fileName);
            uploadedFile.SaveAs(path); //where the actual saving is done...

            return true;
        }
Example #2
0
        public bool DeleteInformationDeskFile([FromBody] Attachment fileAttachment)
        {
            if (fileAttachment == null)
            {
                return(false);
            }

            //getting the attachment..
            var attachment = (AttachmentType)Enum.Parse(typeof(AttachmentType), fileAttachment.AttachmentType);

            //now lets identify the file and go on to delete..
            string folderPath = "";
            string urlPath    = "";

            _generalHelper.GetFolderAndUrlPath(attachment, out folderPath, out urlPath);

            //when its already in the db...
            bool deleteActualFile = true;

            if (fileAttachment.Id > 0)
            {
                switch (attachment)
                {
                case AttachmentType.GeneralInformation:
                    deleteActualFile = _coreRepository.Delete <GeneralInformationAttachment>(fileAttachment.Id);
                    break;

                case AttachmentType.InformationDesk:
                    deleteActualFile = _coreRepository.Delete <InformationDeskAttachment>(fileAttachment.Id);
                    break;
                }
            }
            if (!deleteActualFile)
            {
                return(false);
            }

            //deleeting files...
            bool isFileDeleted = _generalHelper.DeleteFile(fileAttachment.Name, folderPath);

            if (fileAttachment.IsImage)
            {
                _generalHelper.DeleteFile(fileAttachment.Name,
                                          Path.Combine(folderPath, ResourceFolders.Thumbnail.ToString()));
            }

            return(isFileDeleted);
        }