Пример #1
0
        /// <summary>
        /// Public only to allow HangFire to access it
        /// </summary>
        /// <param name="adviceId"></param>
        public void DeactivateById(int adviceId)
        {
            var advice = AdviceRepository.AsQueryable().ById(adviceId);

            if (advice != null)
            {
                Deactivate(advice);
            }
        }
Пример #2
0
 public IQueryable <Advice> GetAdvicesAccessibleToCurrentUser()
 {
     return(OrganizationalUserContext.IsGlobalAdmin()
         ? AdviceRepository.AsQueryable()
         : OrganizationalUserContext
            .OrganizationIds
            .Select(GetAdvicesForOrg)
            .Aggregate <IQueryable <Advice>, IQueryable <Advice> >
            (
                null,
                (acc, next) => acc == null ? next : acc.Concat(next)
            ));
 }
Пример #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;
            }
        }