Пример #1
0
        public ResultList <SimpleResultItem> LoadFieldsByParams(SendMail.Model.IndexedCatalogs ctg, IList <SendMail.Model.EntitaType> tEnt, KeyValuePair <SendMail.Model.FastIndexedAttributes, string> par, int da, int per)
        {
            if (String.IsNullOrEmpty(par.Value))
            {
                return(null);
            }
            if (tEnt == null)
            {
                tEnt = new List <SendMail.Model.EntitaType>();
            }
            if (tEnt.Count == 0)
            {
                tEnt.Add(SendMail.Model.EntitaType.ALL);
            }

            ResultList <SimpleResultItem> res = new ResultList <SimpleResultItem>();

            res.Da = da;
            string field = string.Empty;

            using (var dbcontext = new FAXPECContext())
            {
                var querable = dbcontext.RUBR_ENTITA.AsQueryable();
                switch (par.Key)
                {
                case SendMail.Model.FastIndexedAttributes.RAGIONE_SOCIALE:
                    field    = "RAGIONE_SOCIALE";
                    querable = dbcontext.RUBR_ENTITA.Where(x => x.RAGIONE_SOCIALE.ToUpper().Contains(par.Value.ToUpper()));
                    break;

                case SendMail.Model.FastIndexedAttributes.COGNOME:
                    field    = "COGNOME";
                    querable = dbcontext.RUBR_ENTITA.Where(x => x.COGNOME.ToUpper().Contains(par.Value.ToUpper()));
                    break;

                case SendMail.Model.FastIndexedAttributes.FAX:
                    field    = "FAX";
                    querable = dbcontext.RUBR_CONTATTI.Where(x => x.FAX.ToUpper().Contains(par.Value)).Select(z => z.RUBR_ENTITA);
                    break;

                case SendMail.Model.FastIndexedAttributes.MAIL:
                    field    = "MAIL";
                    querable = dbcontext.RUBR_CONTATTI.Where(x => x.MAIL.ToUpper().Contains(par.Value)).Select(z => z.RUBR_ENTITA);
                    break;

                case SendMail.Model.FastIndexedAttributes.TELEFONO:
                    field    = "TELEFONO";
                    querable = dbcontext.RUBR_CONTATTI.Where(x => x.TELEFONO.ToUpper().Contains(par.Value)).Select(z => z.RUBR_ENTITA);
                    break;

                case SendMail.Model.FastIndexedAttributes.UFFICIO:
                    querable = dbcontext.RUBR_ENTITA.Where(x => x.UFFICIO.ToUpper().Contains(par.Value));
                    break;

                default:
                    throw new ArgumentException("Parametro non implementato");
                }
                if (!tEnt.Contains(SendMail.Model.EntitaType.ALL) && !tEnt.Contains(SendMail.Model.EntitaType.UNKNOWN))
                {
                    var referrals = tEnt.Select(t => t.ToString()).ToArray();
                    querable = querable.Where(x => referrals.Contains(x.REFERRAL_TYPE));
                }
                try
                {
                    int tot = querable.Count();
                    res.Per    = (tot > per) ? per : tot;
                    res.Totale = tot;
                    List <RUBR_ENTITA> list = querable.OrderBy(f => f.ID_REFERRAL).Skip(res.Da).Take(res.Per).ToList();
                    foreach (RUBR_ENTITA r in list)
                    {
                        res.List.Add(
                            new SimpleResultItem(
                                //  r.GetValue("descr").ToString(),
                                r.RAGIONE_SOCIALE,
                                r.ID_REFERRAL.ToString(),
                                String.Format("{0} {1} {2}", r.DISAMB_PRE, r.RAGIONE_SOCIALE, r.DISAMB_POST),
                                r.REFERRAL_TYPE,
                                "R",
                                100));
                    }
                }
                catch (Exception ex)
                {
                    ManagedException mEx = new ManagedException("Errore nella ricerca in rubrica dell'entità o contatto  Data Layer E075 Dettagli Errore: " + ex.Message,
                                                                "ERR_075", string.Empty, string.Empty, ex.InnerException);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);

                    _log.Error(err);
                    int tot = 0;
                    res.List = null;
                    throw mEx;
                }
            }
            return(res);
        }
