public ActionResult Edit(AssetViewModel asset) { using (var dtx = new HeimContext()) { asset.Updated = DateTimeOffset.UtcNow; SaveAssetFiles(dtx, asset); dtx.Entry <Asset>(asset).State = EntityState.Modified; dtx.SaveChanges(); return(View(asset)); } }
private void SaveAssetFiles(HeimContext dtx, AssetViewModel mat) { // Save Material file and Preview file IStorage storage = null; string root = null; // prepare storage if (mat.PreviewImageFile != null || mat.AssetFile != null) { root = ConfigurationManager.AppSettings["UserDataRoot"]; root = Path.Combine(root, "assets", mat.ID.ToString()); storage = this.GetStorage(Server.MapPath(root)); storage.EnsureRootExist(); } string ext = ""; if (mat.PreviewImageFile != null) { ext = mat.PreviewImageFile.InputStream.GetFileExtension(); ext = ext == null ? null : ext.ToLower(); if (mat != null) { mat.PreviewFilePath = Path.Combine(root, "pre_" + mat.Updated.Ticks.ToString() + ext).Replace('\\', '/'); storage.Save(mat.PreviewImageFile.InputStream, "pre_" + mat.Updated.Ticks.ToString() + ext); } } if (mat.AssetFile != null) { ext = mat.AssetFile.InputStream.GetFileExtension(); ext = ext == null ? null : ext.ToLower(); if (ext != null) { mat.AssetFilePath = Path.Combine(root, mat.Updated.Ticks.ToString() + ext).Replace('\\', '/'); storage.Save(mat.AssetFile.InputStream, mat.Updated.Ticks.ToString() + ext); } } }
public ActionResult Create([Bind(Exclude = "ID")] AssetViewModel mat) { using (var dtx = new HeimContext()) { if (ModelState.IsValid) { mat.Created = DateTimeOffset.UtcNow; mat.Updated = mat.Created; dtx.Assets.Add(mat as Asset); dtx.SaveChanges(); SaveAssetFiles(dtx, mat); dtx.Entry <Asset>(mat as Asset).State = EntityState.Modified; dtx.SaveChanges(); } return(View(mat)); } }
public ActionResult Edit(AssetViewModel asset) { using(var dtx = new HeimContext()) { asset.Updated = DateTimeOffset.UtcNow; SaveAssetFiles(dtx, asset); dtx.Entry<Asset>(asset).State = EntityState.Modified; dtx.SaveChanges(); return View(asset); } }
private void SaveAssetFiles(HeimContext dtx, AssetViewModel mat) { // Save Material file and Preview file IStorage storage = null; string root = null; // prepare storage if(mat.PreviewImageFile != null || mat.AssetFile != null) { root = ConfigurationManager.AppSettings["UserDataRoot"]; root = Path.Combine(root, "assets", mat.ID.ToString()); storage = this.GetStorage(Server.MapPath(root)); storage.EnsureRootExist(); } string ext = ""; if(mat.PreviewImageFile != null) { ext = mat.PreviewImageFile.InputStream.GetFileExtension(); ext = ext == null ? null : ext.ToLower(); if(mat != null) { mat.PreviewFilePath = Path.Combine(root, "pre_" + mat.Updated.Ticks.ToString() + ext).Replace('\\', '/'); storage.Save(mat.PreviewImageFile.InputStream, "pre_" + mat.Updated.Ticks.ToString() + ext); } } if(mat.AssetFile != null) { ext = mat.AssetFile.InputStream.GetFileExtension(); ext = ext == null ? null : ext.ToLower(); if(ext != null) { mat.AssetFilePath = Path.Combine(root, mat.Updated.Ticks.ToString() + ext).Replace('\\', '/'); storage.Save(mat.AssetFile.InputStream, mat.Updated.Ticks.ToString() + ext); } } }