public async Task <IActionResult> Create([Bind("ID,BackgroundImageName,BackgroundImageFileName,BackgroundImageFilePath,BackgroundImage")] PageManagerViewModel pageManager) { if (ModelState.IsValid) { /* Upload file to images bgpageimages folder. */ if (pageManager.BackgroundImage != null) { var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/bgpageimages/", pageManager.BackgroundImage.FileName); using (var stream = new FileStream(path, FileMode.Create)){ await pageManager.BackgroundImage.CopyToAsync(stream); } pageManager.BackgroundImageFileName = pageManager.BackgroundImage.FileName; pageManager.BackgroundImageFilePath = path; } PageManager newItem = new PageManager() { BackgroundImageFileName = pageManager.BackgroundImage.FileName, BackgroundImageName = pageManager.BackgroundImageName, BackgroundImageFilePath = pageManager.BackgroundImageFilePath }; _context.Add(newItem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(pageManager)); }
// GET: PageManagers public async Task <IActionResult> Index() { List <PageManagerViewModel> pageMgrList = new List <PageManagerViewModel>(); PageManagerViewModel pageMgrItem; await _context.PageManager.ForEachAsync(delegate(PageManager item) { pageMgrItem = new PageManagerViewModel() { ID = item.ID, BackgroundImageFileName = item.BackgroundImageFileName, BackgroundImageFilePath = item.BackgroundImageFilePath, BackgroundImageName = item.BackgroundImageName }; pageMgrList.Add(pageMgrItem); }); return(View(pageMgrList.ToList())); }
/// <summary> /// Check if pre-requisites for closing application are available. /// Save session data on closing and cancel closing process if necessary. /// </summary> /// <returns>true if application is OK to proceed closing with closed, otherwise false.</returns> public bool Exit_CheckConditions(object sender) { var msg = ServiceLocator.ServiceContainer.Instance.GetService <IMessageBoxService>(); try { if (mShutDownInProgress == true) { return(true); } var docSource = sender as IDocumentCollection; if (docSource == null) { return(true); } IList <IDirtyDocument> dirtyDocs = docSource.GetDirtyDocuments(); if (dirtyDocs == null) { return(true); } return(PageManagerViewModel.GetOKToLeavePageWithoutSave(dirtyDocs)); ////// Do layout serialization after saving/closing files ////// since changes implemented by shut-down process are otherwise lost ////try ////{ //// App.CreateAppDataFolder(); //// this.SerializeLayout(sender); // Store the current layout for later retrieval ////} ////catch ////{ ////} } catch (Exception exp) { logger.Error(exp.Message, exp); msg.Show(exp, Local.Strings.STR_UNEXPECTED_ERROR, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton); //App.IssueTrackerLink, App.IssueTrackerLink, Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } return(true); }
public async Task <IActionResult> Edit(int id, [Bind("ID,BackgroundImageName,BackgroundImageFileName,BackgroundImageFilePath,BackgroundImage")] PageManagerViewModel pageManager) { if (id != pageManager.ID) { return(NotFound()); } if (ModelState.IsValid) { try { PageManager currentItem = _context.PageManager.Where(a => a.ID == pageManager.ID).FirstOrDefault(); // Upload the new image. if (pageManager.BackgroundImage != null) { //Delete the previous file System.IO.File.Delete(currentItem.BackgroundImageFilePath); var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/bgpageimages/", pageManager.BackgroundImage.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await pageManager.BackgroundImage.CopyToAsync(stream); } // Delete the previous file currentItem.BackgroundImageFilePath = path; currentItem.BackgroundImageFileName = pageManager.BackgroundImage.FileName; } currentItem.BackgroundImageName = pageManager.BackgroundImageName; _context.Update(currentItem); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PageManagerExists(pageManager.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(pageManager)); }
// GET: PageManagers/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var pageManager = await _context.PageManager.SingleOrDefaultAsync(m => m.ID == id); if (pageManager == null) { return(NotFound()); } PageManagerViewModel pageManagerItem = new PageManagerViewModel() { ID = pageManager.ID, BackgroundImageFileName = pageManager.BackgroundImageFileName, BackgroundImageFilePath = pageManager.BackgroundImageFilePath, BackgroundImageName = pageManager.BackgroundImageName }; return(View(pageManagerItem)); }