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 Result<Score> EditScore(Score score, Result<Score> aResult)
		{
			theServiceUri
				.At("scores")
				.With("Id", score.Id)
				.With("Rev", score.Rev)
				.Put(DreamMessage.Ok(MimeType.JSON, score.ToString()), new Result<DreamMessage>())
				.WhenDone(delegate(Result<DreamMessage> answer)
				{
					if (!answer.Value.IsSuccessful)
					{
						if (answer.Value.Status == DreamStatus.NotFound)
							aResult.Return((Score)null);
						else
							aResult.Throw(answer.Exception);
					}
					else
					{
						aResult.Return(new Score(JObject.Parse(answer.Value.ToText())));
					}
				}
				);
			return aResult;
		}
		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 Result<Score> CreateScore(Score score, Result<Score> aResult)
		{
			theServiceUri
				.At("scores")
				.Post(DreamMessage.Ok(MimeType.JSON, score.ToString()), new Result<DreamMessage>())
				.WhenDone(delegate(Result<DreamMessage> answer)
					{
						if (!answer.Value.IsSuccessful)
						{
							if (answer.Value.Status != DreamStatus.Ok)
								aResult.Throw(new Exception());
						}
						else
						{
							aResult.Return(new Score(JObject.Parse(answer.Value.ToText())));
						}
					}
				);
			return aResult;
		}