Ejemplo n.º 1
0
        public IActionResult DeletePhoto([FromBody] DeleteFileInfo deleteFileInfo)
        {
            string FolderPath = _pathHelper.GetFullPathToFile(deleteFileInfo.Path);
            string FullPath   = Path.Combine(FolderPath, deleteFileInfo.PhotoName);

            if (System.IO.File.Exists(FullPath))
            {
                System.IO.File.Delete(FullPath);
                _dbService.DeletePhotoFromDb(deleteFileInfo);

                return(Ok());
            }
            else
            {
                return(Json("File does not exist"));
            }
        }
Ejemplo n.º 2
0
        public void DeletePhotoFromDb(DeleteFileInfo deleteFileInfo)
        {
            using (FamilyArchiveContext db = new FamilyArchiveContext())
            {
                string searchString = string.Empty;
                if (string.IsNullOrEmpty(deleteFileInfo.Path))
                {
                    searchString = deleteFileInfo.PhotoName;
                }
                else
                {
                    searchString = Path.Combine(deleteFileInfo.Path, deleteFileInfo.PhotoName);
                }

                List <Photos> photos = db.Photos.Where(p => p.Name == searchString).ToList();
                db.Photos.RemoveRange(photos);
                db.SaveChanges();
            }
        }