public virtual void UpdateFile( ContentAttachment a, String oldFilePath ) { a.update(); if (a.IsImage) Img.DeleteImgAndThumb( oldFilePath ); else Img.DeleteFile( oldFilePath ); }
public virtual Result Create( ContentAttachment a, User user, IMember owner ) { a.OwnerId = owner.Id; a.OwnerType = owner.GetType().FullName; a.OwnerUrl = owner.Url; a.Creator = user; a.CreatorUrl = user.Url; a.Guid = Guid.NewGuid().ToString(); Result result = db.insert( a ); refreshAttachmentCount( a ); return result; }
public virtual Result SaveFile( HttpFile postedFile ) { Result result = Uploader.SaveFileOrImage( postedFile ); if (result.HasErrors)return result; ContentAttachment uploadFile = new ContentAttachment(); uploadFile.FileSize = postedFile.ContentLength; uploadFile.Type = postedFile.ContentType; uploadFile.Name = result.Info.ToString(); uploadFile.Description = System.IO.Path.GetFileName( postedFile.FileName ); uploadFile.Guid = Guid.NewGuid().ToString(); uploadFile.insert(); result.Info = uploadFile; return result; }
public void CreateByTemp( String ids, ContentPost post ) { int[] arrIds = cvt.ToIntArray( ids ); if (arrIds.Length == 0) return; int attachmentCount = 0; foreach (int id in arrIds) { ContentAttachmentTemp at = ContentAttachmentTemp.findById( id ); if (at == null) continue; ContentAttachment a = new ContentAttachment(); a.AppId = at.AppId; a.Guid = at.Guid; a.FileSize = at.FileSize; a.Type = at.Type; a.Name = at.Name; a.Description = at.Description; a.PostId = post.Id; a.OwnerId = post.OwnerId; a.OwnerType = post.OwnerType; a.OwnerUrl = post.OwnerUrl; a.Creator = post.Creator; a.CreatorUrl = post.CreatorUrl; a.insert(); at.delete(); attachmentCount++; } post.Attachments = attachmentCount; post.update( "Attachments" ); }
private Boolean isImage( ContentAttachment attachment ) { return Uploader.IsImage( attachment.Type ); }
public void SaveAdd( int postId ) { ContentPost post = postService.GetById( postId, ctx.owner.Id ); HttpFile postedFile = ctx.GetFileSingle(); Result result = Uploader.SaveFileOrImage( postedFile ); if (result.HasErrors) { errors.Join( result ); run( Add, postId ); return; } ContentAttachment uploadFile = new ContentAttachment(); uploadFile.FileSize = postedFile.ContentLength; uploadFile.Type = postedFile.ContentType; uploadFile.Name = result.Info.ToString(); uploadFile.Description = ctx.Post( "Name" ); uploadFile.AppId = ctx.app.Id; uploadFile.PostId = postId; attachService.Create( uploadFile, (User)ctx.viewer.obj, ctx.owner.obj ); echoToParentPart( lang( "opok" ) ); }
public virtual void UpdateName( ContentAttachment attachment, string name ) { attachment.Description = name; attachment.update( "Description" ); }
public virtual void AddHits( ContentAttachment attachment ) { attachment.Downloads++; db.update( attachment, "Downloads" ); }
private static void refreshAttachmentCount( ContentAttachment at ) { ContentPost post = ContentPost.findById( at.PostId ); if (post == null) return; int count = ContentAttachment.count( "PostId=" + post.Id ); post.Attachments = count; post.update(); }
public ActionResult UploadContentAttachment() { IUser user = UserContext.CurrentUser; if (user == null) { return new EmptyResult(); } ContentAttachmentService attachementService = new ContentAttachmentService(); long userId = user.UserId; string userDisplayName = user.DisplayName; long attachmentId = 0; if (Request.Files.Count > 0 && Request.Files["Filedata"] != null) { HttpPostedFileBase postFile = Request.Files["Filedata"]; string fileName = postFile.FileName; string contentType = MimeTypeConfiguration.GetMimeType(postFile.FileName); ContentAttachment attachment = new ContentAttachment(postFile, contentType); attachment.UserId = userId; attachment.UserDisplayName = userDisplayName; using (Stream stream = postFile.InputStream) { attachementService.Create(attachment, stream); } attachmentId = attachment.AttachmentId; } return Json(new { AttachmentId = attachmentId }); }