public async Task <ActionResult> Edit([Bind(Include = "Id,Name,Active,Slides,Presenter")] ScreenSaverItem screenSaverItem) { screenSaverItem.Modified = DateTimeOffset.Now; if (ModelState.IsValid) { SavePowerPointSlidesToServer(screenSaverItem); db.Entry(screenSaverItem).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ModelState["Slides"].Errors.Clear(); if (ModelState.IsValid) { try { db.Configuration.ValidateOnSaveEnabled = false; db.Entry(screenSaverItem).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } catch { } finally { db.Configuration.ValidateOnSaveEnabled = true; } } return(View(screenSaverItem)); }
public async Task <ActionResult> DeleteConfirmed(int id) { ScreenSaverItem screenSaverItem = await db.ScreenSaverItems.FindAsync(id); db.ScreenSaverItems.Remove(screenSaverItem); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <FileResult> GetSlide(int id) { ScreenSaverItem screenSaverItem = await db.ScreenSaverItems.FindAsync(id); using (var slidefile = new System.IO.FileStream(screenSaverItem.SlidesPath, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { byte[] data = new byte[slidefile.Length]; await slidefile.ReadAsync(data, 0, data.Length); return(File(data, System.Net.Mime.MediaTypeNames.Application.Octet, screenSaverItem.Name + ".pptx")); } }
// GET: ScreenSaver/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ScreenSaverItem screenSaverItem = await db.ScreenSaverItems.FindAsync(id); if (screenSaverItem == null) { return(HttpNotFound()); } return(View(screenSaverItem)); }
private void SavePowerPointSlidesToServer(ScreenSaverItem screenSaverItem) { var path = System.IO.Path.Combine(Server.MapPath(Nebulus.AppConfiguration.Settings.FileStorageLocation)); if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } var filepath = path + screenSaverItem.Id + System.IO.Path.GetExtension(screenSaverItem.Slides.FileName); screenSaverItem.Slides.SaveAs(filepath); screenSaverItem.SlidesPath = filepath; }
public async Task <ActionResult> Create([Bind(Include = "Id,Created,Modified,Name,Slides,CreatorId,Active,Presenter")] ScreenSaverItem screenSaverItem) { if (ModelState.IsValid) { screenSaverItem.Created = DateTimeOffset.Now; screenSaverItem.Modified = screenSaverItem.Created; screenSaverItem.CreatorId = User.Identity.GetUserId(); db.ScreenSaverItems.Add(screenSaverItem); await db.SaveChangesAsync(); SavePowerPointSlidesToServer(screenSaverItem); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(screenSaverItem)); }