private void UpdateAssessmentClassScore(AssessmentClassScore assessmentScoreObj)
        {
            using (var context = new dbTIREntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var data = context.tblAssessmentScores
                                   .Where(x => x.AssessmentScoreId == assessmentScoreObj.AssessmentScoreId)
                                   .FirstOrDefault();

                        if (assessmentScoreObj.Score != EDS.Constants.SystemParameter.ScoreTargetDefaultValue.DefaultValue)
                        {
                            data.Score = assessmentScoreObj.Score;
                        }
                        if (assessmentScoreObj.Target != EDS.Constants.SystemParameter.ScoreTargetDefaultValue.DefaultValue)
                        {
                            data.Projection = assessmentScoreObj.Target;
                        }
                        data.ChangeDatetime = DateTime.UtcNow;
                        context.tblAssessmentScores.Add(data);
                        context.Entry(data).State = EntityState.Modified;
                        context.SaveChanges();
                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                        throw ex;
                    }
                }
            }
        }
 private void SaveAssessmentClassScore(AssessmentClassScore assessmentScoreObj)
 {
     using (var context = new dbTIREntities())
     {
         using (var dbContextTransaction = context.Database.BeginTransaction())
         {
             try
             {
                 int defaultValue = EDS.Constants.SystemParameter.ScoreTargetDefaultValue.DefaultValue;
                 int?score        = assessmentScoreObj.Score != defaultValue ? assessmentScoreObj.Score : null;
                 int?projection   = assessmentScoreObj.Target != defaultValue ? assessmentScoreObj.Target : null;
                 tblAssessmentScore tblAssessmentScore = new tblAssessmentScore()
                 {
                     AssessmentId   = assessmentScoreObj.AssessmentId,
                     StudentId      = assessmentScoreObj.StudentId,
                     Score          = score,
                     Projection     = projection,
                     GradeLevel     = assessmentScoreObj.GradeLevel,
                     SchoolID       = assessmentScoreObj.SchoolId,
                     CreateDatetime = DateTime.UtcNow
                 };
                 context.tblAssessmentScores.Add(tblAssessmentScore);
                 context.SaveChanges();
                 dbContextTransaction.Commit();
             }
             catch (Exception ex)
             {
                 dbContextTransaction.Rollback();
                 throw ex;
             }
         }
     }
 }
        private void AddClassAssessmentScoreScore(AssessmentClassScore assessmentScoreObj, out string result)
        {
            using (var context = new dbTIREntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        //Update existing score
                        if (assessmentScoreObj.AssessmentScoreId != 0)
                        {
                            UpdateAssessmentClassScore(assessmentScoreObj);
                        }
                        // Save new Score
                        else
                        {
                            if (assessmentScoreObj.AssessmentScoreId == 0 && assessmentScoreObj.AssessmentId != 0)
                            {
                                SaveAssessmentClassScore(assessmentScoreObj);
                            }
                        }

                        result = "Records Saved Scuccessfully.";
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                        throw ex;
                    }
                }
            }
        }