Exemplo n.º 1
0
        private AlertAttivita manage(AlertAttivitaDTO alertDto)
        {
            AlertAttivita 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;
        }
Exemplo n.º 2
0
        private bool insert(AlertAttivitaDTO alertDto, out AlertAttivita 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);

                    Attivita attivita = null;
                    if (alertDto.IdAttivita > 0)
                        attivita = daoFactory.GetAttivitaDao().Find(alertDto.IdAttivita, false);

                    Referente referente = null;
                    if (alertDto.IdDestinatario > 0)
                        referente = daoFactory.GetReferenteDao().Find(alertDto.IdDestinatario, false);

                    if (attivita != null && referente != null)
                    {
                        alert = new AlertAttivita(notifyType, referente, attivita)
                        {
                            AvvisoScadenza = alertDto.AvvisoScadenza,
                            TipoAvviso = notifyType
                        };
                        daoFactory.GetAlertAttivitaDao().SaveOrUpdate(alert);
                    }
                }
                catch (Exception ex)
                {
                    _log.ErrorFormat("Errore nell'inserimento dell'alert - {0} - id:{1} - attivita:{2} - referente:{3}", ex, Utility.GetMethodDescription(), alertDto.ID, alertDto.IdAttivita, alertDto.IdDestinatario);
                }
            }

            return true;
        }
Exemplo n.º 3
0
        private AlertAttivitaDTO setDto(AlertAttivita alert)
        {
            try
            {
                var dto = new AlertAttivitaDTO
                {
                    AvvisoScadenza = alert.AvvisoScadenza,
                    DisplayName = alert.ToString(),
                    ID = alert.ID,
                    TipoAvviso = alert.TipoAvviso.ToString(),
                    ToNotify = alert.ToNotify
                };

                if (alert.Destinatario != null)
                {
                    dto.IdDestinatario = alert.Destinatario.ID;
                    if (alert.Destinatario.IsDinamico)
                    {
                        var referenteEffettivo = alert.Destinatario.GetReferenteEffettivo(alert.Attivita.PraticaRiferimento.CondominioRiferimento, alert.Attivita);
                        dto.DisplayDestinatario = alert.Destinatario.DisplayName;
                        if(referenteEffettivo != null)
                            dto.DisplayDestinatario += " (" + referenteEffettivo.Sigla + ")";
                    }
                    else
                        dto.DisplayDestinatario = alert.Destinatario.DisplayName;
                }

                dto.Version = alert.Version;

                return dto;
            }
            catch (Exception ex)
            {
                _log.ErrorFormat("Errore nella creazione dell'oggetto DTO per alert -  {0} - id:{1}", ex, Utility.GetMethodDescription(), alert.ID);
                throw;
            }
        }
Exemplo n.º 4
0
        private bool update(AlertAttivitaDTO alertDto, out AlertAttivita alert)
        {
            alert = null;
            var daoFactory = _windsorRepository.GetDaoFactory(_info.Azienda);

            try
            {
                alert = daoFactory.GetAlertAttivitaDao().GetById(alertDto.ID, false);
                alert = daoFactory.GetAlertAttivitaDao().GetById(alertDto.ID, false);
                alert.AvvisoScadenza = alertDto.AvvisoScadenza;
                alert.Destinatario = daoFactory.GetReferenteDao().GetById(alertDto.IdDestinatario, false);
                alert.TipoAvviso = (NotifyType)Enum.Parse(typeof(NotifyType), alertDto.TipoAvviso);

                daoFactory.GetAlertAttivitaDao().Update(alert);
            }
            catch (Exception ex)
            {
                _log.ErrorFormat("Errore nel salvataggio dell'alert attività - {0} - id:{1}", ex, Utility.GetMethodDescription(), alertDto.ID);
                throw;
            }

            return true;
        }
Exemplo n.º 5
0
 public int? ManageDomainEntity(AlertAttivitaDTO dto)
 {
     try
     {
         var alert = manage(dto);
         return alert != null ? (int?) alert.ID : null;
     }
     catch (Exception ex)
     {
         _log.ErrorFormat("Errore nel caricamento degli Alert - {0} - id:{1}", ex, Utility.GetMethodDescription(), dto.ID);
         throw;
     }
 }