public void Deactivate(Advice advice) { DeleteJobFromHangfire(advice); advice.IsActive = false; AdviceRepository.Update(advice); AdviceRepository.Save(); }
public bool SendAdvice(int id) { using var transaction = TransactionManager.Begin(IsolationLevel.ReadCommitted); try { var advice = AdviceRepository.AsQueryable().ById(id); if (advice != null) { if (advice.AdviceType == AdviceType.Immediate || IsAdviceInScope(advice)) { if (DispatchEmails(advice)) { AdviceRepository.Update(advice); AdviceSentRepository.Insert(new AdviceSent { AdviceId = id, AdviceSentDate = OperationClock.Now }); } } if (advice.AdviceType == AdviceType.Immediate) { advice.IsActive = false; } else if (IsAdviceExpired(advice)) { advice.IsActive = false; DeleteJobFromHangfire(advice); } AdviceRepository.Save(); AdviceSentRepository.Save(); transaction.Commit(); } return(true); } catch (Exception e) { Logger?.Error(e, "General error sending emails in advice service"); transaction.Rollback(); throw; } }
public void CreateAdvice(Advice advice) { ScheduleAdvice(advice); AdviceRepository.Update(advice); AdviceRepository.Save(); }