public ActionResult Index(FormCollection collection) { var item = new Upload(); var whiteList = new string[] { "Artist", "Name", "Tab", "BookId" }; if (TryUpdateModel(item, whiteList, collection.ToValueProvider())) { if (ModelState.IsValid) { //_uploadService.Upload(item.Artist, item.Name, item.BookId, item.Tab, User.Identity.Name); var tab = new Tab { Artist = item.Artist, Name = item.Name, Content = item.Tab, CreatedOn = DateTime.UtcNow, AuthorName = User.Identity.Name }; RavenSession.Store(tab); if (item.BookId > 0) { var bookTasks = new BookTasks(); bookTasks.AddTabToBook(tab.Id, item.BookId.Value); } TempData.Add(Constants.TempDataMessage, "Upload successful, thanks!"); return RedirectToAction("Index", "Songs"); } } return View(); }
public void Import() { var path = ConfigurationManager.AppSettings["ImportFolder"]; if (string.IsNullOrEmpty(path)) { return; } var physicalPath = System.Web.HttpContext.Current.Server.MapPath(path); using (var session = RavenController.DocumentStore.OpenSession()) { var book = session.Query<Book>().Where(x => x.Name.Equals("Singalong")).FirstOrDefault(); var bookTasks = new BookTasks(); foreach (var filePath in Directory.GetFiles(physicalPath)) { var filename = Path.GetFileNameWithoutExtension(filePath); var parts = filename.Split(new[] { " - " }, System.StringSplitOptions.None); if (parts.Length != 2) { continue; } var artist = parts[0].Trim(); var name = parts[1].Trim(); var content = File.ReadAllText(filePath); var tab = new Tab { Artist = artist, Name = name, Content = content, CreatedOn = DateTime.Now }; session.Store(tab); bookTasks.AddTabToBook(tab.Id, book.Id); File.Delete(filePath); } session.SaveChanges(); } }