Beispiel #1
0
 public void Deactivate(Advice advice)
 {
     DeleteJobFromHangfire(advice);
     advice.IsActive = false;
     AdviceRepository.Update(advice);
     AdviceRepository.Save();
 }
Beispiel #2
0
 public void BulkDeleteAdvice(IEnumerable <Advice> toBeDeleted)
 {
     using var transaction = TransactionManager.Begin(IsolationLevel.ReadCommitted);
     foreach (var advice in toBeDeleted)
     {
         RemoveAdviceAndItsRelatedEntities(advice);
     }
     AdviceRepository.Save();
     transaction.Commit();
 }
Beispiel #3
0
        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;
            }
        }
Beispiel #4
0
 public void Delete(Advice advice)
 {
     RemoveAdviceAndItsRelatedEntities(advice);
     AdviceRepository.Save();
 }
Beispiel #5
0
 public void CreateAdvice(Advice advice)
 {
     ScheduleAdvice(advice);
     AdviceRepository.Update(advice);
     AdviceRepository.Save();
 }