コード例 #1
0
        public TabletHearingFormatDto(HearingFormatView hfV)
        {
            this.idFolder   = hfV.idFolder;
            this.idJudicial = hfV.idJudicial;

            TabletHearingFormatImputedDto hfImp = new TabletHearingFormatImputedDto();

            hfImp.name          = hfV.imputedName;
            hfImp.lastNameP     = hfV.imputedFLastName;
            hfImp.lastNameM     = hfV.imputedSLastName;
            hfImp.birthDate     = hfV.imputedBirthDate == null ? null : String.Format("{0:yyyy/MM/dd}", hfV.imputedBirthDate);
            this.hearingImputed = hfImp;
        }
コード例 #2
0
        public HearingFormatView newHearingFormatByCase(int idCase)
        {
            using (var db = FactoryConn.GetConn()) {
                var hearingFormatData = new HearingFormatView();

                var formatosAnteriores = db.Table <HearingFormat> ().Where(prev => prev.CaseDetention == idCase &&
                                                                           prev.IsFinished == true).OrderByDescending(prev => prev.Id).ToList();

                //intenta traer los formatos anteriores y con eso llenar el nuevo formato
                if (formatosAnteriores != null && formatosAnteriores.Count > 0)
                {
                    var ultimo = formatosAnteriores.FirstOrDefault();
                    hearingFormatData = fillHearingFormaData(ultimo.Id);
                    Case ActualCase = db.Table <Case> ().Where(actul => actul.Id == idCase).FirstOrDefault();
                    hearingFormatData.IsSubstracted = ActualCase.IsSubstracted;
                }
                else
                {
                    var caso     = db.Table <Case> ().Where(cs => cs.Id == idCase).FirstOrDefault();
                    var meeting  = db.Table <Meeting> ().Where(me => me.CaseDetentionId == idCase).FirstOrDefault();
                    var imputado = db.Table <Imputed> ().Where(im => im.MeetingId == meeting.Id).FirstOrDefault();
                    hearingFormatData.initTime         = DateTime.Now;
                    hearingFormatData.appointmentDate  = DateTime.Today;
                    hearingFormatData.idCase           = caso.Id;
                    hearingFormatData.idFolder         = caso.IdFolder;
                    hearingFormatData.idJudicial       = caso.IdMP;
                    hearingFormatData.imputedName      = imputado.Name;
                    hearingFormatData.imputedFLastName = imputado.LastNameP;
                    hearingFormatData.imputedSLastName = imputado.LastNameM;
                    hearingFormatData.imputedBirthDate = imputado.BirthDate;

                    db.CreateTable <User> ();
                    var  usrList  = db.Table <User> ().ToList();
                    User reviewer = usrList.FirstOrDefault();
                    int  revId    = 0;
                    if (reviewer != null && reviewer.Id > 0)
                    {
                        revId = reviewer.Id;
                    }
                    hearingFormatData.userName = reviewer.fullname;
                }
                hearingFormatData.canSave    = true;
                hearingFormatData.canEdit    = true;
                hearingFormatData.disableAll = false;
                db.Close();
                return(hearingFormatData);
            }
        }
