public ActionResult Upload(IEnumerable<HttpPostedFileBase> files, ImportViewModel model) { string errorMessage = _blogMLService.SaveAndImport(files.ToList(), model); if (string.IsNullOrEmpty(errorMessage)) return RedirectToAction("Successful"); ImportViewModel modelReloaded = ImportViewModel(); return View("Index",modelReloaded); }
public string Import(string path, ImportViewModel model) { XmlTextReader xmlStream = _streamHelper.StringToXmlReader(path); BlogMLBlog blogMl = BlogMLSerializer.Deserialize(xmlStream); IList<Post> posts = _blogMLMappingService.MapToEntity(blogMl); string errorMessage = _importRepository.ImportPosts(posts, model.SelectedBlogSite, model.SelectedUserId); return errorMessage; }
public string SaveAndImport(IList<HttpPostedFileBase> files, ImportViewModel model) { if (files == null || !files.Any()) return "No files were provided"; string fileName = Path.GetFileName(files[0].FileName); string path = _httpHelper.GetPath("~/App_Data/blogml", fileName); files[0].SaveAs(path); string errorMessage = Import(path, model); return errorMessage; }
private ImportViewModel ImportViewModel() { List<BlogSiteViewModel> blogs = _blogSiteService.GetBlogsAll() .Where(x => x.IsActive) .ToList(); BlogSiteViewModel primary = _blogSiteService.GetBlogsAll() .FirstOrDefault(x => x.IsPrimary); SelectList selectList = primary == null ? new SelectList(blogs, "BlogId", "BlogName") : new SelectList(blogs, "BlogId", "BlogName", primary.BlogId); List<UserViewModel> users = _profileUserService.GetAllUsers() .Where(x => x.IsActive) .ToList(); var uSelectList = new SelectList(users, "Id", "UserName"); var model = new ImportViewModel { BlogSiteList = selectList, UserList = uSelectList }; return model; }