public void Update(UploadedFileDTO uploadedFileDTO)
        {
            var file = _mapper.Map <UploadedFileDTO, UploadedFiles>(uploadedFileDTO);

            Database.UploadedFiles.Update(file);
            Database.Save();
        }
예제 #2
0
        public JsonResult Upload(Guid id)
        {
            if (Request.Files.Count == 1)
            {
                try
                {
                    foreach (string fileName in Request.Files)
                    {
                        HttpPostedFileBase hpf = Request.Files[fileName];

                        var file = new UploadedFileDTO
                        {
                            fileId      = id,
                            fileName    = fileName,
                            contentType = hpf.ContentType,
                            content     = hpf.InputStream.ReadToEnd(),
                            dateCreated = DateTime.Now,
                        };

                        FileModel.SaveWeborbFile(file);

                        // TRICK: we support single file
                        break;
                    }

                    return(Json(OperationResult.Success()));
                }
                catch (Exception ex)
                {
                    _logger.Error("[File.Upload] failed", ex);
                    return(Json(OperationResult.Error("Error occured")));
                }
            }
            return(Json(OperationResult.Error("Error occured. Not File uploaded.")));
        }
예제 #3
0
        /// <summary>
        /// The save WEBORB file.
        /// </summary>
        /// <param name="file">
        /// The file.
        /// </param>
        public void SaveWeborbFile(UploadedFileDTO file)
        {
            var workingDir = this.WebOrbFolderName(file.fileId);

            if (!Directory.Exists(workingDir))
            {
                Directory.CreateDirectory(workingDir);
            }

            System.IO.File.WriteAllBytes(Path.Combine(workingDir, file.fileName), file.content);
        }
