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)); }
// // 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 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 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)); }
// // 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)); }