/// <summary> /// This function is used to add a new weighting /// </summary> /// <param name="studentExtend"></param> public void CreateWeighting(WeightingViewModel model) { using (var context = new dbTIREntities()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { tblAssessmentWeighting tblWeighting = new tblAssessmentWeighting() { AssessmentTypeId = Convert.ToInt32(model.AssessmentTypeId), SubjectId = Convert.ToInt32(model.SubjectId), DistrictId = Convert.ToInt32(model.DistrictId), SchoolYearId = Convert.ToInt32(model.SchoolYearId), CreateDatetime = DateTime.UtcNow }; context.tblAssessmentWeightings.Add(tblWeighting); context.SaveChanges(); int assessmentWeightingId = tblWeighting.AssessmentWeightingId; tblAssessmentGradeWeighting tblGradeWeighting = new tblAssessmentGradeWeighting() { AssessmentWeightingId = assessmentWeightingId, Grade = Convert.ToInt16(model.Grade), Weighting = (decimal)model.Weighting }; context.tblAssessmentGradeWeightings.Add(tblGradeWeighting); context.SaveChanges(); dbContextTransaction.Commit(); } catch (Exception ex) { dbContextTransaction.Rollback(); throw ex; } } } }