/// <summary>
        ///   Metodo per l'esecuzione del command.
        /// </summary>
        /// <param name="command">Il DTO del command.</param>
        public void Handle(ComponiPartenzaCommand command)
        {
            var richiestaAssistenza = this._getRichiestaAssistenzaById.Get(command.IdRichiestaAssistenza);

            foreach (var cp in command.ComposizioniPartenza)
            {
                richiestaAssistenza.AddEvento(cp);
            }

            _saveRichiestaAssistenza.Save(richiestaAssistenza);
        }
Beispiel #2
0
        public void Handle(AddInterventoCommand command)
        {
            var Competenze    = _getCompetenze.GetCompetenzeByCoordinateIntervento(command.Chiamata.Localita.Coordinate).ToHashSet();
            var lstCompetenze = new List <Distaccamento>();

            Competenze.ToList().ForEach(c => lstCompetenze.Add(_getDistaccamento.Get(c).Result));

            if (Competenze.ToList()[0] == null)
            {
                throw new Exception(Costanti.CoordinateErrate);
            }

            var sedeRichiesta     = command.CodiceSede;
            var prioritaRichiesta = (RichiestaAssistenza.Priorita)command.Chiamata.PrioritaRichiesta;
            var codiceChiamata    = _generaCodiceRichiesta.GeneraCodiceChiamata(sedeRichiesta, DateTime.UtcNow.Year);

            command.Chiamata.Codice = codiceChiamata;
            var listaCodiciTipologie = new List <string>();
            var utentiInLavorazione  = new List <string>();
            var utentiPresaInCarico  = new List <string>();

            foreach (var tipologia in command.Chiamata.Tipologie)
            {
                listaCodiciTipologie.Add(tipologia.Codice);
            }
            if (command.Chiamata.ListaUtentiInLavorazione != null)
            {
                foreach (var utente in command.Chiamata.ListaUtentiInLavorazione)
                {
                    utentiInLavorazione.Add(utente.Nominativo);
                }
            }
            if (command.Chiamata.ListaUtentiPresaInCarico != null)
            {
                foreach (var utente in command.Chiamata.ListaUtentiPresaInCarico)
                {
                    utentiPresaInCarico.Add(utente.Nominativo);
                }
            }

            var richiesta = new RichiestaAssistenza()
            {
                Tipologie          = listaCodiciTipologie,
                CodZoneEmergenza   = command.Chiamata.ZoneEmergenza,
                Richiedente        = command.Chiamata.Richiedente,
                Localita           = command.Chiamata.Localita,
                Descrizione        = command.Chiamata.Descrizione,
                Codice             = codiceChiamata,
                TrnInsChiamata     = $"Turno {_getTurno.Get().Codice.Substring(0, 1)}",
                TipoTerreno        = command.Chiamata.TipoTerreno,
                ObiettivoSensibile = command.Chiamata.ObiettivoSensibile,
                UtInLavorazione    = utentiInLavorazione,
                UtPresaInCarico    = utentiPresaInCarico,
                NotePubbliche      = command.Chiamata.NotePubbliche,
                NotePrivate        = command.Chiamata.NotePrivate,
                CodUOCompetenza    = Competenze.ToArray(),
                Competenze         = lstCompetenze.Select(d => new Sede(d.CodSede.ToString(), d.DescDistaccamento, d.Indirizzo, d.Coordinate, null, null, null, null, null)).ToList(),
                CodOperatore       = command.CodUtente,
                CodSOCompetente    = command.CodiceSede,
                CodEntiIntervenuti = command.Chiamata.listaEnti != null?command.Chiamata.listaEnti.Select(c => c.ToString()).ToList() : null
            };

            if (command.Chiamata.Stato == Costanti.RichiestaChiusa)
            {
                new ChiusuraRichiesta("", richiesta, DateTime.UtcNow, command.CodUtente);
            }

            if (command.Chiamata.Tags != null)
            {
                foreach (var t in command.Chiamata.Tags)
                {
                    richiesta.Tags.Add(t);
                }
            }

            new Telefonata(richiesta, command.Chiamata.Richiedente.Telefono, DateTime.UtcNow, command.CodUtente)
            {
                NominativoChiamante = command.Chiamata.Richiedente.Nominativo,
                Motivazione         = command.Chiamata.Motivazione,
                NotePrivate         = command.Chiamata.NotePrivate,
                NotePubbliche       = command.Chiamata.NotePubbliche,
                NumeroTelefono      = command.Chiamata.Richiedente.Telefono,
                Esito = command.Chiamata.Azione.ToString(),
                CodiceSchedaContatto = command.Chiamata.CodiceSchedaNue
            };

            new AssegnazionePriorita(richiesta, prioritaRichiesta, DateTime.UtcNow.AddMilliseconds(1.0), command.CodUtente);

            if (command.Chiamata.RilevanteGrave || command.Chiamata.RilevanteStArCu)
            {
                new MarcaRilevante(richiesta, DateTime.UtcNow.AddMilliseconds(1.5), command.CodUtente, "", command.Chiamata.RilevanteGrave,
                                   command.Chiamata.RilevanteStArCu);
            }

            if (command.Chiamata.Azione.Equals(Azione.FalsoAllarme) || command.Chiamata.Azione.Equals(Azione.ChiusuraForzata) ||
                command.Chiamata.Azione.Equals(Azione.InterventoDuplicato) || command.Chiamata.Azione.Equals(Azione.InterventoNonPiuNecessario))
            {
                command.Chiamata.Stato = Costanti.RichiestaChiusa;
                new ChiusuraRichiesta("", richiesta, DateTime.UtcNow.AddMilliseconds(1.0), command.CodUtente);
            }

            if (command.Chiamata.CodiceSchedaNue != null)
            {
                var codiceFiscaleOperatore = _getUtenteById.GetUtenteByCodice(command.CodUtente).CodiceFiscale;
                _setStatoGestioneSchedaContatto.Gestita(command.Chiamata.CodiceSchedaNue, command.CodiceSede, codiceFiscaleOperatore, true);
            }

            _saveRichiestaAssistenza.Save(richiesta);
        }