public ActionResult Upload(long?id, string qqfile) { // determine file type var isimage = qqfile.IsImage(); var filename = Path.GetFileNameWithoutExtension(qqfile); var ext = Path.GetExtension(qqfile); if (isimage) { var uploader = new FileHandler(filename.ToSafeUrl() + ext, UploaderType.PHOTO, sessionid); var thisImage = new blog_image(); thisImage.url = uploader.url; bool ok = uploader.Save(Request.InputStream); if (!ok) { return(Json("An error has occurred. Unable to save blog image".ToJsonFail())); } // save to database var imageid = repository.AddBlogImage(thisImage); string thumbnailUrl = Img.by_size(thisImage.url, Imgsize.USER_PROFILE); if (id.HasValue) { thisImage.blogid = id.Value; repository.Save(); } return(Json(new { id = imageid, url = thumbnailUrl }.ToJsonOKData())); } else { var uploader = new FileHandler(filename.ToSafeUrl() + ext, UploaderType.BLOG, sessionid); var file = new blog_file(); file.url = uploader.url; file.name = qqfile; bool ok = uploader.Save(Request.InputStream); if (!ok) { return(Json("An error has occurred. Unable to save blog file".ToJsonFail())); } // save to database var fileid = repository.AddBlogFile(file); if (id.HasValue) { file.blogid = id.Value; repository.Save(); } return(Json(new{ id = fileid, url = file.url, name = file.name }.ToJsonOKData())); } }
public long AddBlogFile(blog_file file) { db.blog_files.InsertOnSubmit(file); Save(); return(file.id); }