protected void lbUploadImage_Click(object sender, EventArgs e) { if (fuImage.HasFile) { // Create new brand media row to get id BrandMedia newMedia = new BrandMedia(); newMedia.BrandId = GetIntState(BRAND_ID); newMedia.MediaFilename = fuImage.FileName; newMedia.Id = BrandService.InsertBrandMedia(newMedia); // Save image string filename = newMedia.Id.ToString() + Path.GetExtension(fuImage.FileName).ToLower(); fuImage.SaveAs(MediaSettings.BrandMediaLocalPath + filename); // Update brand media newMedia.MediaFilename = filename; BrandService.UpdateBrandMedia(newMedia); PopulateBrandInfo(GetIntState(BRAND_ID)); hfCurrentPanel.Value = "media"; enbNotice.Message = "Image was added successfully."; } else { enbNotice.Message = "Sorry, there is no image to upload."; } }
public ActionResult UploadLogo(int BrandID) { using (var unit = GetUnitOfWork()) { var Brand = unit.Service <Brand>().Get(b => b.BrandID == BrandID); string fileName = ""; foreach (string f in Request.Files) { var upload = Request.Files.Get(f); //var extension = upload.FileName.Substring(upload.FileName.LastIndexOf(".") + 1); //var fileName = BrandID + "_logo." + extension; fileName = ExtractFileName(upload.FileName); var path = ConfigurationManager.AppSettings["FTPBrandLogoDirectory"]; //var type = (Request["TypeID"]).ToString(); var targetPath = Path.Combine(path, fileName); var physicalDirectory = Path.Combine(ConfigurationManager.AppSettings["FTPMediaDirectory"], path); var fullPath = Path.Combine(ConfigurationManager.AppSettings["FTPMediaDirectory"], targetPath); //no file if (!Directory.Exists(physicalDirectory)) { Directory.CreateDirectory(physicalDirectory); } using (var st = upload.InputStream) { //copy it locally byte[] buff = new byte[st.Length]; st.Read(buff, 0, (int)st.Length); System.IO.File.WriteAllBytes(fullPath, buff); //set the path } BrandMedia bm = new BrandMedia() { TypeID = 1, BrandID = Brand.BrandID, Sequence = 0, MediaPath = targetPath }; unit.Service <BrandMedia>().Create(bm); } unit.Save(); return(new JsonResult { ContentType = "text/html", Data = new { success = true, message = fileName + " is succesfully uploaded." } }); } }
public void UpdateBrandMedia(BrandMedia media) { _brandMediaRepository.Update(media); _cacheManager.RemoveByPattern(CacheKey.BRAND_PATTERN_KEY); }
public int InsertBrandMedia(BrandMedia media) { return(_brandMediaRepository.Create(media)); }