public IActionResult SaveFile(IFormFile file, long applicationID)
        {
            if (file == null || file.Length == 0)
            {
                return(Ok(new Application_ResponseWrapper()
                {
                    ResponseCode = "1003", ResponseMessage = "Invalid file", Status = "failed"
                }));
            }
            try
            {
                CheckFileDirectory();
                StringBuilder directoryPath = new StringBuilder();
                directoryPath.Append((file.ContentType.Contains("image/")?ImageFileLocation:DocFileLocation));

                string systemFileName = Path.GetFileNameWithoutExtension(file.FileName) + "_" + DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss") + "_" + Path.GetExtension(file.FileName);

                directoryPath.Append("/" + systemFileName);
                using (FileStream fs = System.IO.File.Create(directoryPath.ToString()))
                {
                    //file.CopyToAsync(fs);
                    file.CopyTo(fs);
                    fs.Flush();
                }

                Application_Files application_Files = new Application_Files {
                    applicationID = applicationID, actualFileName = file.FileName, systemFileName = systemFileName, attachmentUrl = directoryPath.ToString(), createdDate = DateTime.Now
                };
                application_Files = _applicationFilesRepository.Insert(application_Files);

                if (application_Files != null)
                {
                    return(Ok(new Application_ResponseWrapper()
                    {
                        ResponseCode = "0", ResponseMessage = "Information saved", Status = "success", ResponseResult = application_Files
                    }));
                }
                else
                {
                    return(Ok(new Application_ResponseWrapper()
                    {
                        ResponseCode = "1001", ResponseMessage = "Information not saved", Status = "failed"
                    }));
                }
            }
            catch (Exception ex)
            {
                return(Ok(new Application_ResponseWrapper()
                {
                    ResponseCode = "1005", ResponseMessage = ex.ToString(), Status = "failed"
                }));
            }
        }
        public IActionResult FindById(long id)
        {
            Application_Files application_Files = _applicationFilesRepository.FindById(id);

            if (application_Files == null)
            {
                return(Ok(new Application_ResponseWrapper()
                {
                    ResponseCode = "1001", ResponseMessage = "Result not found", Status = "failed"
                }));
            }
            return(Ok(new Application_ResponseWrapper()
            {
                ResponseCode = "0", ResponseMessage = "success", Status = "success", ResponseResult = application_Files
            }));
        }
        public IActionResult DeleteFile(long id)
        {
            if (id == 0)
            {
                return(Ok(new Application_ResponseWrapper()
                {
                    ResponseCode = "1003", ResponseMessage = "Invalid file.", Status = "failed"
                }));
            }
            try
            {
                string directoryPath = DocFileLocation;
                //--get existing file detail by file id.
                Application_Files _file = _applicationFilesRepository.FindById(id);
                if (_file == null)
                {
                    return(Ok(new Application_ResponseWrapper()
                    {
                        ResponseCode = "1006", ResponseMessage = "File not found.", Status = "failed"
                    }));
                }

                System.IO.File.Delete(_hostingEnviroment.ContentRootPath + "/" + directoryPath + "/" + _file.systemFileName);
                if (!System.IO.File.Exists(_hostingEnviroment.ContentRootPath + "/" + directoryPath + "/" + _file.systemFileName))
                {
                    _applicationFilesRepository.DeleteById(id);
                    return(Ok(new Application_ResponseWrapper()
                    {
                        ResponseCode = "0", ResponseMessage = "File deleted", Status = "success", ResponseResult = _file
                    }));
                }
                else
                {
                    return(Ok(new Application_ResponseWrapper()
                    {
                        ResponseCode = "1008", ResponseMessage = "File not deleted", Status = "failed"
                    }));
                }
            }
            catch (Exception ex)
            {
                return(Ok(new Application_ResponseWrapper()
                {
                    ResponseCode = "1005", ResponseMessage = ex.ToString(), Status = "failed"
                }));
            }
        }
 public Application_Files Insert(Application_Files FileDetail)
 {
     try
     {
         if (FileDetail == null)
         {
             return(null);
         }
         var Obj = _db.ObjApplicationFiles.Add(FileDetail);
         _db.SaveChanges();
         return(FileDetail);
     }
     catch (Exception e)
     {
         LogError(e, FileDetail.applicationID, 0);
         return(null);
     }
 }
 public Application_Files Update(Application_Files Files)
 {
     try
     {
         if (Files == null)
         {
             return(null);
         }
         Files.updatedDate = DateTime.Now;
         _db.ObjApplicationFiles.Update(Files);
         _db.SaveChanges();
         return(Files);
     }
     catch (Exception e)
     {
         LogError(e, Files.applicationID, 0);
         return(null);
     }
 }
        public IActionResult UpdateFile(IFormFile file, long id)
        {
            if (file == null || file.Length == 0)
            {
                return(Ok(new Application_ResponseWrapper()
                {
                    ResponseCode = "1003", ResponseMessage = "Invalid file.", Status = "failed"
                }));
            }
            try
            {
                //--get existing file detail by file id.
                Application_Files _file = _applicationFilesRepository.FindById(id);
                if (_file == null)
                {
                    return(Ok(new Application_ResponseWrapper()
                    {
                        ResponseCode = "1006", ResponseMessage = "File not found.", Status = "failed"
                    }));
                }

                System.IO.File.Delete(_hostingEnviroment.ContentRootPath + "/" + _file.attachmentUrl);

                if (!System.IO.File.Exists(_hostingEnviroment.ContentRootPath + "/" + _file.attachmentUrl))
                {
                    CheckFileDirectory();
                    //----------------------------------------
                    StringBuilder directoryPath = new StringBuilder();
                    directoryPath.Append((file.ContentType.Contains("image/")?ImageFileLocation:DocFileLocation));

                    string systemFileName = Path.GetFileNameWithoutExtension(file.FileName) + "_" + DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss") + "_" + Path.GetExtension(file.FileName);
                    directoryPath.Append("/" + systemFileName);
                    using (FileStream fs = System.IO.File.Create(directoryPath.ToString()))
                    {
                        //file.CopyToAsync(fs);
                        file.CopyTo(fs);
                        fs.Flush();
                    }

                    _file.actualFileName = file.FileName;
                    _file.systemFileName = systemFileName;
                    _file.attachmentUrl  = directoryPath.ToString();
                    _file.updatedDate    = DateTime.Now;

                    _applicationFilesRepository.Update(_file);

                    return(Ok(new Application_ResponseWrapper()
                    {
                        ResponseCode = "0", ResponseMessage = "Information saved", Status = "success", ResponseResult = _file
                    }));
                }
                else
                {
                    return(Ok(new Application_ResponseWrapper()
                    {
                        ResponseCode = "1007", ResponseMessage = "File not updated", Status = "failed"
                    }));
                }
            }
            catch (Exception ex)
            {
                return(Ok(new Application_ResponseWrapper()
                {
                    ResponseCode = "1005", ResponseMessage = ex.ToString(), Status = "failed"
                }));
            }
        }