Пример #2
0
        public ResultList <RubricaContatti> LoadContattiByParams(List <SendMail.Model.EntitaType> tEnt, Dictionary <SendMail.Model.FastIndexedAttributes, List <string> > pars, int da, int per, bool withEntita)
        {
            if (tEnt == null)
            {
                tEnt = new List <SendMail.Model.EntitaType>();
            }
            if (tEnt.Count == 0)
            {
                tEnt.Add(SendMail.Model.EntitaType.ALL);
            }
            if (tEnt.Contains(SendMail.Model.EntitaType.UNKNOWN))
            {
                throw new ArgumentException("Tipo entità errato");
            }

            List <RubricaContatti>       lContatti = null;
            List <RubricaEntita>         lEntita   = null;
            ResultList <RubricaContatti> res       = new ResultList <RubricaContatti>();

            var pp = from k in pars.Keys
                     where k == SendMail.Model.FastIndexedAttributes.COGNOME ||
                     k == SendMail.Model.FastIndexedAttributes.RAGIONE_SOCIALE ||
                     k == SendMail.Model.FastIndexedAttributes.UFFICIO
                     select k;

            var entPar = (from ep in pars
                          where pp.Contains(ep.Key)
                          select ep).ToDictionary((x =>
                                                   x.Key), (y => (IList <string>)y.Value));

            if (pp.Count() != 0)
            {
                RubrEntitaSQLDb            sql = new RubrEntitaSQLDb();
                ResultList <RubricaEntita> rE  = sql.LoadEntitaByParams((IList <SendMail.Model.EntitaType>)tEnt,
                                                                        entPar, da, per);
                lEntita = (List <RubricaEntita>)rE.List;
            }

            var cPars = from p in pars
                        where !entPar.Keys.Contains(p.Key)
                        select p;

            //as IEnumerable<KeyValuePair<SendMail.Model.FastIndexedAttributes,
            //List<string>>>;
            if (cPars.Count() != 0)
            {
                using (var dbcontext = new FAXPECContext())
                {
                    var query = dbcontext.RUBR_CONTATTI.AsQueryable();

                    List <RUBR_CONTATTI> list = new List <RUBR_CONTATTI>();
                    foreach (var kvp in cPars)
                    {
                        switch (kvp.Key)
                        {
                        case SendMail.Model.FastIndexedAttributes.FAX:
                            string[] faxies = kvp.Value.ToArray();
                            list = query.Where(x => faxies.Contains(x.FAX)).ToList();
                            break;

                        case SendMail.Model.FastIndexedAttributes.MAIL:
                            string[] mailies = kvp.Value.ToArray();
                            list = query.Where(x => mailies.Contains(x.MAIL)).ToList();
                            break;

                        case SendMail.Model.FastIndexedAttributes.TELEFONO:
                            string[] telefoni = kvp.Value.ToArray();
                            list = query.Where(x => telefoni.Contains(x.TELEFONO)).ToList();
                            break;

                        default:
                            break;
                        }
                    }
                    lContatti = new List <RubricaContatti>();
                    foreach (var c in list)
                    {
                        var ListTitoli = (from t in dbcontext.RUBR_CONTATTI_BACKEND
                                          where t.REF_ID_CONTATTO == c.ID_CONTACT
                                          select t.COMUNICAZIONI_TITOLI.ID_TITOLO).ToList();

                        lContatti.Add(AutoMapperConfiguration.MapToRubrContatti(c, ListTitoli));
                    }
                }
            }

            if (lEntita != null)
            {
                if (lContatti == null)
                {
                    lContatti = new List <RubricaContatti>();
                }
                lEntita.ForEach(e => lContatti.AddRange(LoadContattiOrgByOrgId(e.IdReferral.Value, true, true, false, true)));
            }

            if (lContatti != null)
            {
                res.List = new List <RubricaContatti>();
                foreach (var c in lContatti)
                {
                    if (res.List.SingleOrDefault(x => x.IdContact == c.IdContact) == null)
                    {
                        res.List.Add(c);
                    }
                }

                res.Da     = da;
                res.Totale = res.List.Count;
                res.Per    = (per > res.Totale) ? res.Totale : per;
            }
            return(res);
        }
