Exemple #1
0
 public UploadModel( Upload upload )
 {
     this.UploadId = upload.UploadId;
     this.Title = upload.Title;
     this.Description = upload.Description;
     this.UploadLocation = upload.PhysicalLocation;
 }
 public UploadsListItemModel( Upload upload )
 {
     this.UploadId = upload.UploadId;
     this.Name = upload.Filename;
     this.Location = upload.PhysicalLocation;
     this.DateUpdated = upload.DateUpdated;
 }
        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;
        }
        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;
        }