コード例 #1
0
            public async Task <Unit> Handle(DeleteInspeccionCommand request, CancellationToken cancellationToken)
            {
                TInspeccion entityInspeccion = _context.TInspeccion.Find(request.CodInspeccion);

                if (entityInspeccion != null && entityInspeccion.Estado == false)
                {
                    throw new NotFoundException("Inspeccion", request.CodInspeccion);
                }
                else
                {
                    entityInspeccion.Estado = false;
                    _context.TInspeccion.Update(entityInspeccion);

                    await _context.SaveChangesAsync(cancellationToken);
                }
                return(Unit.Value);
            }
コード例 #2
0
            public async Task <Unit> Handle(CreateInspeccionCommand request, CancellationToken cancellationToken)
            {
                try
                {
                    if (request.Inspeccion == null)
                    {
                        throw new Exception("falta Inspeccion");
                    }
                    TInspeccion entity  = _mapper.Map <InspeccionDto, TInspeccion>(request.Inspeccion);
                    string      max_cod = nextCod();
                    entity.CodInspeccion = max_cod;
                    _context.TInspeccion.Add(entity);

                    if (request.Observaciones != null)
                    {
                        foreach (var _detalle in request.Observaciones)
                        {
                            TDetalleInspeccion newDetalle = new TDetalleInspeccion();
                            newDetalle.CodInspeccion   = max_cod;
                            newDetalle.CodTabla        = _detalle.CodTabla;
                            newDetalle.Lugar           = _detalle.Lugar;
                            newDetalle.CodUbicacion    = _detalle.CodUbicacion;
                            newDetalle.CodAspectoObs   = _detalle.CodAspectoObs;
                            newDetalle.CodActividadRel = _detalle.CodActividadRel;
                            newDetalle.Observacion     = _detalle.Observacion;
                            newDetalle.CodNivelRiesgo  = _detalle.CodNivelRiesgo;
                            _context.TDetalleInspeccion.Add(newDetalle);
                            var num1 = await _context.SaveChangesAsync(cancellationToken);

                            if (_detalle.PlanesAccion != null && _detalle.PlanesAccion.Count > 0)
                            {
                                // var num2 = await _planAccion.Create(_detalle.PlanesAccion, max_cod, newDetalle.Correlativo.ToString());
                                _detalle.PlanesAccion.ForEach(t => { t.docReferencia = max_cod; t.docSubReferencia = newDetalle.Correlativo.ToString(); });
                                var num2 = await _mediator.Send(new CreatePlanAccionCommand()
                                {
                                    planes = _detalle.PlanesAccion
                                });
                            }
                            if (request.Files != null)
                            {
                                foreach (var _file in request.Files)
                                {
                                    var decodeFileName = Base64Decode(_file.Name);
                                    var obj            = JsonConvert.DeserializeObject <CreateFileAtributesVCCDto>(decodeFileName);

                                    if (obj.CodDetalle == _detalle.Correlativo.ToString())
                                    {
                                        //var num3 = await _imagenes.UploadOneFile(_file, max_cod, newDetalle.Correlativo.ToString());
                                        var num3 = await _mediator.Send(new CreateOneFileCommand { File = _file, NroDocReferencia = max_cod, NroSubDocReferencia = newDetalle.Correlativo.ToString(), CodTablaRef = "TINSP" });
                                    }
                                }
                            }
                        }
                    }

                    if (request.Equipo != null)
                    {
                        var nuevo_equipo_List = _mapper.Map <IList <EquipoDto>, IList <TEquipoInspeccion> >(request.Equipo);
                        foreach (var persona in nuevo_equipo_List)
                        {
                            persona.CodInspeccion = max_cod;
                            //_context.TDetalleInspeccion.Add(detalle);
                        }
                        _context.TEquipoInspeccion.AddRange(nuevo_equipo_List);
                    }

                    if (request.Atendidos != null)
                    {
                        var nuevo_atendidos_List = _mapper.Map <IList <AtendidosDto>, IList <TPersonaAtendida> >(request.Atendidos);
                        foreach (var persona in nuevo_atendidos_List)
                        {
                            persona.CodInspeccion = max_cod;
                            //_context.TDetalleInspeccion.Add(detalle);
                        }
                        _context.TPersonaAtendida.AddRange(nuevo_atendidos_List);
                    }

                    if (request.AnalisisCausa != null)
                    {
                        var nuevo_analisis_List = _mapper.Map <IList <InspeccionAnalisisCausaDto>, IList <TInspeccionAnalisisCausa> >(request.AnalisisCausa);
                        foreach (var analisis in nuevo_analisis_List)
                        {
                            analisis.CodInspeccion = max_cod;
                            //_context.TDetalleInspeccion.Add(detalle);
                        }
                        _context.TInspeccionAnalisisCausa.AddRange(nuevo_analisis_List);
                    }

                    var num4 = await _context.SaveChangesAsync(cancellationToken);

                    return(Unit.Value);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
コード例 #3
0
            public async Task <GetInspeccionVM> Handle(GetInspeccionQuery request, CancellationToken cancellationToken)
            {
                GetInspeccionVM VM = new GetInspeccionVM();

                TInspeccion inspeccion = _context.TInspeccion.Find(request.CodInspeccion);

                if (inspeccion != null && inspeccion.Estado == false)
                {
                    throw new NotFoundException("Inspeccion", request.CodInspeccion);
                }

                VM.Inspeccion        = _mapper.Map <TInspeccion, InspeccionDto>(inspeccion);
                VM.DetalleInspeccion = _context.TDetalleInspeccion
                                       .Where(t => t.Estado == true && t.CodInspeccion.Equals(request.CodInspeccion))
                                       .ProjectTo <DetalleInspeccionDto>(_mapper.ConfigurationProvider)
                                       .ToList();
                foreach (var detalle in VM.DetalleInspeccion)
                {
                    if (!string.IsNullOrEmpty(detalle.CodUbicacion))
                    {
                        //detalle.DesUbicacion = await _general.GetUbicaciones(detalle.CodUbicacion);
                        detalle.DesUbicacion = await _mediator.Send(new Code2NameUbicacionQuery()
                        {
                            codigo = detalle.CodUbicacion
                        });
                    }
                }

                VM.EquipoInspeccion = _context.TEquipoInspeccion
                                      .Where(t => t.Estado == true && t.CodInspeccion.Equals(request.CodInspeccion))
                                      .ProjectTo <EquipoDto>(_mapper.ConfigurationProvider)
                                      .ToList();
                foreach (var persona in VM.EquipoInspeccion)
                {
                    //var nombreYapellidos = await _general.GetPersonas(persona.CodPersona);
                    var nombreYapellidos = await _mediator.Send(new GetCode2NameOneQuery()
                    {
                        code = persona.CodPersona
                    });

                    if (nombreYapellidos != null)
                    {
                        persona.Nombres = nombreYapellidos;
                    }
                }
                VM.PersonasAtendidas = _context.TPersonaAtendida
                                       .Where(t => t.Estado == true && t.CodInspeccion.Equals(request.CodInspeccion))
                                       .ProjectTo <AtendidosDto>(_mapper.ConfigurationProvider)
                                       .ToList();
                foreach (var personasAtendida in VM.PersonasAtendidas)
                {
                    //var nombreYapellidos = await _general.GetPersonas(personasAtendida.CodPersona);
                    var nombreYapellidos = await _mediator.Send(new GetCode2NameOneQuery()
                    {
                        code = personasAtendida.CodPersona
                    });

                    if (nombreYapellidos != null)
                    {
                        personasAtendida.Nombres = nombreYapellidos;
                    }
                }
                VM.AnalisisCausa = _context.TInspeccionAnalisisCausa
                                   .Where(t => t.Estado == true && t.CodInspeccion.Equals(request.CodInspeccion))
                                   .ProjectTo <InspeccionAnalisisCausaDto>(_mapper.ConfigurationProvider)
                                   .ToList();

                return(VM);
            }