Ejemplo n.º 1
0
 public AlertContrattoDTO GetByDomainEntity(AlertContratto alert)
 {
     try
     {
         return setDto(alert);
     }
     catch (Exception ex)
     {
         if (alert != null)
             _log.Error("Errore nel caricamento degli alert: " + Utility.GetMethodDescription() + " - id:" + alert.ID, ex);
         else
             _log.Error("Errore nel caricamento degli alert: " + Utility.GetMethodDescription() + " - AlertContratto --> null", ex);
         throw;
     }
 }
Ejemplo n.º 2
0
        private void notifySingleAlert(AlertContratto alert, IDaoFactory daoFactory)
        {
            if (alert.TipoAvviso == NotifyType.Email)
                notifyEmailAlert(alert, daoFactory);

            // In futuro prevedere le altre tipologie di notifica
        }
Ejemplo n.º 3
0
        private bool update(AlertContrattoDTO alertDto, out AlertContratto alert)
        {
            bool result = false;
            alert = null;
            var daoFactory = _windsorRepository.GetDaoFactory(_info.Azienda);

            try
            {
                alert = daoFactory.GetAlertContrattoDao().GetById(alertDto.ID, false);

                // Condizione necessare per il controllo del fatto che sul DB ho una versione uguale o più vecchia
                if (alertDto.Version == alert.Version)
                {

                    switch (alertDto.TipoAlert)
                    {
                        case TipoAlertEnum.PremioAssicurativo:
                            alert = daoFactory.GetAlertPremioContrattoDao().GetById(alertDto.ID, false);
                            break;
                        case TipoAlertEnum.ContrattoAssicurativo:
                            alert = daoFactory.GetAlertScadenzaContrattoDao().GetById(alertDto.ID, false);
                            break;
                        case TipoAlertEnum.ContrattoAppalto:
                            alert = daoFactory.GetAlertScadenzaContrattoDao().GetById(alertDto.ID, false);
                            break;
                        default:
                            alert = daoFactory.GetAlertContrattoDao().GetById(alertDto.ID, false);
                            break;
                    }

                    alert.AvvisoScadenza = alertDto.AvvisoScadenza;
                    alert.Descrizione = alertDto.Descrizione;
                    alert.Destinatario = daoFactory.GetReferenteDao().GetById(alertDto.IdReferente, false);
                    alert.TipoAvviso = (NotifyType)Enum.Parse(typeof(NotifyType), alertDto.TipoAvviso);

                    daoFactory.GetAlertContrattoDao().Update(alert);

                    result = true;
                }
                else
                {
                    // Eccezione: Sul db c'è qualche cosa di più nuovo.
                    _log.Error("Errore nel salvataggio dell'alert contratto: id:" + alertDto.ID + " - il dato sul db è più recente di quello che si vuole salvare");
                }
            }
            catch (Exception ex)
            {
                _log.Error("Errore nel salvataggio dell'alert contratto: " + Utility.GetMethodDescription() + " - id:" + alertDto.ID, ex);
                throw;
            }

            return result;
        }
Ejemplo n.º 4
0
        private bool insert(AlertContrattoDTO alertDto, out AlertContratto alert)
        {
            alert = null;
            if (alertDto != null)
            {
                var daoFactory = _windsorRepository.GetDaoFactory(_info.Azienda);

                try
                {
                    var notifyType = NotifyType.Email;
                    if(!string.IsNullOrEmpty(alertDto.TipoAvviso))
                        notifyType = (NotifyType) Enum.Parse(typeof (NotifyType), alertDto.TipoAvviso);

                    switch (alertDto.TipoAlert)
                    {
                        case TipoAlertEnum.ContrattoAppalto:
                            ContrattoAppalto contrattoAppalto = null;
                            if (alertDto.IdContratto > 0)
                                contrattoAppalto = daoFactory.GetContrattoAppaltoDao().Find(alertDto.IdContratto.Value, false);
                            alert = new AlertScadenzaContratto(notifyType, alertDto.Descrizione, contrattoAppalto);
                            break;
                        case TipoAlertEnum.ContrattoAssicurativo:
                            AssicurazioneContratto contrattoAssicurativo = null;
                            if (alertDto.IdContratto > 0)
                                contrattoAssicurativo = daoFactory.GetAssicurazioneContrattoDao().Find(alertDto.IdContratto.Value, false);
                            alert = new AlertScadenzaContratto(notifyType, alertDto.Descrizione, contrattoAssicurativo);
                            break;
                        case TipoAlertEnum.PremioAssicurativo:
                            AssicurazioneContratto contrattoPremio = null;
                            if (alertDto.IdContratto > 0)
                                contrattoPremio = daoFactory.GetAssicurazioneContrattoDao().Find(alertDto.IdContratto.Value, false);
                            alert = new AlertPremioContratto(notifyType, alertDto.Descrizione, contrattoPremio);
                            break;
                    }

                    if (alert != null)
                    {
                        alert.AvvisoScadenza = alertDto.AvvisoScadenza;
                        alert.Descrizione = alertDto.Descrizione;
                        alert.Destinatario = daoFactory.GetReferenteDao().Find(alertDto.IdReferente, false);
                        alert.TipoAvviso = notifyType;

                        daoFactory.GetAlertContrattoDao().SaveOrUpdate(alert);
                    }
                }
                catch (Exception ex)
                {
                    _log.Error("Errore nell'inserimento dell'alert: " + Utility.GetMethodDescription() + " - id:" + alertDto.ID + " - contratto:" + alertDto.IdContratto.GetValueOrDefault(), ex);
                }
            }

            return true;
        }
Ejemplo n.º 5
0
        private AlertContrattoDTO setDto(AlertContratto alert)
        {
            try
            {
                var dto = new AlertContrattoDTO
                {
                    AvvisoScadenza = alert.AvvisoScadenza,
                    Descrizione = alert.Descrizione,
                    DisplayName = alert.ToString(),
                    ID = alert.ID,
                    TipoAvviso = alert.TipoAvviso.ToString(),
                    ToNotify = alert.ToNotify
                };

                if (alert.Destinatario != null)
                {
                    dto.IdReferente = alert.Destinatario.ID;
                    if (alert.Destinatario.IsDinamico)
                    {
                        var referenteEffettivo = alert.Destinatario.GetReferenteEffettivo(alert.ContrattoRiferimento.CondominioRiferimento, null);
                        dto.DisplayReferente = alert.Destinatario.DisplayName;
                        if(referenteEffettivo != null)
                            dto.DisplayReferente += " (" + referenteEffettivo.Sigla + ")";
                    }
                    else
                        dto.DisplayReferente = alert.Destinatario.DisplayName;
                }

                if (Conversione.IsTypeOf(alert, typeof(AlertPremioContratto)))
                    dto.TipoAlert = TipoAlertEnum.PremioAssicurativo;
                else if (Conversione.IsTypeOf(alert, typeof(AlertScadenzaContratto)))
                {
                    dto.TipoAlert = Conversione.IsTypeOf(alert.ContrattoRiferimento, typeof(ContrattoAppalto)) ? TipoAlertEnum.ContrattoAppalto : TipoAlertEnum.ContrattoAssicurativo;
                }

                dto.Version = alert.Version;

                return dto;
            }
            catch (Exception ex)
            {
                _log.Error("Errore nella creazione dell'oggetto DTO per alert: " + Utility.GetMethodDescription() + " - id:" + alert.ID, ex);
                throw;
            }
        }