/// <summary> /// This method is used to Create Health Track /// </summary> public async Task <HealthTrack> CreateHealthTrack(HealthTrack healthTrack) { _context.HealthTrack.Add(healthTrack); await _context.SaveChangesAsync(); _context.Entry(healthTrack).Reference(c => c.Employee).Load(); return(healthTrack); }
private async Task <HealthTrackViewModel> SaveHealthTrack(HealthTrackViewModel healthTrackViewModel) { // user can add declaration var healthTrackModel = new HealthTrack(); // To map health Track detail healthTrackModel.MapFromViewModel(healthTrackViewModel, (ClaimsIdentity)_principal.Identity); var healthTrackSymptoms = new List <HealthTrackSymptom>(); if (healthTrackViewModel.HealthTrackSymptoms.Any()) { // To map HealthTrack Symptoms healthTrackSymptoms = healthTrackViewModel.HealthTrackSymptoms.Select(t => { var symptom = new HealthTrackSymptom(); symptom.MapFromViewModel(t); return(symptom); }).ToList(); } var healthTrackQuestionAnswer = new List <HealthTrackQuestionAnswer>(); if (healthTrackViewModel.HealthTrackQuestionAnswers.Any()) { healthTrackQuestionAnswer = healthTrackViewModel.HealthTrackQuestionAnswers.Select(t => { var questionAns = new HealthTrackQuestionAnswer(); questionAns.MapFromViewModel(t); return(questionAns); }).ToList(); } healthTrackModel.HealthTrackSymptoms = healthTrackSymptoms; healthTrackModel.HealthTrackQuestions = healthTrackQuestionAnswer; healthTrackModel = await _healthTrackRepository.CreateHealthTrack(healthTrackModel); healthTrackViewModel.Id = healthTrackModel.Id; var employeeVm = new EmployeeViewModel(); employeeVm.MapFromModel(healthTrackModel.Employee); healthTrackViewModel.Employee = employeeVm; // send email to HR and security await SendEmail(healthTrackViewModel); return(healthTrackViewModel); }