Exemplo n.º 1
0
        public bool RemoveGalleryImage(int galleryId, int clientId, string imageName, DeletePhysicalImage deleteImage)
        {
            bool          retFlag     = default(bool);
            StringBuilder deleteQuery = new StringBuilder("DELETE FROM ClientBusinessGallery WHERE GalleryId = @GalleryId");

            // delete file
            //  if success, remove entry from DB .. wat if data remove fails?
            //  HENCE deleting data from DB first.. den remove physical file.. if file deletion fails, rollback data removal!

            using (TransactionScope transScope = new TransactionScope())
            {
                try
                {
                    if (clientDA.RemoveGalleryPic(galleryId, deleteQuery.ToString()))
                    {
                        if (deleteImage.Invoke(clientId, imageName))
                        // using delegate to execute the delete image function from Utility class in WebApp
                        // feeling so lazy to move the utility generic functionalities to 'Common' project
                        {
                            transScope.Complete();
                            retFlag = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    transScope.Dispose();
                    throw ex;
                }
                finally
                {
                    transScope.Dispose();
                }
            }
            return(retFlag);
        }