コード例 #1
0
        private SaveResult CreateImageUpload( UploadModel model )
        {
            string fileLocation;
            string uploadFolder = ContentLocation.UploadFolder;

            try
            {
                int domainId = UserSession.Current.DomainId;

                Domain domain = base.Database.Domains.Find( domainId );

                uploadFolder += domain.UploadFolder.ToString();

                string physicalLocation = uploadFolder.MapToServer();

                if ( Directory.Exists( physicalLocation ) == false )
                {
                    Directory.CreateDirectory( physicalLocation );
                }

                string currentDate = DateTime.Today.ToString( "yyyy-MM-dd" );
                uploadFolder += "/" + currentDate;
                physicalLocation += "/" + currentDate;

                if ( Directory.Exists( physicalLocation ) == false )
                {
                    Directory.CreateDirectory( physicalLocation );
                }

                fileLocation = physicalLocation + "/" + model.Upload.FileName;

                if ( File.Exists( fileLocation ) )
                {
                    File.Delete( fileLocation );
                }

                model.Upload.SaveAs( fileLocation );
            }
            catch// ( IOException ioException )
            {
                // Log exception

                return SaveResult.WriteFailure;
            }

            Upload upload = new Upload();
            upload.Initialise();
            upload.DomainId = UserSession.Current.DomainId;
            upload.Filename = model.Upload.FileName;
            upload.PhysicalLocation = uploadFolder + "/" + model.Upload.FileName;
            upload.Title = model.Title;
            upload.Description = model.Description;
            base.Database.Uploads.Add( upload );
            base.Database.SaveChanges();

            return SaveResult.Success;
        }
コード例 #2
0
        public SaveResult SaveImage( UploadModel model )
        {
            Upload upload = base.Database.Uploads.Find( model.UploadId );

            if ( upload == null )
            {
                return CreateImageUpload( model );
            }

            return UpdateImageUpload( upload, model );
        }
コード例 #3
0
        private SaveResult UpdateImageUpload( Upload upload, UploadModel model )
        {
            if ( model.Upload != null )
            {
                try
                {
                    if ( File.Exists( upload.PhysicalLocation ) )
                    {
                        File.Delete( upload.PhysicalLocation );
                    }

                    model.Upload.SaveAs( upload.PhysicalLocation );
                }
                catch// ( IOException ioException )
                {
                    // Log exception

                    return SaveResult.WriteFailure;
                }
            }

            upload.UpdateTimeStamp();
            upload.Title = model.Title;
            upload.Description = model.Description;

            base.Database.SaveChanges();

            return SaveResult.Success;
        }