public async Task <(bool, string)> SubmitAppraisal(int empId, IEnumerable <AppraisalResultForCreationDto> entities) { var employee = await resultAreaRepo.GetEmployee(entities.FirstOrDefault().myId); string title = "Appraise"; string msg = $"has successfully appraised self. Kindly login to the portal and appraise him/her. <br /> Thank you.</p>"; string url = "https://resourceedge.herokuapp.com/"; string subject = ""; List <SingleEmailDto> emailDto = new List <SingleEmailDto>(); SingleEmailDto email = new SingleEmailDto(); if (employee != null) { subject = $"Appraise {employee.FullName}"; try { foreach (var entity in entities) { var keyResultArea = GetOnlyApplicableKeyoutcomesForAppraisal(entity.KeyResultAreaId, empId, entity.KeyOutcomeScore.Select(x => x.KeyOutcomeId.ToString()).ToList()).FirstOrDefault(); if (keyResultArea == null) { return(false, "No Key Result Area Found, Invalid Key result area Id"); } //var keyResultArea = await resultAreaRepo.QuerySingle(entity.KeyResultAreaId); if (entity.whoami == null) { var myAppraisal = mapper.Map <AppraisalResult>(entity); myAppraisal.NextAppraisee = "Appraiser"; myAppraisal.EmployeeAccept.IsAccepted = true; myAppraisal.KeyResultArea = keyResultArea; var average = myAppraisal.KeyOutcomeScore.Average(x => x.EmployeeScore.Value); myAppraisal.EmployeeCalculation.ScoreTotal = myAppraisal.KeyOutcomeScore.Sum(x => x.EmployeeScore).Value; myAppraisal.EmployeeCalculation.Average = average; myAppraisal.EmployeeCalculation.WeightContribution = (average * (Convert.ToDouble(myAppraisal.KeyResultArea.Weight)) / 100); this.InsertResult(myAppraisal); email.ReceiverFullName = keyResultArea.AppraiserDetails.Name; email.ReceiverEmailAddress = keyResultArea.AppraiserDetails.Email; email.HtmlContent = await sender.FormatEmail(employee.FullName, keyResultArea.AppraiserDetails.Name, msg, title, url); if (email.HtmlContent == null) { email.HtmlContent = @$ "<b>Dear {myAppraisal.KeyResultArea.AppraiserDetails.Name},</b> <br /> <p>{employee.FullName} has successfully appraised self. Kindly login to the portal and appraise him/her.<br /><br /> Thank you.</p>"; } emailDto.Add(email); } } } catch (Exception ex) { return(false, "Oops something went wrong"); } finally { var emailDtos = AppraisalResultExtension.FormatEmailForAppraisal(emailDto); if (emailDtos.Any()) { emailDtos.ForEach(async e => await sender.SendToSingleEmployee(subject, e)); } } } return(true, "Appraisal Submitted Successfull"); }