コード例 #3
0
        public HFDtoSave fillHearingFormatWithView(HearingFormatView viewFormat)
        {
            string testJson = "{'id':1,'idFolder':'1020304050','recidivist':false,'dateCreate':'2015/06/08'}";
            var    objecto  = JsonConvert.DeserializeObject <TestTabletCaseDto> (testJson);

            using (var db = FactoryConn.GetConn()) {
                HFDtoSave     result        = new HFDtoSave();
                HearingFormat hearingFormat = new HearingFormat();
                if (viewFormat.idFormat != null && viewFormat.idFormat > 0)
                {
                    var updatable = db.Table <HearingFormat> ().Where(up => up.Id == viewFormat.idFormat).FirstOrDefault();
                    if (updatable != null)
                    {
                        hearingFormat = updatable;
                    }
                }
                hearingFormat.RegisterTime = DateTime.Now;
//			var supervisor = db.Table<User> ().FirstOrDefault ();
//			hearingFormat.Supervisor = supervisor.Id;

                hearingFormat.HearingType     = viewFormat.hearingTypeId ?? 0;
                hearingFormat.ImputedPresence = viewFormat.imputedPresence ?? 0;
                hearingFormat.HearingResult   = viewFormat.hearingResult;

                hearingFormat.TimeAgo       = viewFormat.TimeAgo;
                hearingFormat.LocationPlace = viewFormat.LocationPlace;

                bool          hasFirstFH = false;
                HearingFormat lastHF     = null;
                Case          existCase  = db.Table <Case> ().Where(cs => cs.Id == viewFormat.idCase).FirstOrDefault();
                hearingFormat.CaseDetention = existCase.Id;
                List <HearingFormat> existFinishedFormats = db.Table <HearingFormat> ().Where(hef => hef.CaseDetention == existCase.Id &&
                                                                                              hef.IsFinished == true).OrderByDescending(hef => hef.Id).ToList();

                if (existFinishedFormats != null && existFinishedFormats.Count > 0)
                {
                    hasFirstFH = true;
                    lastHF     = existFinishedFormats.First();
                }

                if (hasFirstFH)
                {
                    hearingFormat.IdFolder   = lastHF.IdFolder;
                    hearingFormat.IdJudicial = lastHF.IdJudicial;

                    if (viewFormat.hearingTypeId != null)
                    {
                        hearingFormat.HearingType = viewFormat.hearingTypeId ?? 0;
                        hearingFormat.HearingTypeSpecification = viewFormat.hearingTypeSpecification;
                    }

                    hearingFormat.ImputedPresence = viewFormat.imputedPresence ?? 0;
                    hearingFormat.HearingResult   = viewFormat.hearingResult;
                }
                else
                {
                    hearingFormat.IdFolder   = viewFormat.idFolder;
                    hearingFormat.IdJudicial = viewFormat.idJudicial;
                }

                hearingFormat.Room       = viewFormat.room;
                hearingFormat.District   = viewFormat.District;
                hearingFormat.IsHomeless = viewFormat.IsHomeless;

                hearingFormat.TimeAgo       = viewFormat.TimeAgo;
                hearingFormat.LocationPlace = viewFormat.LocationPlace;

                try {
                    if (viewFormat.appointmentDateStr != null && viewFormat.appointmentDateStr.Trim() != "")
                    {
                        hearingFormat.AppointmentDate = DateTime.ParseExact(viewFormat.appointmentDateStr, "yyyy/MM/dd",
                                                                            System.Globalization.CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        hearingFormat.AppointmentDate = null;
                    }

                    if (viewFormat.initTimeStr != null && viewFormat.initTimeStr.Trim() != "")
                    {
                        hearingFormat.InitTime = DateTime.ParseExact(viewFormat.initTimeStr, "HH:mm:ss",
                                                                     System.Globalization.CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        hearingFormat.InitTime = null;
                    }

                    if (viewFormat.endTimeStr != null && viewFormat.endTimeStr.Trim() != "")
                    {
                        hearingFormat.EndTime = DateTime.ParseExact(viewFormat.endTimeStr, "HH:mm:ss",
                                                                    System.Globalization.CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        hearingFormat.EndTime = null;
                    }

                    if (viewFormat.umecaDateStr != null && viewFormat.umecaDateStr.Trim() != "")
                    {
                        hearingFormat.UmecaDate = DateTime.ParseExact(viewFormat.umecaDateStr, "yyyy/MM/dd",
                                                                      System.Globalization.CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        hearingFormat.AppointmentDate = null;
                    }

                    if (viewFormat.umecaTimeStr != null && viewFormat.umecaTimeStr.Trim() != "")
                    {
                        hearingFormat.UmecaTime = DateTime.ParseExact(viewFormat.umecaTimeStr, "HH:mm:ss",
                                                                      System.Globalization.CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        hearingFormat.UmecaTime = null;
                    }

                    if (viewFormat.umecaSupervisorId != null)
                    {
                        var super = db.Table <User> ().FirstOrDefault();
                        hearingFormat.UmecaSupervisor = super.Id;
                    }
                } catch (Exception e) {
                    Console.WriteLine("Ha ocurrido un error fillHearingFormat");
                    Console.WriteLine("Exception message :::>" + e.Message);
                    return(null);
                }

                hearingFormat.JudgeName    = viewFormat.judgeName;
                hearingFormat.MpName       = viewFormat.mpName;
                hearingFormat.DefenderName = viewFormat.defenderName;

                hearingFormat.PreviousHearing = viewFormat.previousHearing ?? 0;

                HearingFormatImputed hearingImputed = db.Table <HearingFormatImputed> ().Where(hfi => hfi.Id == hearingFormat.hearingImputed).FirstOrDefault();

                if (hearingImputed == null)
                {
                    hearingImputed = new HearingFormatImputed();
                }

                hearingImputed.Name      = viewFormat.imputedName;
                hearingImputed.LastNameP = viewFormat.imputedFLastName;
                hearingImputed.LastNameM = viewFormat.imputedSLastName;

                try {
                    if (viewFormat.imputedBirthDateStr != null && viewFormat.imputedBirthDateStr.Trim() != "")
                    {
                        hearingImputed.BirthDate = DateTime.ParseExact(viewFormat.imputedBirthDateStr, "yyyy/MM/dd",
                                                                       System.Globalization.CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        hearingImputed.BirthDate = null;
                    }
                } catch (Exception e) {
                    Console.WriteLine("Ha ocurrido un error fillHearingFormat hearingImputed.BirthDate");
                    Console.WriteLine("Exception message :::>" + e.Message);
                    //logException.Write(e, this.getClass(), "parsingBirthDateHearingFormat", sharedUserService);
                    return(null);
                }
                try {
                    hearingImputed.ImputeTel = viewFormat.imputedTel;

                    if (viewFormat.location != null && viewFormat.location.Id > 0)
                    {
                        Address address = db.Table <Address> ().Where(ad => ad.Id == hearingImputed.Address).FirstOrDefault();
                        if (address == null)
                        {
                            address = new Address();
                        }

                        address.Street         = viewFormat.street;
                        address.OutNum         = viewFormat.outNum;
                        address.InnNum         = viewFormat.innNum;
                        address.Lat            = viewFormat.lat;
                        address.Lng            = viewFormat.lng;
                        address.LocationId     = viewFormat.location.Id;
                        address.addressString  = address.ToString();
                        hearingImputed.Address = address.Id;                        //TODO: asignar el id al guardar el address
                        result.addressImputado = address;
                    }
                    if (hearingFormat.IsHomeless)
                    {
                        Address address = db.Table <Address> ().Where(ad => ad.Id == hearingImputed.Address).FirstOrDefault();
                        if (address == null)
                        {
                            address = new Address();
                        }
                        address.Street = viewFormat.street;
                        address.OutNum = viewFormat.outNum;
                        address.InnNum = viewFormat.innNum;
                        Location homeles = db.Table <Location> ().Where(homeLess => homeLess.Name == Constants.HOMELESS_LOC).FirstOrDefault();
                        if (homeles != null && homeles.Id > 0)
                        {
                            address.LocationId = homeles.Id;
                        }
                        address.addressString  = address.ToString();
                        hearingImputed.Address = address.Id;                        //TODO: asignar el id al guardar el address
                        result.addressImputado = address;
                    }

                    hearingFormat.hearingImputed = hearingImputed.Id;                    //TODO: asignar el id al guardar el imputed
                    result.hearingFormatImputed  = hearingImputed;
                } catch (Exception e) {
                    Console.WriteLine("Ha ocurrido un error fillHearingFormat Imputed address");
                    Console.WriteLine("Exception message :::>" + e.Message);
                    //logException.Write(e, this.getClass(), "parsingBirthDateHearingFormat", sharedUserService);
                    return(null);
                }


                HearingFormatSpecs hearingSpecs = new HearingFormatSpecs();

                if (hearingFormat.HearingFormatSpecs > 0)
                {
                    hearingSpecs = db.Table <HearingFormatSpecs> ().Where(hspc => hspc.Id == hearingFormat.HearingFormatSpecs).FirstOrDefault();
                }
                hearingSpecs.ControlDetention      = viewFormat.controlDetention ?? 0;
                hearingSpecs.Extension             = viewFormat.extension ?? 0;
                hearingSpecs.ImputationFormulation = viewFormat.impForm ?? 0;

                try {
                    if (viewFormat.imputationDateStr != null && viewFormat.imputationDateStr.Trim() != "")
                    {
                        hearingSpecs.ImputationDate = DateTime.ParseExact(viewFormat.imputationDateStr, "yyyy/MM/dd",
                                                                          System.Globalization.CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        hearingSpecs.ImputationDate = null;
                    }

                    if (viewFormat.extDate != null)
                    {
                        hearingSpecs.ExtDate = viewFormat.extDate;
                    }
                    else
                    {
                        hearingSpecs.ExtDate = null;
                    }

                    if (viewFormat.linkageDate != null)
                    {
                        hearingSpecs.LinkageDate = viewFormat.linkageDate;
                    }
                    else
                    {
                        hearingSpecs.LinkageDate = null;
                    }

                    if (viewFormat.linkageTime != null)
                    {
                        hearingSpecs.LinkageTime = viewFormat.linkageTime;
                    }
                } catch (Exception e) {
                    Console.WriteLine("Ha ocurrido un error fillHearingFormat times");
                    Console.WriteLine("Exception message :::>" + e.Message);
                    //logException.Write(e, this.getClass(), "parsingSpecsHearingFormat", sharedUserService);
                    return(null);
                }

                hearingSpecs.LinkageProcess = viewFormat.vincProcess ?? 0;
                hearingSpecs.LinkageRoom    = viewFormat.linkageRoom;


                if (viewFormat.vincProcess != null &&
                    viewFormat.vincProcess == Constants.PROCESS_VINC_YES ||
                    viewFormat.vincProcess == Constants.PROCESS_VINC_NO_REGISTER)
                {
                    hearingSpecs.ArrangementType     = viewFormat.arrangementType ?? 0;
                    hearingSpecs.NationalArrangement = viewFormat.nationalArrangement.GetValueOrDefault();


                    String[] terms = null;
                    if (viewFormat.terms != null)
                    {
                        viewFormat.terms.Split(',');
                    }

                    if (terms != null && terms.Length > 0)
                    {
                        hearingFormat.Terms = terms [0];
                    }
                    else
                    {
                        hearingFormat.Terms = viewFormat.terms;
                    }

//				List<ArrangementView> lstAssignedArrnmtView;
//				Type type = new TypeToken<>() {
//				}.getType();

                    if (viewFormat.lstArrangement != null && viewFormat.lstArrangement.Trim() != "")
                    {
                        var lstAssignedArrnmtView = JsonConvert.DeserializeObject <List <ArrangementView> > (viewFormat.lstArrangement);

                        if (lstAssignedArrnmtView.Count > 0)
                        {
                            List <AssignedArrangement> lstNewAssigArrmnt = new List <AssignedArrangement> ();

                            foreach (ArrangementView arrV in lstAssignedArrnmtView)
                            {
                                if (arrV.selVal == true)
                                {
                                    AssignedArrangement assArrmnt = new AssignedArrangement();
                                    assArrmnt.Arrangement   = arrV.id;
                                    assArrmnt.Description   = arrV.description;
                                    assArrmnt.HearingFormat = hearingFormat.Id;
                                    lstNewAssigArrmnt.Add(assArrmnt);
                                }
                            }

                            var oldArrangements = db.Table <AssignedArrangement> ().Where(aa => aa.HearingFormat == hearingFormat.Id).ToList();


                            if (oldArrangements != null && oldArrangements.Count > 0)
                            {
                                foreach (AssignedArrangement actArr in oldArrangements)
                                {
//								actArr.HearingFormat = 0;
//								actArr.Arrangement = 0;
                                    db.Delete(actArr);
                                }
                            }

                            result.newArrangments = lstNewAssigArrmnt;
                        }
                    }

                    var lstContactData = new List <ContactData> ();



                    if (viewFormat.lstContactData != null && viewFormat.lstContactData.Trim() != "")
                    {
                        lstContactData = JsonConvert.DeserializeObject <List <ContactData> > (viewFormat.lstContactData);

                        if (lstContactData.Count > 0)
                        {
                            List <ContactData> lstNewContactData = new List <ContactData> ();

                            foreach (ContactData conV in lstContactData)
                            {
                                ContactData contact = new ContactData();
                                contact.NameTxt       = conV.NameTxt;
                                contact.PhoneTxt      = conV.PhoneTxt;
                                contact.AddressTxt    = conV.AddressTxt;
                                contact.HearingFormat = hearingFormat.Id;
                                contact.liveWith      = conV.liveWith;
                                lstNewContactData.Add(contact);
                            }

                            var oldContacts = new List <ContactData> ();
                            if (hearingFormat != null && hearingFormat.Id > 0)
                            {
                                var prevContacts = db.Table <ContactData> ().Where(cont => cont.HearingFormat == hearingFormat.Id).ToList();
                                if (prevContacts != null && prevContacts.Count > 0)
                                {
                                    oldContacts = prevContacts;
                                }
                            }


                            if (oldContacts != null && oldContacts.Count > 0)
                            {
                                foreach (ContactData act in oldContacts)
                                {
//								act.HearingFormat = 0;
                                    db.Delete(act);
                                }
                            }

                            result.lstContactDataView = lstNewContactData;
                        }
                        else
                        {
                            var oldContacts = new List <ContactData> ();
                            if (hearingFormat != null && hearingFormat.Id > 0)
                            {
                                var prevContacts = db.Table <ContactData> ().Where(cont => cont.HearingFormat == hearingFormat.Id).ToList();
                                if (prevContacts != null && prevContacts.Count > 0)
                                {
                                    oldContacts = prevContacts;
                                }
                            }


                            if (oldContacts != null && oldContacts.Count > 0)
                            {
                                foreach (ContactData act in oldContacts)
                                {
                                    //act.HearingFormat = 0;
                                    db.Delete(act);
                                }
                            }
                        }
                    }
                }
                else
                {
                    hearingFormat.ConfirmComment = viewFormat.confirmComment;
                }


                var prevCrime = db.Table <Crime> ().Where(crm => crm.HearingFormat == hearingFormat.Id).ToList();
                if (prevCrime != null && prevCrime.Count > 0)
                {
                    foreach (Crime c in prevCrime)
                    {
//					c.setHearingFormat = null;
                        db.Delete(c);
                    }
                }
                var auxCrime  = new List <Crime> ();
                var crimeView = JsonConvert.DeserializeObject <List <CrimeDto> > (viewFormat.listCrime);
                if (crimeView != null && crimeView.Count > 0)
                {
                    foreach (CrimeDto cdto in crimeView)
                    {
                        auxCrime.Add(cdto.ToCrime());
                    }
                }
                result.crimeList             = auxCrime;
                result.newHearingFormatSpecs = hearingSpecs;
                hearingFormat.IsFinished     = viewFormat.isFinished.GetValueOrDefault();
                hearingFormat.Comments       = viewFormat.comments;


                result.hearingFormat = hearingFormat;
                db.Close();
                return(result);
            }
        }
コード例 #4
0
        public void  HearingFormatVisualize(int idCase, int idFormato)
        {
            using (var db = FactoryConn.GetConn()) {
                var view = new HearingFormatEditDto();
                var hearingFormatData = new HearingFormatView();
                var statusClosed      = db.Table <StatusCase> ().Where(stc2 => stc2.Name == Constants.CASE_STATUS_CLOSED).FirstOrDefault();
                var casoverStatus     = db.Table <Case> ().Where(cs => cs.Id == idCase && cs.StatusCaseId == statusClosed.Id).ToList();

                if (casoverStatus != null && casoverStatus.Count > 0)
                {
                    HearingFormatList(idCase, "No es posible agregar mas formatos, el caso se encuentra cerrado.");
                    return;
                }

                if (idFormato > 0)
                {
                    hearingFormatData = fillHearingFormaData(idFormato);
                    Case ActualCase = db.Table <Case> ().Where(actul => actul.Id == idCase).FirstOrDefault();
                    hearingFormatData.IsSubstracted = ActualCase.IsSubstracted;
                }
                else                     //si es nuevo
                {
                    var last = db.Table <HearingFormat> ().Where(hf => hf.CaseDetention == idCase && hf.IsFinished == false).ToList();
                    if (last != null && last.Count > 0)
                    {
                        HearingFormatList(idCase, "No es posible agregar mas formatos, el caso tiene un formato de audiencia incompleto.");
                        return;
                    }
                    hearingFormatData                = newHearingFormatByCase(idCase);
                    hearingFormatData.isFinished     = false;
                    hearingFormatData.endTime        = null;
                    hearingFormatData.idFormat       = null;
                    hearingFormatData.confirmComment = null;
                    hearingFormatData.credPass       = null;
                }

                var pervF = db.Table <HearingFormat> ().Where(prev => prev.CaseDetention == idCase &&
                                                              prev.IsFinished == true).ToList();
                if (pervF != null && pervF.Count > 0)
                {
                    hearingFormatData.hasPrevHF = true;
                }
                else
                {
                    hearingFormatData.hasPrevHF = false;
                }

                view.IdCase = idCase;
                if (string.IsNullOrEmpty(hearingFormatData.listCrime))
                {
                    view.listCrime = "[]";
                }
                else
                {
                    view.listCrime = hearingFormatData.listCrime;
                }


                var catalogoCrimenes = db.Table <CrimeCatalog> ().Where(ccs => ccs.IsObsolete == false).ToList();
                var optCrimes        = new List <CatalogDto> ();
                foreach (CrimeCatalog cc in catalogoCrimenes)
                {
                    optCrimes.Add(new CatalogDto(cc.Id, cc.Name));
                }
                view.optionsCrime = JsonConvert.SerializeObject(optCrimes);
                var elections    = db.Table <Election> ().ToList();
                var optElections = new List <CatalogDto> ();
                foreach (Election el in elections)
                {
                    optElections.Add(new CatalogDto(el.Id, el.Name));
                }
                view.listElection = JsonConvert.SerializeObject(optElections);
                view.readonlyBand = false;

                var hearingtypes = db.Table <HearingType> ().Where(ht => ht.IsObsolete == false).OrderBy(ht => ht.Description).ToList();
                if (hearingtypes != null & hearingtypes.Count > 0)
                {
                    var tiposFormato = new List <SelectList> ();
                    foreach (HearingType tp in hearingtypes)
                    {
                        var tipo = new SelectList(tp.Id, tp.Description, tp.Lock, tp.Specification);
                        tiposFormato.Add(tipo);
                    }
                    view.lstHearingType = JsonConvert.SerializeObject(tiposFormato);
                }
                else
                {
                    view.lstHearingType = "[]";
                }

                var country   = db.Table <Country> ().Where(ctry => ctry.Alpha2 == Constants.ALPHA2_MEXICO).FirstOrDefault();
                var listState = db.Table <State> ().Where(st => st.CountryId == country.Id).OrderBy(st => st.Name).ToList();
                if (listState != null & listState.Count > 0)
                {
                    var stateDtoList = new List <StateDto> ();
                    foreach (State lst in listState)
                    {
                        var rowState = new StateDto(lst);
                        stateDtoList.Add(rowState);
                    }
                    view.listState = JsonConvert.SerializeObject(stateDtoList);
                }
                else
                {
                    view.listState = "[]";
                }

                if (hearingFormatData.idAddres != null && hearingFormatData.idAddres > 0)
                {
                    var direccion = db.Table <Address> ().Where(addr => addr.Id == hearingFormatData.idAddres).FirstOrDefault();
                    var adres     = db.Table <Location> ().Where(loc => loc.Id == direccion.LocationId).FirstOrDefault();
                    var parser    = new AddressDto(direccion);
                    parser.locationId = direccion.LocationId ?? 0;
                    parser.zipCode    = adres.ZipCode;
                    view.address      = JsonConvert.SerializeObject(parser);
                }
                hearingFormatData.canEdit    = false;
                hearingFormatData.canSave    = false;
                hearingFormatData.disableAll = true;
                view.model = JsonConvert.SerializeObject(hearingFormatData);
                var temp = new HearingFormatEdit {
                    Model = view
                };
                //			var temp = new NewMeeting{Model = new EntrevistaTabla{Name="nombre" , DateBirthString=DateTime.Today.ToString("yyyy/mm/dd")} };
                var pagestring = "nada que ver";
                pagestring = temp.GenerateString();
                webView.LoadHtmlString(pagestring);
                db.Close();
            }
        }
コード例 #5
0
        public HearingFormatView fillHearingFormaData(int idFormato)
        {
            var result = new HearingFormatView();

            using (var db = FactoryConn.GetConn()) {
                db.CreateTable <User> ();
                var  usrList  = db.Table <User> ().ToList();
                User reviewer = usrList.FirstOrDefault();
                int  revId    = 0;
                if (reviewer != null && reviewer.Id > 0)
                {
                    revId = reviewer.Id;
                }

                result.canSave    = true;
                result.canEdit    = true;
                result.disableAll = false;
                var formatosFuente = db.Table <HearingFormat> ().Where(hf => hf.Id == idFormato).FirstOrDefault();

                result.idFormat = formatosFuente.Id;
                result.idCase   = formatosFuente.CaseDetention;

                result.idFolder        = formatosFuente.IdFolder;
                result.idJudicial      = formatosFuente.IdJudicial;
                result.appointmentDate = formatosFuente.AppointmentDate ?? DateTime.Now;
                result.room            = formatosFuente.Room;
                result.initTime        = formatosFuente.InitTime ?? DateTime.Now;
                result.endTime         = formatosFuente.EndTime ?? DateTime.Now;
                result.judgeName       = formatosFuente.JudgeName;
                result.mpName          = formatosFuente.MpName;
                result.defenderName    = formatosFuente.DefenderName;
                result.isFinished      = formatosFuente.IsFinished;

                result.IsHomeless    = formatosFuente.IsHomeless;
                result.District      = formatosFuente.District;
                result.TimeAgo       = formatosFuente.TimeAgo;
                result.LocationPlace = formatosFuente.LocationPlace;



                db.CreateTable <HearingFormatImputed> ();
                var imputado = db.Table <HearingFormatImputed> ().Where(imp => imp.Id == formatosFuente.hearingImputed).FirstOrDefault();
                if (imputado != null && imputado.Id > 0)
                {
                    result.imputedName      = imputado.Name;
                    result.imputedFLastName = imputado.LastNameP;
                    result.imputedSLastName = imputado.LastNameM;
                    result.imputedBirthDate = imputado.BirthDate;
                    result.imputedTel       = imputado.ImputeTel;
                }

                result.umecaDate = formatosFuente.UmecaDate ?? DateTime.Now;
                result.umecaTime = formatosFuente.UmecaTime ?? DateTime.Now;

                result.userName = reviewer.fullname;

                if (formatosFuente.HearingType > 0)
                {
                    result.hearingTypeId            = formatosFuente.HearingType;
                    result.hearingTypeSpecification = formatosFuente.HearingTypeSpecification;
                }

                result.imputedPresence = formatosFuente.ImputedPresence;
                result.hearingResult   = formatosFuente.HearingResult;

                if (imputado != null && imputado.Id > 0)
                {
                    result.idAddres = imputado.Address;
                }

                var specs = db.Table <HearingFormatSpecs> ().Where(hfs => hfs.Id == formatosFuente.HearingFormatSpecs).FirstOrDefault();

                if (specs != null)
                {
                    result.controlDetention = specs.ControlDetention;
                    result.extension        = specs.Extension;
                    result.extDate          = specs.ExtDate ?? DateTime.Now;
                    result.impForm          = specs.ImputationFormulation;
                    result.imputationDate   = specs.ImputationDate ?? DateTime.Now;
                    result.vincProcess      = specs.LinkageProcess;
                    result.linkageRoom      = specs.LinkageRoom;
                    result.linkageDate      = specs.LinkageDate ?? DateTime.Now;
                    result.linkageTime      = specs.LinkageTime ?? DateTime.Now;
                }

                if (specs != null && specs.LinkageProcess > 0 &&
                    (specs.LinkageProcess == Constants.PROCESS_VINC_YES || specs.LinkageProcess == Constants.PROCESS_VINC_NO_REGISTER))
                {
                    result.arrangementType     = specs.ArrangementType;
                    result.nationalArrangement = specs.NationalArrangement;
                    result.terms = formatosFuente.Terms;
                }

                if (specs != null && specs.NationalArrangement != null && specs.ArrangementType > 0)
                {
                    List <ArrangementView> lstExistArrangement = getArrangmentLst(specs.NationalArrangement, specs.ArrangementType, idFormato);
                    result.lstArrangement = JsonConvert.SerializeObject(lstExistArrangement);
                }


                result.imputedPresence = formatosFuente.ImputedPresence;
                result.hearingResult   = formatosFuente.HearingResult;
                result.previousHearing = formatosFuente.PreviousHearing;
                result.comments        = formatosFuente.Comments;
                var contactos = db.Table <ContactData> ().Where(con => con.HearingFormat == formatosFuente.Id).ToList();
                if (contactos != null && contactos.Count > 0)
                {
                    result.lstContactData = JsonConvert.SerializeObject(contactos);
                }

                var crimes = db.Table <Crime> ().Where(crm => crm.HearingFormat == formatosFuente.Id).ToList();
                if (crimes != null && crimes.Count > 0)
                {
                    var crimeList = new List <CrimeDto> ();
                    foreach (Crime c in crimes)
                    {
                        var parsedCrime = new CrimeDto();
                        var crimen      = new CatalogDto();
                        crimen.id           = c.IdCrimeCat ?? 0;
                        crimen.name         = db.Table <CrimeCatalog> ().Where(cct => cct.Id == c.IdCrimeCat).FirstOrDefault().Name ?? "";
                        parsedCrime.crime   = crimen;
                        parsedCrime.comment = c.Comment;
                        CatalogDto aux     = new CatalogDto();
                        var        federal = db.Table <Election> ().Where(ele => ele.Id == c.Federal).FirstOrDefault();
                        aux.name            = federal.Name;
                        aux.id              = c.Federal ?? 0;
                        parsedCrime.federal = aux;
                        parsedCrime.article = c.Article;
                        crimeList.Add(parsedCrime);
                    }
                    result.listCrime = JsonConvert.SerializeObject(crimeList);
                }

                if (contactos != null && contactos.Count > 0)
                {
                    result.lstContactData = JsonConvert.SerializeObject(contactos);
                }

                db.Close();
                return(result);
            }
        }