예제 #4
0
        /// <summary>
        /// The file start.
        /// </summary>
        /// <param name="stream">
        /// The stream.
        /// </param>
        /// <returns>
        /// The <see cref="ServiceResponse"/>.
        /// </returns>
        public FilesUploadedResultDTO uploadMultipart(string fileId, Stream stream)
        {
            try
            {
                var request        = this.CurrentRequest;
                var requestHeaders = request.Headers;

                Guid fileIdVal;
                if (string.IsNullOrWhiteSpace(fileId) || !Guid.TryParse(fileId, out fileIdVal))
                {
                    throw new ApplicationException("fileId is not passed or not a GUID");
                }

                string contentType   = requestHeaders["Content-Type"];
                int    boundaryIndex = contentType.With(x => x.IndexOf("boundary=", StringComparison.Ordinal));
                var    streamedFiles = new HttpMultipart(
                    stream,
                    boundaryIndex > 0 ? contentType.Substring(boundaryIndex + 9).Trim() : null);
                var createdFiles  = new List <Guid>();
                var notSavedFiles = new Dictionary <string, string>();
                foreach (var httpMultipartBoundary in streamedFiles.GetBoundaries())
                {
                    var fileName = string.IsNullOrWhiteSpace(httpMultipartBoundary.Filename)
                                       ? httpMultipartBoundary.Name
                                       : httpMultipartBoundary.Filename;
                    if (fileName.Equals("FileName", StringComparison.InvariantCultureIgnoreCase) ||
                        fileName.Equals("Upload", StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    var file = new UploadedFileDTO
                    {
                        fileId      = fileIdVal,
                        fileName    = fileName,
                        contentType = httpMultipartBoundary.ContentType,
                        content     = httpMultipartBoundary.Value.ReadFully(),
                        dateCreated = DateTime.Now,
                    };

                    this.FileModel.SaveWeborbFile(file);
                    createdFiles.Add(fileIdVal);
                }

                return(this.FormatSuccessfulResponse(createdFiles, notSavedFiles));
            }
            catch (Exception ex)
            {
                var error = new Error(Errors.CODE_ERRORTYPE_GENERIC_ERROR, "File upload unhandled exception", ex.ToString());
                IoC.Resolve <ILogger>().Error("File upload unhandled exception", ex);
                throw new FaultException <Error>(error, error.errorMessage);
            }
        }
        public bool AddUploadedFile(UploadedFileDTO uploadedFile)
        {
            operational.UploadedFiles.Add(new UploadedFile
            {
                FileOriginalName        = uploadedFile.FileOriginalName,
                FileInsertedRowsCount   = uploadedFile.FileInsertedRowsCount,
                FileCorruptedRowsCount  = uploadedFile.FileCorruptedRowsCount,
                FileDuplicatedRowsCount = uploadedFile.FileDuplicatedRowsCount,
                FileUploadedBy          = uploadedFile.FileUploadedById,
                FileSourceType          = (int)uploadedFile.FileSourceType,
                FileUploadTime          = uploadedFile.FileUploadTime
            });

            return(operational.SaveChanges() > 0);
        }
        public bool InsertAccidentFileDetails(UploadedFileDTO fileDetails)
        {
            if (fileDetails == null)
            {
                return(false);
            }

            var uploadedFile = new UploadedFile
            {
                FileOriginalName        = fileDetails.FileOriginalName,
                FileUploadedBy          = fileDetails.FileUploadedById,
                FileUploadTime          = fileDetails.FileUploadTime,
                FileSourceType          = (int)fileDetails.FileSourceType,
                FileInsertedRowsCount   = fileDetails.FileInsertedRowsCount,
                FileDuplicatedRowsCount = fileDetails.FileDuplicatedRowsCount,
                FileCorruptedRowsCount  = fileDetails.FileCorruptedRowsCount
            };

            operational.UploadedFiles.Add(uploadedFile);

            return(operational.SaveChanges() > 0);
        }
예제 #7
0
        public IHttpActionResult SubirArchivoInterface([FromBody] UploadedFileDTO file)
        {
            List <HistoricoKilometrajeDTO> listaResultado         = new List <HistoricoKilometrajeDTO>();
            DataResult <List <HistoricoKilometrajeDTO> > response = null;

            ClaimsIdentity claimsIdentity = User.Identity as ClaimsIdentity;
            Claim          claim          = claimsIdentity.FindFirst(ClaimTypes.Email);

            string emailUsuario = claim == null ? "" : claim.Value;

            try
            {
                listaResultado = repository.ImportarDatosInterface(file, emailUsuario);
                response       = DataResultHelper.Done(listaResultado);
            }
            catch (Exception exception)
            {
                response = DataResultHelper.Fail <List <HistoricoKilometrajeDTO> >(exception);
            }

            return(Ok(response));
        }
예제 #8
0
 public bool AddUploadedFile(UploadedFileDTO uploadedFile)
 {
     return(new AccidentStandardDAL().AddUploadedFile(uploadedFile));
 }
        public List <HistoricoKilometrajeDTO> ImportarDatosInterface(UploadedFileDTO file, string usuario)
        {
            List <HistoricoKilometrajeDTO> listaResultado = new List <HistoricoKilometrajeDTO>();
            List <T_Ihmn>     datosAgregar = new List <T_Ihmn>();
            DB_MAPRI_Entities context      = null;

            int      columnasDetectadas   = 0;
            int      filaInicio           = 0;
            DateTime?fechaCreacionArchivo = null;
            bool     esFilaFecha          = false;

            try
            {
                XLWorkbook archivoXLSX = GetWoorkbook(file.Data);

                IXLRows nonEmptyDataRows = archivoXLSX.Worksheet("Report").RowsUsed();

                foreach (IXLRow dataRow in nonEmptyDataRows)
                {
                    if (columnasDetectadas == listaColumnasGuardar.Count)
                    {
                        break;
                    }

                    IXLCells cellsUsed = dataRow.CellsUsed();

                    foreach (IXLCell cellItem in cellsUsed)
                    {
                        if (columnasDetectadas == listaColumnasGuardar.Count)
                        {
                            break;
                        }

                        string valorCelda = cellItem.GetValue <string>().Trim();

                        if (valorCelda == "Created")
                        {
                            esFilaFecha = true;
                            continue;
                        }
                        if (esFilaFecha && fechaCreacionArchivo == null)
                        {
                            double baseDate = cellItem.GetValue <double>();
                            fechaCreacionArchivo = DateTime.FromOADate(baseDate);
                        }

                        int    rowNumber    = cellItem.Address.RowNumber;
                        int    columnNumber = cellItem.Address.ColumnNumber;
                        string value        = cellItem.Value.ToString().Trim();

                        if (listaColumnasGuardar.ContainsKey(value))
                        {
                            if (listaColumnasGuardar[value] == 0)
                            {
                                listaColumnasGuardar[value] = columnNumber;
                                if (filaInicio == 0)
                                {
                                    filaInicio = rowNumber + 1;
                                }
                                columnasDetectadas++;
                            }
                        }
                    }
                }

                var dataRows = archivoXLSX.Worksheet("Report").RowsUsed().Where(r => r.RowNumber() >= filaInicio);

                Parallel.ForEach(dataRows, new ParallelOptions {
                    MaxDegreeOfParallelism = 10
                }, e => AgregarHistoricoKilometrajeDTO(e, fechaCreacionArchivo, ref listaResultado));

                datosAgregar.AddRange(
                    listaResultado.AsParallel().Select(
                        e => new T_Ihmn()
                {
                    VIN          = e.VIN,
                    Fecha        = e.Fecha,
                    Kilometros   = e.Kilometros,
                    Horas        = e.Horas,
                    Minutos      = e.Minutos,
                    CreationUser = usuario,
                    Accion       = "Alta",
                    CreationDate = DateTime.Now
                })
                    );

                context = new DB_MAPRI_Entities();

                context.T_Ihmn.AddRange(datosAgregar);
                int saved = context.SaveChanges();

                listaResultado.Clear();

                listaResultado.AddRange(
                    datosAgregar.AsParallel().Select(
                        e => new HistoricoKilometrajeDTO()
                {
                    Id         = e.Id,
                    VIN        = e.VIN,
                    Fecha      = e.Fecha,
                    Kilometros = e.Kilometros,
                    Horas      = e.Horas,
                    Minutos    = e.Minutos
                })
                    );
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                context?.Dispose();
            }


            return(listaResultado);
        }