Пример #3
0
        public List <SendMail.Model.RubricaMapping.RubricaContatti> LoadContattiOrgByOrgId(long identita, bool startFromOrg, bool includeDescendant, bool includeIPA, bool includeAppMappings)
        {
            List <RubricaContatti> lContatti = null;

            try
            {
                List <RUBR_CONTATTI> list           = null;
                List <RUBR_CONTATTI> listDescendant = null;
                List <RUBR_CONTATTI> mergedList     = null;
                using (var dbcontext = new FAXPECContext())
                {
                    if (startFromOrg)
                    {
                        list = dbcontext.RUBR_CONTATTI.Where(x => x.RUBR_ENTITA.ID_REFERRAL == (int)identita).ToList();
                        //var a = (from r in dbcontext.RUBR_CONTATTI
                        //     where r.RUBR_ENTITA.ID_REFERRAL == (int)identita);
                    }
                    else
                    {
                        list = dbcontext.RUBR_CONTATTI.Where(x => x.REF_ID_REFERRAL == (int)identita).ToList();
                        //var a = (from r in dbcontext.RUBR_CONTATTI
                        //        where r.REF_ID_REFERRAL ==(int) identita);
                    }
                    if (includeDescendant)
                    {
                        listDescendant = dbcontext.RUBR_CONTATTI.Where(x => x.RUBR_ENTITA.ID_PADRE == (int)identita).ToList();
                        mergedList     = list.Union(listDescendant).ToList();
                    }
                    else
                    {
                        mergedList = list;
                    }

                    if (mergedList.Count > 0)
                    {
                        lContatti = new List <RubricaContatti>();
                        foreach (RUBR_CONTATTI r in mergedList)
                        {
                            if (includeAppMappings)
                            {
                                var ListTitoli = (from t in dbcontext.RUBR_CONTATTI_BACKEND
                                                  where t.REF_ID_CONTATTO == r.ID_CONTACT
                                                  select t.COMUNICAZIONI_TITOLI.ID_TITOLO).ToList();
                                lContatti.Add(AutoMapperConfiguration.MapToRubrContatti(r, ListTitoli));
                            }
                            else
                            {
                                lContatti.Add(AutoMapperConfiguration.MapToRubrContatti(r));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ManagedException mEx = new ManagedException("Errore nella ricerca in rubrica dei contatti per organizzazione  Data Layer E077 Dettagli Errore: " + ex.Message,
                                                            "ERR_077", string.Empty, string.Empty, ex.InnerException);
                ErrorLogInfo err = new ErrorLogInfo(mEx);

                _log.Error(err);
                throw mEx;
            }

            return(lContatti);
        }
Пример #4
0
        //1-se i titoli hanno referenze da 'RICHIESTE' la cancellazione deve essere logica
        //2-se i tioli hanno refrenze a sottotiotli prima devono essere cancellati i sottotitoli
        //3- se però tutti i sottotitoli sono cancellati logicamente allora si può procedere con la cancellazione logica
        public void Delete(decimal id)
        {
            using (var dbcontext = new FAXPECContext())
            {
                using (var transaction = dbcontext.Database.BeginTransaction())
                {
                    try
                    {
                        var     deleted           = dbcontext.COMUNICAZIONI_TITOLI.Where(x => x.ID_TITOLO == id).First();
                        var     st                = dbcontext.COMUNICAZIONI_SOTTOTITOLI.Where(x => x.REF_ID_TITOLO == id).ToList();
                        int     sottoTitoli       = st.Count;
                        int     sottoTitoliAttivi = 0;
                        decimal lastActive        = -1;
                        if (st.Count > 1)
                        {
                            foreach (COMUNICAZIONI_SOTTOTITOLI t in st)
                            {
                                if (t.ACTIVE != 0)
                                {
                                    sottoTitoliAttivi++;
                                    lastActive = t.ID_SOTTOTITOLO;
                                }
                            }
                            if (sottoTitoliAttivi > 1)
                            {
                                transaction.Rollback();
                                ManagedException mEx = new ManagedException("ATTENZIONE!!! Cancellare prima i sottotitoli associati questo titolo",
                                                                            "DAL_TIT_0015", string.Empty,
                                                                            string.Empty, null);
                                ErrorLogInfo err = new ErrorLogInfo(mEx);

                                log.Error(mEx);
                                throw mEx;
                            }
                            else if (sottoTitoliAttivi == 1)
                            {
                                deleted.ACTIVE = 0;
                                var oldsottotitolo = dbcontext.COMUNICAZIONI_SOTTOTITOLI.Where(x => x.ID_SOTTOTITOLO == lastActive).First();
                                oldsottotitolo.ACTIVE = 0;
                                int rows = dbcontext.SaveChanges();
                            }
                        }
                        else if (st.Count == 1)
                        {
                            //cancello fisicamente i record del titolo e del sottotitolo di default
                            //TODO:occorre aggiungere la parte relativa al controllo sulle richieste associate
                            //se ci sono la cancellazione torna ad essere logica
                            var oldsottotitolo = dbcontext.COMUNICAZIONI_SOTTOTITOLI.Where(x => x.ID_SOTTOTITOLO == st[0].ID_SOTTOTITOLO).First();
                            dbcontext.COMUNICAZIONI_SOTTOTITOLI.Remove(oldsottotitolo);
                            dbcontext.COMUNICAZIONI_TITOLI.Remove(deleted);
                            int rows = dbcontext.SaveChanges();
                        }
                        if (st.Count == 0)
                        {
                            dbcontext.COMUNICAZIONI_TITOLI.Remove(deleted);
                            int row = dbcontext.SaveChanges();
                            if (row != 1)
                            {
                                transaction.Rollback();
                                //TASK: Allineamento log - Ciro
                                ManagedException mEx = new ManagedException(DalExMessages.NESSUNA_RIGA_MODIFICATA,
                                                                            "DAL_TIT_009", string.Empty,
                                                                            string.Empty, null);
                                ErrorLogInfo err = new ErrorLogInfo(mEx);

                                log.Error(mEx);
                                throw mEx;
                            }
                            //throw new ManagedException(DalExMessages.NESSUNA_RIGA_MODIFICATA, "DAL_TIT_009", "", "", "", "", "", null);
                        }
                    }
                    /*TODO: INSERIRE I LOG DELLE ECCEZIONI*/
                    catch (Exception ex)
                    {
                        //TASK: Allineamento log - Ciro
                        transaction.Rollback();
                        if (ex.GetType() != typeof(ManagedException))
                        {
                            ManagedException mEx = new ManagedException(DalExMessages.RUBRICA_NON_AGGIORNATA,
                                                                        "DAL_UNIQUE_CODE", string.Empty,
                                                                        string.Empty, ex);
                            ErrorLogInfo err = new ErrorLogInfo(mEx);

                            log.Error(mEx);
                            throw mEx;
                        }
                        else
                        {
                            throw;
                        }
                        //throw new ManagedException(DalExMessages.RUBRICA_NON_AGGIORNATA, "DAL_UNIQUE_CODE", "", "", "", "", "", ex);
                    }
                }
            }
        }