public int ActualizarOrdenProcesoPlanta(RegistrarActualizarOrdenProcesoPlantaRequestDTO request, IFormFile file)
        {
            OrdenProcesoPlanta ordenProcesoPlanta = _Mapper.Map <OrdenProcesoPlanta>(request);

            var AdjuntoBl = new AdjuntarArchivosBL(_fileServerSettings);

            byte[] fileBytes = null;
            if (file != null)
            {
                if (file.Length > 0)
                {
                    using (var ms = new MemoryStream())
                    {
                        file.CopyTo(ms);
                        fileBytes = ms.ToArray();
                        string s = Convert.ToBase64String(fileBytes);
                    }

                    ordenProcesoPlanta.NombreArchivo = file.FileName;
                    ResponseAdjuntarArchivoDTO response = AdjuntoBl.AgregarArchivo(new RequestAdjuntarArchivosDTO()
                    {
                        filtros = new AdjuntarArchivosDTO()
                        {
                            archivoStream = fileBytes,
                            filename      = file.FileName,
                        },
                        pathFile = _fileServerSettings.Value.OrdenProcesoPlanta
                    });

                    ordenProcesoPlanta.PathArchivo = _fileServerSettings.Value.OrdenProcesoPlanta + "\\" + response.ficheroReal;
                }
            }

            ordenProcesoPlanta.FechaUltimaActualizacion   = DateTime.Now;
            ordenProcesoPlanta.UsuarioUltimaActualizacion = request.Usuario;
            int affected = _IOrdenProcesoPlantaRepository.Actualizar(ordenProcesoPlanta);

            _IOrdenProcesoPlantaRepository.EliminarProcesoPlantaDetalle(ordenProcesoPlanta.OrdenProcesoPlantaId);


            foreach (OrdenProcesoPlantaDetalle detalle in request.OrdenProcesoPlantaDetalle)
            {
                detalle.OrdenProcesoPlantaId = request.OrdenProcesoPlantaId;

                _IOrdenProcesoPlantaRepository.InsertarProcesoPlantaDetalle(detalle);
            }


            return(affected);
        }
        public int RegistrarOrdenProcesoPlanta(RegistrarActualizarOrdenProcesoPlantaRequestDTO request, IFormFile file)
        {
            OrdenProcesoPlanta OrdenProcesoPlanta = _Mapper.Map <OrdenProcesoPlanta>(request);

            OrdenProcesoPlanta.FechaRegistro   = DateTime.Now;
            OrdenProcesoPlanta.UsuarioRegistro = request.Usuario;
            OrdenProcesoPlanta.Numero          = _ICorrelativoRepository.Obtener(request.EmpresaId, Documentos.OrdenProcesoPlanta);

            var AdjuntoBl = new AdjuntarArchivosBL(_fileServerSettings);

            byte[] fileBytes = null;

            if (file != null)
            {
                if (file.Length > 0)
                {
                    using (var ms = new MemoryStream())
                    {
                        file.CopyTo(ms);
                        fileBytes = ms.ToArray();
                        string s = Convert.ToBase64String(fileBytes);
                    }

                    OrdenProcesoPlanta.NombreArchivo = file.FileName;
                    //Adjuntos
                    ResponseAdjuntarArchivoDTO response = AdjuntoBl.AgregarArchivo(new RequestAdjuntarArchivosDTO()
                    {
                        filtros = new AdjuntarArchivosDTO()
                        {
                            archivoStream = fileBytes,
                            filename      = file.FileName,
                        },
                        pathFile = _fileServerSettings.Value.OrdenProcesoPlanta
                    });
                    OrdenProcesoPlanta.PathArchivo = _fileServerSettings.Value.OrdenProcesoPlanta + "\\" + response.ficheroReal;
                }
            }

            int OrdenProcesoPlantaId = _IOrdenProcesoPlantaRepository.Insertar(OrdenProcesoPlanta);

            foreach (OrdenProcesoPlantaDetalle detalle in request.OrdenProcesoPlantaDetalle)
            {
                detalle.OrdenProcesoPlantaId = OrdenProcesoPlantaId;
                _IOrdenProcesoPlantaRepository.InsertarProcesoPlantaDetalle(detalle);
            }
            return(OrdenProcesoPlantaId);
        }