//AJAX CALL public ActionResult AjaxSearchMaster(string wordsToSearch) { theLogger.Info(String.Format("method GetPlaysForSource, parameter wordsToSearch {0}", wordsToSearch)); if (String.IsNullOrWhiteSpace(wordsToSearch)) { theLogger.Error("Reason: wordsToSearch is null or white space"); return(PartialView("AjaxSearchForMaster", new List <ScoreSearchItem>())); } FoireMusesConnection connection = GetConnection(); SearchResult <ScoreSearchItem> searchResultMaster = null; try { searchResultMaster = connection.SearchScore(0, 20, new Dictionary <string, object>() { { "isMaster", true }, { "titleWild", wordsToSearch } }, new Result <SearchResult <ScoreSearchItem> >()).Wait(); } catch (Exception e) { theLogger.Error("Stacktrace:\n" + e.StackTrace); return(PartialView("AjaxSearchForMaster", new List <ScoreSearchItem>())); } if (searchResultMaster == null) { theLogger.Error("Reason: searchResultMaster is null"); return(PartialView("AjaxSearchForMaster", new List <ScoreSearchItem>())); } return(PartialView("AjaxSearchForMaster", searchResultMaster.Rows)); }
//AJAX CALL public ActionResult GetPlaysForSource(string id) { theLogger.Info(String.Format("method GetPlaysForSource, parameter id {0}", id)); if (String.IsNullOrWhiteSpace(id)) { theLogger.Error("Reason: id is null or white space"); return(PartialView("playList", new List <Play>())); } FoireMusesConnection connection = GetConnection(); SearchResult <Play> searchResultPlay = null; try { searchResultPlay = connection.GetPlaysFromSource(id, 0, 0, new Result <SearchResult <Play> >()).Wait(); } catch (Exception e) { theLogger.Error("Stacktrace:\n" + e.StackTrace); return(PartialView("playList", new List <Play>())); } if (searchResultPlay == null) { theLogger.Error("Reason: searchResultPlay result is null"); return(PartialView("playList", new List <Play>())); } return(PartialView("playList", searchResultPlay.Rows)); }
public ActionResult Edit(string sourceId) { FoireMusesConnection connection = GetConnection(); Source source = null; try { if (sourceId != null) //get the score matching the id { source = connection.GetSource(sourceId, new Result <Source>()).Wait(); if (source == null) { return(RedirectToAction("Missing", "Error", null)); } ViewBag.HeadTitle = "Edition"; } else { source = new Source(); ViewBag.HeadTitle = "Creation"; } } catch (ArgumentException e) { ViewBag.Error = "Veuillez remplir les champs correctement"; return(View("Edit", source)); } catch (Exception e) { return(RedirectToAction("Problem", "Error", null)); } return(View("Edit", source)); }
public ActionResult SearchScore(string title = null, string editor = null, string composer = null, string verses = null, int page = 1) { FoireMusesConnection connection = GetConnection(); if (String.IsNullOrWhiteSpace(title) && String.IsNullOrWhiteSpace(editor) && String.IsNullOrWhiteSpace(composer) && String.IsNullOrWhiteSpace(verses)) { ViewBag.Error = "You must specify at least one criteria before making a search"; return(View("Score")); } SearchResult <ScoreSearchItem> searchResult = null; try { searchResult = connection.SearchScore((page - 1) * PageSize, PageSize, new Dictionary <string, object>() { { "title", title }, { "editor", editor }, { "composer", composer }, { "verses", verses } }, new Result <SearchResult <ScoreSearchItem> >()).Wait(); } catch (Exception e) { return(RedirectToAction("Problem", "Error", null)); } var viewModel = new ListViewModel <ScoreSearchItem>() { CurrentPage = page, SearchResult = searchResult }; return(View("ListScoreSearch", viewModel)); }
// // GET: /Scores/Details public ViewResult Details(string sourceId) { //use mindtouch dream to access the web service. // treat the result and return it to the view FoireMusesConnection connection = GetConnection(); Source source = null; IList <SourcePageSearchItem> pages = null; IEnumerable <string> attachedFiles = null; IEnumerable <string> documents = null; try { source = connection.GetSource(sourceId, new Result <Source>()).Wait(); if (source.HasAttachement) { attachedFiles = source.GetAttachmentNames().Where(x => !x.StartsWith("$")); documents = source.GetAttachmentNames().Where(x => x.StartsWith("$")); } pages = connection.GetSourcePagesFromSource(source.Id, 0, 0, new Result <SearchResult <SourcePageSearchItem> >()).Wait().Rows; } catch (Exception e) { // do stuff to return error message to the screen } ViewBag.AttachedFiles = attachedFiles; ViewBag.Documents = documents; ViewBag.Pages = pages; return(View(source)); }
public ActionResult Download(string scoreId, string fileType, string fileName) { FoireMusesConnection connection = GetConnection(); Stream theStream; string contentType; switch (fileType) { case "pdf": contentType = "application/pdf"; break; case "mid": contentType = "audio/midi"; break; case "musicxml": contentType = "text/xml"; break; default: contentType = ""; break; } try { theStream = connection.GetConvertedScore(scoreId, fileName, new Result <Stream>()).Wait(); } catch (Exception e) { return(RedirectToAction("Problem", "Error", null)); } return(File(theStream, contentType, fileName)); }
public ActionResult SearchMusic(string music = null, int page = 1) { if (String.IsNullOrWhiteSpace(music)) { ViewBag.Error = "You must at least search for one note"; return(View("Music")); } FoireMusesConnection connection = GetConnection(); SearchResult <ScoreSearchItem> searchResult = null; try { searchResult = connection.SearchScore((page - 1) * PageSize, PageSize, new Dictionary <string, object>() { { "music", music } }, new Result <SearchResult <ScoreSearchItem> >()).Wait(); } catch (Exception e) { return(RedirectToAction("Problem", "Error", null)); } var viewModel = new ListViewModel <ScoreSearchItem>() { CurrentPage = page, SearchResult = searchResult }; return(View("ListScoreSearch", viewModel)); }
public ActionResult Edit(string scoreId) { theLogger.Info(String.Format("GET method Edit, parameter scoreId {0}", scoreId)); FoireMusesConnection connection = GetConnection(); Score score = null; SearchResult <SourceSearchItem> sourceList = null; try { if (!String.IsNullOrWhiteSpace(scoreId)) //get the score matching the id { score = connection.GetScore(scoreId, new Result <Score>()).Wait(); if (score == null) { return(RedirectToAction("Missing", "Error", null)); } if (score.TextualSource != null && score.TextualSource.PieceId != null) { SearchResult <Play> searchResultPlay = null; searchResultPlay = connection.GetPlaysFromSource(score.TextualSource.SourceId, 0, 0, new Result <SearchResult <Play> >()).Wait(); if (searchResultPlay == null) { return(RedirectToAction("Problem", "Error", null)); } ViewBag.Pieces = searchResultPlay.Rows; } if (score.MasterId != null) { Score maitre = connection.GetScore(score.MasterId, new Result <Score>()).Wait(); if (maitre == null) { score.MasterId = null; } else { ViewBag.MasterIdTitle = maitre.Title; } } ViewBag.HeadTitle = "Edition"; } else { score = new Score(); ViewBag.HeadTitle = "Création"; } sourceList = connection.GetSources(0, 0, new Result <SearchResult <SourceSearchItem> >()).Wait(); } catch (Exception e) { return(RedirectToAction("Problem", "Error", null)); } if (score == null || sourceList == null) { return(RedirectToAction("Missing", "Error", null)); } ViewBag.Sources = sourceList.Rows.OrderBy(x => x.Name); return(View("Edit", score)); }
public ActionResult Edit(Score model, FormCollection collection) { theLogger.Info("POST method Edit"); if (model == null) { return(RedirectToAction("Missing", "Error", null)); } FoireMusesConnection connection = GetConnection(); try { if (model.Id == null) { if (model.TextualSource.SourceId == null) { model.TextualSource = null; } if (model.MusicalSource.SourceId == null) { model.MusicalSource = null; } model = connection.CreateScore(model, new Result <Score>()).Wait(); } else { Score current = connection.GetScore(model.Id, new Result <Score>()).Wait(); if (current == null) { return(RedirectToAction("Missing", "Error", null)); } TryUpdateModel(current); if (current.TextualSource.SourceId == null) { current.TextualSource = null; } if (current.MusicalSource.SourceId == null) { current.MusicalSource = null; } model = connection.EditScore(current, new Result <Score>()).Wait(); } } catch (Exception e) { theLogger.Error("Stacktrace:\n" + e.StackTrace); return(RedirectToAction("Problem", "Error", null)); } if (model == null) { theLogger.Error("Reason: model is null"); return(RedirectToAction("Problem", "Error", null)); } return(RedirectToAction("Details", new { scoreId = model.Id })); }
public ActionResult CreateUser(RegisterModel model) { User user = new User(); user.Id = model.Username; user.Password = model.Password; user.Email = model.Email; user.IsAdmin = model.IsAdmin; FoireMusesConnection connection = GetConnection(); user = connection.CreateUser(user, new Result <User>()).Wait(); return(RedirectToAction("Index", "Home", null)); }
public ActionResult Edit(Source model, FormCollection collection) { if (model == null) { return(RedirectToAction("Problem", "Error", null)); } if (!ValidateSource(model)) { ViewBag.Error = "Certains champs sont mal rempli ou incomplet, veuillez les remplirs correctements."; if (model.Id != null) { ViewBag.HeadTitle = "Edition"; } else { ViewBag.HeadTitle = "Creation"; } return(View("Edit", model)); } FoireMusesConnection connection = GetConnection(); try { //we use the same view to edit and create, so let's differentiate both if (model.Id == null) { model = connection.CreateSource(model, new Result <Source>()).Wait(); } else { //when updating, first get the current score out of the db then update with values Source current = connection.GetSource(model.Id, new Result <Source>()).Wait(); if (current == null) { return(RedirectToAction("Problem", "Error", null)); } TryUpdateModel(current); model = connection.EditSource(current, new Result <Source>()).Wait(); } } catch (Exception e) { return(RedirectToAction("Problem", "Error", null)); } if (model == null) { return(RedirectToAction("Problem", "Error", null)); } //redirect to details return(Redirect("Details?sourceId=" + model.Id)); }
public ActionResult Images(string scoreId, string fileName) { FoireMusesConnection connection = GetConnection(); Stream theStream; try { theStream = connection.GetAttachements(scoreId, fileName, new Result <Stream>()).Wait(); } catch (Exception e) { return(File(System.IO.File.OpenRead("~/Content/images/indisponible.gif"), "image/gif")); } return(File(theStream, "image/png")); }
protected FoireMusesConnection GetConnection() { FoireMusesConnection connection = new FoireMusesConnection(new XUri(Configuration.ApiUrl + ":" + Configuration.ApiPort + "/" + Configuration.ApiAt), Configuration.ApiUsername, Configuration.ApiPassword); if (!User.Identity.IsAuthenticated) { return(connection); } else { // Enables the remote process to use the user's credentials instead of this process' credentials //use settings to create default creditentials to be used by the server. //use some secret key connection.Impersonate(User.Identity.Name); return(connection); } }
public ActionResult PageEdit(SourcePage model) { if (!ValidatePage(model)) { ViewBag.Error = "Certains champs sont mal rempli ou incomplet, veuillez les remplirs correctements."; if (model.Id != null) { ViewBag.HeadTitle = "Edition"; } else { ViewBag.HeadTitle = "Creation"; } return(View("PageEdit", model)); } FoireMusesConnection connection = GetConnection(); try { if (model.Id == null) { model = connection.CreateSourcePage(model, new Result <SourcePage>()).Wait(); } else { SourcePage current = connection.GetSourcePage(model.Id, new Result <SourcePage>()).Wait(); if (current == null) { return(RedirectToAction("Problem", "Error", null)); } TryUpdateModel(current); model = connection.EditSourcePage(current, new Result <SourcePage>()).Wait(); } } catch (Exception e) { return(RedirectToAction("Problem", "Error", null)); } if (model == null) { return(RedirectToAction("Problem", "Error", null)); } return(View("PageDetails", model)); }
public ActionResult PageEdit(string sourcePageId, string sourceId) { FoireMusesConnection connection = GetConnection(); SourcePage page = null; try { if (sourcePageId == null) { if (String.IsNullOrWhiteSpace(sourceId)) { return(RedirectToAction("Missing", "Error", null)); } else { Source source = connection.GetSource(sourceId, new Result <Source>()).Wait(); if (source == null) { return(RedirectToAction("Missing", "Error", null)); } } ViewBag.HeadTitle = "Creation"; page = new SourcePage(); page.SourceId = sourceId; } else { page = connection.GetSourcePage(sourcePageId, new Result <SourcePage>()).Wait(); if (page == null) { return(RedirectToAction("Missing", "Error", null)); } ViewBag.HeadTitle = "Edition"; } } catch (Exception e) { return(RedirectToAction("Problem", "Error", null)); } return(View(page)); }
public ActionResult Publish(string scoreId, bool overwrite, HttpPostedFileBase file) { theLogger.Info("POST Publish"); if (file == null || file.ContentType != "text/xml" || file.ContentLength == 0) { ViewBag.Error = "Error during the upload, please be sure to choose a valid xml file from your computer"; return(View("Publish")); } FoireMusesConnection connection = GetConnection(); Score score = null; try { if (scoreId == null) { XDoc theDoc = XDocFactory.From(file.InputStream, MimeType.XML); score = connection.CreateScoreWithXml(theDoc, new Result <Score>()).Wait(); } else { Score current = connection.GetScore(scoreId, new Result <Score>()).Wait(); if (current == null) { return(RedirectToAction("Missing", "Error", null)); } score = connection.UpdateScoreWithXml(current.Id, current.Rev, XDocFactory.From(file.InputStream, MimeType.XML), overwrite, new Result <Score>()).Wait(); if (score == null) { return(RedirectToAction("Problem", "Error", null)); } return(RedirectToAction("Details", new { scoreId = score.Id })); } } catch (Exception e) { theLogger.Error("Stacktrace:\n" + e.StackTrace); return(RedirectToAction("Problem", "Error", null)); } return(RedirectToAction("Edit", new { scoreId = score.Id })); }
public override bool IsUserInRole(string username, string roleName) { if (roleName == "MEMBER") { return(true); } FoireMusesConnection connection = new FoireMusesConnection(new XUri(Configuration.ApiUrl + ":" + Configuration.ApiPort + "/" + Configuration.ApiAt), Configuration.ApiUsername, Configuration.ApiPassword); try { User user = connection.GetUser(username, new Result <User>()).Wait(); if (user.IsAdmin) { return(true); } return(false); } catch (Exception e) { return(false); } }
public override bool ValidateUser(string username, string password) { FoireMusesConnection connection = new FoireMusesConnection(new XUri(Configuration.ApiUrl + ":" + Configuration.ApiPort + "/" + Configuration.ApiAt), Configuration.ApiUsername, Configuration.ApiPassword); try { User user = connection.GetUser(username, new Result <User>()).Wait(); if (user == null) { return(false); } if (user.Password != password) { return(false); } return(true); } catch (Exception e) { return(false); } }
public override string[] GetRolesForUser(string username) { FoireMusesConnection connection = new FoireMusesConnection(new XUri(Configuration.ApiUrl + ":" + Configuration.ApiPort + "/" + Configuration.ApiAt), Configuration.ApiUsername, Configuration.ApiPassword); try { User user = connection.GetUser(username, new Result <User>()).Wait(); if (user.IsAdmin) { return new string[] { "ADMIN", "MEMBER" } } ; else { return new string[] { "MEMBER" } }; } catch (Exception e) { return(new string[] { }); } }
public ActionResult PageDetails(string sourcePageId) { if (String.IsNullOrWhiteSpace(sourcePageId)) { return(RedirectToAction("Missing", "Error", null)); } FoireMusesConnection connection = GetConnection(); SourcePage page; try { page = connection.GetSourcePage(sourcePageId, new Result <SourcePage>()).Wait(); } catch (Exception e) { return(RedirectToAction("Problem", "Error", null)); } if (page == null) { return(RedirectToAction("Missing", "Error", null)); } return(View(page)); }
public ActionResult Fascimiles(string sourceId, HttpPostedFileBase file) { if (String.IsNullOrWhiteSpace(sourceId)) { return(RedirectToAction("Missing", "Error", null)); } if (file == null || file.ContentType != "application/x-zip-compressed" || file.ContentLength == 0) { ViewBag.Error = "Error during the upload, please be sure to choose a valid zip file from your computer"; return(View("Fascimiles")); } FoireMusesConnection connection = GetConnection(); try { connection.BulkFascimile(sourceId, file.InputStream, new Result <bool>()).Wait(); } catch (Exception e) { return(RedirectToAction("Problem", "Error", null)); } return(RedirectToAction("Details", new { sourceId = sourceId })); }
public ActionResult List(int page = 1) { //use mindtouch dream to access the web service. // treat the result and return it to the view FoireMusesConnection connection = GetConnection(); SearchResult <ScoreSearchItem> listScores = null; try { listScores = connection.GetScores((page - 1) * PageSize, PageSize, new Result <SearchResult <ScoreSearchItem> >()).Wait(); } catch (Exception e) { return(RedirectToAction("Problem", "Error", null)); } var viewModel = new ListViewModel <ScoreSearchItem>() { CurrentPage = page, SearchResult = listScores }; return(View(viewModel)); }
public ViewResult List(int page = 1) { //use mindtouch dream to access the web service. // treat the result and return it to the view FoireMusesConnection connection = GetConnection(); SearchResult <SourceSearchItem> listSources = null; try { listSources = connection.GetSources((page - 1) * PageSize, PageSize, new Result <SearchResult <SourceSearchItem> >()).Wait(); } catch (Exception e) { // do stuff to return error message to the screen } var viewModel = new ListViewModel <SourceSearchItem>() { SearchResult = listSources, CurrentPage = page, }; return(View(viewModel)); }
// // GET: /Scores/Details public ActionResult Details(string scoreId) { if (String.IsNullOrWhiteSpace(scoreId)) { return(RedirectToAction("Missing", "Error", null)); } FoireMusesConnection connection = GetConnection(); Score score = null; Score genericScore = null; Source sTextuelle = null; Source sMusicale = null; Play assPlay = null; IList <ScoreSearchItem> otherTitlesScore = null; IEnumerable <string> attachedFiles = null; IEnumerable <string> documents = null; try { score = connection.GetScore(scoreId, new Result <Score>()).Wait(); if (score == null) { return(RedirectToAction("Missing", "Error", null)); } if (score.TextualSource != null && !String.IsNullOrWhiteSpace(score.TextualSource.SourceId)) { sTextuelle = connection.GetSource(score.TextualSource.SourceId, new Result <Source>()).Wait(); if (sTextuelle == null) { return(RedirectToAction("Problem", "Error", null)); } if (!String.IsNullOrWhiteSpace(score.TextualSource.PieceId)) { assPlay = connection.GetPlay(score.TextualSource.PieceId, new Result <Play>()).Wait(); if (assPlay == null) { return(RedirectToAction("Problem", "Error", null)); } } } if (score.MusicalSource != null && !String.IsNullOrWhiteSpace(score.MusicalSource.SourceId)) { sMusicale = connection.GetSource(score.MusicalSource.SourceId, new Result <Source>()).Wait(); if (sMusicale == null) { return(RedirectToAction("Problem", "Error", null)); } } if (score.HasAttachement) { attachedFiles = score.GetAttachmentNames().Where(x => !x.StartsWith("$")); documents = score.GetAttachmentNames().Where(x => x.StartsWith("$")); } if (score.IsMaster) { SearchResult <ScoreSearchItem> results = connection.SearchScore(0, 0, new Dictionary <string, object>() { { "masterId", score.Id } }, new Result <SearchResult <ScoreSearchItem> >()).Wait(); if (results == null) { return(RedirectToAction("Problem", "Error", null)); } otherTitlesScore = results.Rows; } else if (score.MasterId != null) { genericScore = connection.GetScore(score.MasterId, new Result <Score>()).Wait(); if (genericScore == null) { return(RedirectToAction("Problem", "Error", null)); } SearchResult <ScoreSearchItem> results = connection.SearchScore(0, 0, new Dictionary <string, object>() { { "masterId", score.MasterId } }, new Result <SearchResult <ScoreSearchItem> >()).Wait(); if (results == null) { return(RedirectToAction("Problem", "Error", null)); } otherTitlesScore = results.Rows; } } catch (Exception e) { return(RedirectToAction("Problem", "Error", null)); } ViewBag.TextualSource = sTextuelle; ViewBag.AssociatedPlay = assPlay; ViewBag.MusicalSource = sMusicale; ViewBag.AttachedFiles = attachedFiles; ViewBag.Documents = documents; ViewBag.OtherTitlesScore = otherTitlesScore; ViewBag.GenericScore = genericScore; return(View(score)); }