public async Task <ActionResult> AddBanner(Banner model, HttpPostedFileBase upload, string SinglePage) { if (upload != null) { Banner banner = new Banner { Id = Guid.NewGuid(), Name = model.Name, SinglePage = CheckSinglePageBanner(SinglePage), Description = model.Description, Link = model.Link, DateCreate = DateTime.Now }; string fileName = System.IO.Path.GetFileName(upload.FileName); var pathFile = System.IO.Path.Combine(Server.MapPath("~/Files"), fileName); upload.SaveAs(pathFile); var splitPathFile = pathFile.Split('\\'); string correctPathFile = string.Format("/{0}/{1}", splitPathFile[5], splitPathFile[6]); ImageBanner imgban = new ImageBanner { Id = Guid.NewGuid(), Banners = banner, Path = correctPathFile, DateCreate = DateTime.Now }; _context.ImageBanners.Add(imgban); TempData["Flag"] = "Success"; _context.Banners.Add(banner); _context.SaveChanges(); TempData["Flag"] = "Success"; } else { TempData["Flag"] = "Fail"; } return(RedirectToAction("Index")); }
void FreeImageResources( ) { if (HeaderImage != null) { HeaderImage.Recycle( ); HeaderImage.Dispose( ); HeaderImage = null; } if (ImageBanner != null && ImageBanner.Drawable != null) { ImageBanner.Drawable.Dispose( ); ImageBanner.SetImageBitmap(null); } }
void mapSavedPicturesToImageBanners(List <Picture> images, List <ImageBanner> banners) { foreach (var image in images) { ImageBanner banner = new ImageBanner(); banner.ID = image.ID; banner.X = image.X; banner.Y = image.Y; banner.Link = image.Link; banner.BinaryContent = image.Data; banner.ContentType = image.ContentType; banner.Width = image.Width; banner.Height = image.Height; banners.Add(banner); } }
bool TryLoadBanner(string filename) { // if the file exists if (FileCache.Instance.FileExists(filename) == true) { // load it asynchronously AsyncLoader.LoadImage(filename, false, false, delegate(Bitmap imageBmp) { if (IsFragmentActive == true) { // if for some reason it loaded corrupt, remove it. if (imageBmp == null) { FileCache.Instance.RemoveFile(filename); return(false); } else { FreeImageResources( ); HeaderImage = imageBmp; ImageBanner.SetImageBitmap(HeaderImage); ImageBanner.Invalidate( ); Rock.Mobile.PlatformSpecific.Android.UI.Util.FadeView(ImageBanner, true, null); return(true); } } return(false); }); return(true); } else { return(false); } }
void SetupDisplay(View view) { // get the placeholder image in case we need it // attempt to load the image from cache. If that doesn't work, use a placeholder HeaderImage = null; bool imageExists = TryLoadBanner(HeaderImageName); if (imageExists == false) { // use the placeholder and request the image download string widthParam = string.Format("&width={0}", NavbarFragment.GetContainerDisplayWidth_Landscape( )); string requestUrl = Rock.Mobile.Util.Strings.Parsers.AddParamToURL(HeaderImageURL, widthParam); FileCache.Instance.DownloadFileToCache(requestUrl, HeaderImageName, null, delegate { TryLoadBanner(HeaderImageName); }); AsyncLoader.LoadImage(PrivateGeneralConfig.NewsDetailsPlaceholder, true, false, delegate(Bitmap imageBmp) { if (IsFragmentActive == true && imageBmp != null) { HeaderImage = imageBmp; ImageBanner.SetImageBitmap(HeaderImage); ImageBanner.Invalidate( ); Rock.Mobile.PlatformSpecific.Android.UI.Util.FadeView(ImageBanner, true, null); return(true); } return(false); }); } }
protected void submit_banner_Click(object sender, EventArgs e) { eWorldEntities db = new eWorldEntities(); var tmp = db.ImageBanners; db.ImageBanners.RemoveRange(tmp); if (banner.HasFiles) { foreach (HttpPostedFile uploadedFile in banner.PostedFiles) { uploadedFile.SaveAs(MapPath("~/style/image/banner/") + uploadedFile.FileName); listofuploadedfiles.Text += String.Format("<br />{0}", uploadedFile.FileName); ImageBanner im = new ImageBanner(); im.Path = uploadedFile.FileName; db.ImageBanners.Add(im); } } }