public ActionResult EditFlash(FlashContent model,HttpPostedFileBase fileUploadPreview) { using (var context = new SiteContainer()) { var flashContent = context.FlashContent.Include("Project").First(f => f.Id == model.Id); var project = flashContent.Project; ViewBag.projectId = project.Id; ViewBag.projectName = project.Name; //TryUpdateModel(flashContent, new[] {"Title"}); if (fileUploadPreview != null) { var file = fileUploadPreview; var fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName); var filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); file.SaveAs(filePath); flashContent.ImageSourcePreview = fileName; flashContent.Title = model.Title ?? ""; context.SaveChanges(); } else { ViewBag.Errormessage = "Выберите файлы для загрузки!"; return View(); } context.SaveChanges(); return RedirectToAction("Projects", "Home", new { area = "", id = project.Name }); } }
/// <summary> /// Create a new FlashContent object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="imageSource">Initial value of the ImageSource property.</param> /// <param name="title">Initial value of the Title property.</param> /// <param name="projectId">Initial value of the ProjectId property.</param> /// <param name="imageSourcePreview">Initial value of the ImageSourcePreview property.</param> public static FlashContent CreateFlashContent(global::System.Int32 id, global::System.String imageSource, global::System.String title, global::System.Int32 projectId, global::System.String imageSourcePreview) { FlashContent flashContent = new FlashContent(); flashContent.Id = id; flashContent.ImageSource = imageSource; flashContent.Title = title; flashContent.ProjectId = projectId; flashContent.ImageSourcePreview = imageSourcePreview; return flashContent; }
public ActionResult AddFlashToProject(FlashContent model, int projectId, HttpPostedFileBase fileUpload, HttpPostedFileBase fileUploadPreview) { using (var context = new SiteContainer()) { var project = context.Project.First(p => p.Id == projectId); ViewBag.projectId = project.Id; ViewBag.projectName = project.Name; try { if (fileUpload != null && fileUploadPreview != null) { var file = fileUpload; var pi = new FlashContent(); string fileName = IOHelper.GetUploadFileName("~/Content/TmpArchive", file.FileName); string filePath = Server.MapPath("~/Content/TmpArchive"); //string flashSourceFilePath = filePath; //string flashDestFilePath = filePath; filePath = Path.Combine(filePath, fileName); file.SaveAs(filePath); string archiveName = Path.GetFileNameWithoutExtension(fileName); string extractedArchivePath = Path.Combine(Server.MapPath("~/Content/FlashContent"), archiveName); Directory.CreateDirectory(extractedArchivePath); using (ZipFile zip = ZipFile.Read(filePath)) { foreach (ZipEntry e in zip) { e.Extract(extractedArchivePath, true); // true => overwrite existing files } } System.IO.File.Delete(filePath); file = fileUploadPreview; fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName); filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); file.SaveAs(filePath); pi.ImageSourcePreview = fileName; pi.ImageSource = archiveName; pi.Title = model.Title??""; project.FlashContents.Add(pi); context.SaveChanges(); } else { ViewBag.Errormessage = "Выберите файлы для загрузки!"; return View(); } return RedirectToAction("Projects", "Home", new { area = "", id = project.Name }); } catch (Exception ex) { ViewBag.Errormessage = ex.Message; return View(); } //string filePath = Server.MapPath("~/Content/Flash1/ponedelnik.zip"); //string destPath = Server.MapPath("~/Content/Flash2"); //using (ZipFile zip = ZipFile.Read(filePath)) //{ // foreach (ZipEntry e in zip) // { // e.Extract(destPath, true); // true => overwrite existing files // } //} } }
/// <summary> /// Deprecated Method for adding a new object to the FlashContent EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToFlashContent(FlashContent flashContent) { base.AddObject("FlashContent", flashContent); }