public bool AssignDelegate(Employee emp, string deptid) { List <Employee> emplist = erepo.FindEmpByDept(deptid); foreach (Employee e in emplist) { if (emp.DelegateFromDate >= e.DelegateFromDate && emp.DelegateFromDate <= e.DelegateToDate) { if (emp.Id != e.Id) { throw new Exception("Conflict of delegate dates with " + e.Name + ". Please try again"); } } if (emp.DelegateToDate >= e.DelegateFromDate && emp.DelegateToDate <= e.DelegateToDate) { if (emp.Id != e.Id) { throw new Exception("Conflict of delegate dates with " + e.Name + ". Please try again"); } } } try { Employee delegateemp = erepo.AssignDelegateDate(emp); Employee depthead = erepo.FindSupervisorByEmpId(delegateemp.Id); EmailModel email = new EmailModel(); Task.Run(async() => { EmailTemplates.AssignDelTemplate adt = new EmailTemplates.AssignDelTemplate(delegateemp, depthead); email.emailTo = delegateemp.Email; email.emailSubject = adt.subject; email.emailBody = adt.body; await mailservice.SendEmailwithccallAsync(email, emplist); }); return(true); } catch (Exception e) { throw e; } }