public void UpdateEvaluation(EvaluationEntity updatedEvaluation) { if (updatedEvaluation.Id.Equals(Guid.Empty)) { throw new ObjectNotFoundException(); } }
public void CreateEval_EmptyEntity_ThrowsMissingInfoException() { var testClass = InteractorFactory.Create_EvaluationInteractor(); var testEntity = new EvaluationEntity(); Should.Throw <MissingInfoException>(() => testClass.CreateEvaluation(testEntity)); }
public void UpdateEvaluation(EvaluationEntity updatedEvaluation) { var existingEvaluation = Repo.GetById(updatedEvaluation.Id); if (existingEvaluation != null) { existingEvaluation.Weight = updatedEvaluation.Weight; existingEvaluation.NumberOfScores = updatedEvaluation.NumberOfScores; existingEvaluation.PointsPerScore = updatedEvaluation.PointsPerScore; existingEvaluation.DropLowest = updatedEvaluation.DropLowest; existingEvaluation.NumberToDrop = updatedEvaluation.NumberToDrop; existingEvaluation.CurrentPointsGrade = updatedEvaluation.CurrentPointsGrade; existingEvaluation.CurrentPointsPossible = updatedEvaluation.CurrentPointsPossible; existingEvaluation.FinalPointsGrade = updatedEvaluation.FinalPointsGrade; existingEvaluation.TotalPointsPossible = updatedEvaluation.TotalPointsPossible; existingEvaluation.PointsEarned = updatedEvaluation.PointsEarned; existingEvaluation.Name = updatedEvaluation.Name; existingEvaluation.LastModified = DateTime.Now; Repo.Update(existingEvaluation); } else { throw new ObjectNotFoundException("There is no Evaluation with that ID."); } }
private void CalculateGrade(EvaluationEntity evaluationToGrade) { var wizard = new EvaluationWizard(); var scoreWizard = new ScoreWizard(); var evalSpell = new EvaluationResult { TotalScoreCount = evaluationToGrade.NumberOfScores, DropLowest = evaluationToGrade.DropLowest, DropLowestCount = evaluationToGrade.NumberToDrop, PointValuePerScore = evaluationToGrade.PointsPerScore }; var scores = ScoreInteractor.GetScoresByEvaluationId(evaluationToGrade.Id); var scoreSpells = new List <ScoreResult>(); if (scores.Count > 0) { foreach (var scoreEntity in scores) { scoreSpells.Add(scoreWizard.GetSingleScoreResult(scoreEntity.PointsEarned, scoreEntity.PointsPossible)); } evalSpell.Scores = scoreSpells; wizard.Evaluation = evalSpell; wizard.UpdateAllGrades(); evaluationToGrade.PointsEarned = wizard.Evaluation.PointsEarned; evaluationToGrade.CurrentPointsPossible = wizard.Evaluation.PointsPossibleToDate; evaluationToGrade.TotalPointsPossible = wizard.Evaluation.PointsPossibleOverall; evaluationToGrade.CurrentPointsGrade = wizard.Evaluation.GradeToDateRaw; evaluationToGrade.FinalPointsGrade = wizard.Evaluation.GradeOverallRaw; } else { var pointsTotal = (evaluationToGrade.NumberOfScores - evaluationToGrade.NumberToDrop) * evaluationToGrade.PointsPerScore; evaluationToGrade.CurrentPointsGrade = 1; evaluationToGrade.FinalPointsGrade = 0; evaluationToGrade.PointsEarned = 0; evaluationToGrade.CurrentPointsPossible = pointsTotal; evaluationToGrade.TotalPointsPossible = pointsTotal; } }
public Guid CreateEvaluation(EvaluationEntity newEvaluationEntity) { var existingEval = Repo.GetAll().FirstOrDefault(e => e.CourseId == newEvaluationEntity.CourseId && e.Name == newEvaluationEntity.Name); if (existingEval != null) { throw new ObjectAlreadyExistsException($"An Evaluation named {newEvaluationEntity.Name} already exists for this Course."); } ValidateNewEvaluation(newEvaluationEntity); newEvaluationEntity.Id = Guid.NewGuid(); newEvaluationEntity.CreatedOn = DateTime.Now; newEvaluationEntity.LastModified = DateTime.Now; return(Repo.Create(newEvaluationEntity)); }
public EvaluationDomainModel(EvaluationEntity evaluationEntity) { Id = evaluationEntity.Id; Name = evaluationEntity.Name; CourseId = evaluationEntity.CourseId; Weight = evaluationEntity.Weight; PointsEarned = evaluationEntity.PointsEarned; PointsPerScore = evaluationEntity.PointsPerScore; CurrentPointsGrade = evaluationEntity.CurrentPointsGrade; FinalPointsGrade = evaluationEntity.FinalPointsGrade; CurrentPointsPossible = evaluationEntity.CurrentPointsPossible; TotalPointsPossible = evaluationEntity.TotalPointsPossible; NumberOfScores = evaluationEntity.NumberOfScores; DropLowest = evaluationEntity.DropLowest; NumberToDrop = evaluationEntity.NumberToDrop; LastModified = evaluationEntity.LastModified; CreatedOn = evaluationEntity.CreatedOn; }
/// <summary> /// Gets the course attached to the passed ID, and displays the data currently in the database /// </summary> /// <param name="evaluationId"></param> /// <returns></returns> public IDomainModel GetEvaluation(Guid evaluationId) { var evaluationModel = new EvaluationDomainModel(); var evaluationEntity = new EvaluationEntity(); try { evaluationEntity = EvaluationInteractor.GetEvaluation(evaluationId); } catch (GradeTrackerException gte) { return(new ErrorDomainModel(gte, false)); } evaluationModel = new EvaluationDomainModel(evaluationEntity); return(evaluationModel); }
protected void ValidateNewEvaluation(EvaluationEntity newEvaluationEntity) { if (string.IsNullOrEmpty(newEvaluationEntity.Name)) { throw new MissingInfoException("Evaluation Must Have a Name."); } if (newEvaluationEntity.CourseId.Equals(Guid.Empty)) { throw new MissingInfoException("Evaluation Must be Linked to a Course."); } if (newEvaluationEntity.Weight.Equals(0)) { newEvaluationEntity.Weight = 1; } if (newEvaluationEntity.NumberOfScores < 0) { throw new MissingInfoException("The Number of Scores for this Evaluation Cannot be Less than 0."); } }
public Task <int> SubmitForm <TDto>(EvaluationEntity entity, TDto dto) where TDto : class { if (!string.IsNullOrEmpty(entity.F_Id)) { entity.Modify(entity.F_Id); entity.F_LastModifyUserId = _usersService.GetCurrentUserId(); return(_service.UpdateAsync(entity, dto)); } else { //新建 var patient = _uow.GetRepository <PatientEntity>().FindEntity(entity.F_Pid); if (patient == null) { return(Task.FromResult(0)); } if (entity.Sctxdate == null) { entity.Sctxdate = patient.F_DialysisStartTime; } if (entity.Sctxdate != null) { var sctxdate = (DateTime)entity.Sctxdate; var years = (int)(DateTime.Now - sctxdate).TotalDays / 365; var months = (int)((DateTime.Now - sctxdate).TotalDays - years * 365) / 30; var days = (int)(DateTime.Now - sctxdate).TotalDays - years * 365 - months * 30; entity.Sfsctxvalue3 = years > 0 ? years.ToString() : null; entity.Sfsctxvalue2 = months > 0 ? months.ToString() : null; entity.Sfsctxvalue1 = days > 0 ? days.ToString() : null; } else { entity.Sfsctxvalue1 = null; entity.Sfsctxvalue2 = null; entity.Sfsctxvalue3 = null; } entity.Create(); entity.F_CreatorUserId = _usersService.GetCurrentUserId(); return(_service.InsertAsync(entity)); } }
public void UpdateEvaluation_ValidObject_UpdatesScore() { var evalGuid = Guid.NewGuid(); var testList = EvaluationFactory.Create_ListValidEvalEntities(); var testRepo = new MockRepository <EvaluationEntity>(testList); var testClass = InteractorFactory.Create_EvaluationInteractor(testRepo); var evaluationToUpdate = testRepo.GetAll().First(); var updatedEvaluation = new EvaluationEntity { Id = evaluationToUpdate.Id, Weight = .2, DropLowest = true, NumberOfScores = 1 }; testClass.UpdateEvaluation(updatedEvaluation); var result = testClass.GetEvaluation(evaluationToUpdate.Id); result.LastModified.ShouldNotBeSameAs(evaluationToUpdate.LastModified); result.Weight.ShouldBe(.2); result.DropLowest.ShouldBe(true); result.NumberOfScores.ShouldBe(1); }
public Guid CreateEvaluation(EvaluationEntity newEvaluationEntity) { if (string.IsNullOrEmpty(newEvaluationEntity.Name)) { throw new MissingInfoException(); } if (newEvaluationEntity.CourseId.Equals(Guid.Empty)) { throw new MissingInfoException(); } if (newEvaluationEntity.Weight.Equals(0)) { throw new MissingInfoException(); } if (newEvaluationEntity.NumberOfScores < 0) { throw new MissingInfoException(); } return(Guid.NewGuid()); }
public Task <int> SubmitForm(EvaluationEntity entity, string keyValue) { if (!string.IsNullOrEmpty(keyValue)) { entity.Modify(keyValue); _service.Update(entity); var fileEntity = _serviceMain.FindEntity(keyValue); if (fileEntity != null) { fileEntity.F_LastModifyTime = entity.F_LastModifyTime; return(_serviceMain.UpdateAsync(fileEntity, true)); } else { return(Task.FromResult(0)); } } else { //新建 var patient = _uow.GetRepository <PatientEntity>().FindEntity(entity.F_Pid);// db.FindEntity<PatientEntity>(entity.F_Pid); if (patient == null) { return(Task.FromResult(0)); } if (entity.Sctxdate == null) { entity.Sctxdate = patient.F_DialysisStartTime; } if (entity.Sctxdate != null) { DateTime sctxdate = (DateTime)entity.Sctxdate; int years = (int)(DateTime.Now - sctxdate).TotalDays / 365; int months = (int)((DateTime.Now - sctxdate).TotalDays - years * 365) / 30; int days = (int)(DateTime.Now - sctxdate).TotalDays - years * 365 - months * 30; if (years > 0) { entity.Sfsctxvalue3 = years.ToString(); } else { entity.Sfsctxvalue3 = null; } if (months > 0) { entity.Sfsctxvalue2 = months.ToString(); } else { entity.Sfsctxvalue2 = null; } if (days > 0) { entity.Sfsctxvalue1 = days.ToString(); } else { entity.Sfsctxvalue1 = null; } } else { entity.Sfsctxvalue1 = null; entity.Sfsctxvalue2 = null; entity.Sfsctxvalue3 = null; } var claimsIdentity = _httpContext.HttpContext.User.Identity as ClaimsIdentity; claimsIdentity.CheckArgumentIsNull(nameof(claimsIdentity)); var claimUserId = claimsIdentity?.FindFirst(t => t.Type == ClaimTypes.NameIdentifier); var claimUserName = claimsIdentity?.FindFirst(t => t.Type == ClaimTypes.Name); //var LoginInfo = OperatorProvider.Provider.GetCurrent(); entity.F_Id = Common.GuId(); entity.F_CreatorUserId = claimUserId?.Value; entity.F_CreatorTime = DateTime.Now; //entity.Create(); return(_serviceMain.InsertAsync(new FileIndexEntity { F_Id = entity.F_Id, F_Pid = patient.F_Id, F_Name = patient.F_Name, F_DialysisNo = patient.F_DialysisNo, F_CardNo = patient.F_CardNo, F_RecordNo = patient.F_RecordNo, F_Gender = patient.F_Gender, F_CreatorTime = entity.F_CreatorTime, F_RealName = claimUserName?.Value, F_FileType = "透前评估单" })); } }
public Task <int> UpdateForm(EvaluationEntity entity) { return(_service.UpdateAsync(entity)); }