public ActionResult ValuationScoreCard(int id, ValuationScoreCardViewModel model) { if (!this.ModelState.IsValid) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var scoreCard = this.valuationScoreCardRepository.Find(id, this.Authentication.CurrentUserId); model.UpdateScoreCard(scoreCard, this.generalSettings.ScoreCardLifeTime); // It is important to note that the JournalScore of the Journal is updated in a // trigger in the datavaluation and not in the code. This is done to prevent concurrency // issues from leading to incorrect totals and averages for the journal score this.valuationScoreCardRepository.InsertOrUpdate(scoreCard); this.valuationScoreCardRepository.Save(); var journalPrice = this.valuationJournalPriceRepository.Find(id, this.Authentication.CurrentUserId) ?? this.CreateNewValuationJournalPrice(scoreCard); model.UpdateJournalPrice(journalPrice); if (model.HasPrice) { this.valuationJournalPriceRepository.InsertOrUpdate(journalPrice); } else { this.valuationJournalPriceRepository.Delete(journalPrice); } this.valuationJournalPriceRepository.Save(); return(this.Json(true)); }
public void ValidWhenAllQuestionScoresAreNotUndecided() { // Arrange var model = new ValuationScoreCardViewModel { QuestionScores = new List <QuestionScoreViewModel> { new QuestionScoreViewModel { Score = Score.Absent }, new QuestionScoreViewModel { Score = Score.Excellent }, new QuestionScoreViewModel { Score = Score.Good }, } }; // Act var isValid = Validator.TryValidateObject(model, new ValidationContext(model), null); // Assert Assert.True(isValid); }
public void NotValidWhenAllQuestionScoresAreUndecided() { // Arrange var model = new ValuationScoreCardViewModel { QuestionScores = new List <QuestionScoreViewModel> { new QuestionScoreViewModel { Score = Score.Undecided }, new QuestionScoreViewModel { Score = Score.Undecided }, new QuestionScoreViewModel { Score = Score.Undecided }, } }; // Act var isValid = Validator.TryValidateObject(model, new ValidationContext(model), null); // Assert Assert.False(isValid); }
public void NotValidWhenQuestionScoresIsNull() { // Arrange var model = new ValuationScoreCardViewModel { QuestionScores = null }; // Act var isValid = Validator.TryValidateObject(model, new ValidationContext(model), null); // Assert Assert.False(isValid); }
public void NotValidWhenQuestionScoresIsEmpty() { // Arrange var model = new ValuationScoreCardViewModel { QuestionScores = new List <QuestionScoreViewModel>() }; // Act var isValid = Validator.TryValidateObject(model, new ValidationContext(model), null); // Assert Assert.False(isValid); }
public void NotValidWhenOneQuestionScoreIsUndecided() { // Arrange var model = new ValuationScoreCardViewModel { QuestionScores = new List<QuestionScoreViewModel> { new QuestionScoreViewModel { Score = Score.Absent }, new QuestionScoreViewModel { Score = Score.Excellent }, new QuestionScoreViewModel { Score = Score.Undecided }, } }; // Act var isValid = Validator.TryValidateObject(model, new ValidationContext(model), null); // Assert Assert.False(isValid); }