public ActionResult WizardImport(BlogMLWizardImportModel m) { try { //validate if (string.IsNullOrEmpty(m.Owner) || m.Owner.Trim().Length == 0) ModelState.AddModelError("owner", "Owner is required."); if (m.Year < 1990 || m.Year > 2090) ModelState.AddModelError("year", "Please choose a valid year."); if (string.IsNullOrEmpty(m.BlogName) || m.BlogName.Trim().Length == 0) ModelState.AddModelError("blogName", "The blog name is required."); if (m.BlogMLFile == null && Request.Files.Count > 0) m.BlogMLFile = Request.Files[0]; if (m.BlogMLFile == null || m.BlogMLFile.ContentLength < 10) ModelState.AddModelError("blogmlfile", "Please post a valid BlogML file."); if (ModelState.IsValid) { ProcessBlogMLFile(m); return RedirectToAction("ThemeChoice", "Wizard"); } } catch (Exception ex) { ModelState.AddModelError("error", ex); LogService.Error(ex); } return View("BlogMLWizardImport", "Wizard", m); }
public ActionResult WizardImport() { BlogMLWizardImportModel m = new BlogMLWizardImportModel() { BlogName = "blog", PagesName = "pages", MediaName = "media", Owner = "example.com", Year = DateTime.Today.Year }; return View("BlogMLWizardImport", "Wizard", m); }
private void ProcessBlogMLFile(BlogMLWizardImportModel m) { BlogMLBlog blog = null; using (XmlReader r = new XmlTextReader(m.BlogMLFile.InputStream)) { blog = BlogMLSerializer.Deserialize(r); } BlogMLService.Import(new Id(m.Owner, m.Year.ToString(), m.BlogName), !string.IsNullOrEmpty(m.PagesName) ? new Id(m.Owner, m.Year.ToString(), m.PagesName) : null, !string.IsNullOrEmpty(m.MediaName) ? new Id(m.Owner, m.Year.ToString(), m.MediaName) : null, ImportMode.New, blog); var uri = new Uri(Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath); if (!uri.ToString().EndsWith("/")) uri = new Uri(uri.ToString() + "/"); AppService appSvc = AppServiceRepository.GetService(); appSvc.Base = uri; AppServiceRepository.UpdateService(appSvc); }