コード例 #1
0
 public int? ManageDomainEntity(AlertContrattoDTO dto)
 {
     try
     {
         var alert = manage(dto);
         return alert != null ? (int?) alert.ID : null;
     }
     catch (Exception ex)
     {
         _log.Error("Errore nel caricamento degli alert: " + Utility.GetMethodDescription() + " - id:" + dto.ID.ToString(), ex);
         throw;
     }
 }
コード例 #2
0
        private AlertContratto manage(AlertContrattoDTO alertDto)
        {
            AlertContratto alert = null;
            bool result;

            // Controllo sullo stato U, I
            switch (alertDto.Stato.ToUpper())
            {
                case "U":
                    result = update(alertDto, out alert);

                    if (!result)
                        throw new Exception("Il dato sul database è più recente di quello utilizzato");
                    break;
                case "I":
                    result = insert(alertDto, out alert);

                    if (!result)
                        throw new Exception("Impossibile scrivere sul database");
                    break;
            }

            return alert;
        }
コード例 #3
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;
        }
コード例 #4
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;
        }
コード例 #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;
            }
        }
コード例 #6
0
ファイル: SferaService.cs プロジェクト: gipasoft/Sfera
		public int? SetAlertContratto(AlertContrattoDTO alertContratto, UserInfo userinfo)
		{
			var windsorRep = new WindsorConfigRepository();
			try
			{
				windsorRep.BeginTransaction(userinfo);
				var repo = new AlertContrattoRepository(userinfo, windsorRep);
                var item = repo.ManageDomainEntity(alertContratto);
				windsorRep.Commit();
				return item;
			}
			catch (Exception ex)
			{
                _log.ErrorFormat("Errore nella lettura del dettaglio di Tipo Alert - {0} - id:{1} - azienda:{2}", ex, Utility.GetMethodDescription(), alertContratto.ID, userinfo.Azienda);
				windsorRep.Rollback();
				throw;
			}
		}