Exemple #1
0
        public SecureFileModel UploadFileToDB(SecureFileModel model)
        {
            var p_FileName         = new Parameter("@FileName", model.FileName);
            var p_FileExtension    = new Parameter("@FileExtension", model.FileExtension);
            var p_FileDocumentType = new Parameter("@FileDocumentType", model.FileDocType);
            var p_FilePath         = new Parameter("@FilePath", model.FileFullPath);
            var p_ActualFileName   = new Parameter("@ActualFileName", model.ActualFileName);
            var p_TenantID         = new Parameter("@TenantID", model.TenantID);
            var p_CreatedBy        = new Parameter("@CreatedBy", model.CreatedBy);
            var p_CreatedByEntity  = new Parameter("@CreatedByEntity", model.CreatedByEntity);

            Parameter p_IsError  = new Parameter("@IsError", DBNull.Value, ParameterDirection.Output, DbType.Int16, 1);
            Parameter p_ErrorMsg = new Parameter("@ErrorMsg", DBNull.Value, ParameterDirection.Output, DbType.String, 16);

            var r = dataBaseService.ExecuteScalar(StoredProcedures.InsertUpdateDeleteSecureFile
                                                  , DBCommandType.Procedure
                                                  , p_FileName
                                                  , p_FileExtension
                                                  , p_FileDocumentType
                                                  , p_FilePath
                                                  , p_ActualFileName
                                                  , p_TenantID
                                                  , p_CreatedBy
                                                  , p_CreatedByEntity
                                                  , p_IsError
                                                  , p_ErrorMsg
                                                  );

            return(PrepareReturnModel(Convert.ToInt32(r), Convert.ToString(""), model));
        }
Exemple #2
0
 public SecureFileViewModel Map(SecureFileModel secureModel)
 {
     return(new SecureFileViewModel
     {
         ActualFileName = secureModel.ActualFileName,
         CreatedBy = secureModel.CreatedBy,
         Id = secureModel.Id
     });
 }
Exemple #3
0
        public SecureFileModel GetSecureFileDetails(SecureFileModel model)
        {
            var       fileParam  = new Parameter("@Id", model.Id);
            Parameter p_IsError  = new Parameter("@IsError", DBNull.Value, ParameterDirection.Output, DbType.Int16, 1);
            Parameter p_ErrorMsg = new Parameter("@ErrorMsg", DBNull.Value, ParameterDirection.Output, DbType.String, 16);

            var dataSet = dataBaseService.GetDataSet(StoredProcedures.GetSecureFileDetail, DBCommandType.Procedure, fileParam);

            return(dataSet.Tables[0].Rows.Cast <DataRow>().Select(r => Map(r)).FirstOrDefault());
        }
Exemple #4
0
        public SecureFileModel UploadToFileSystem(SecureFileModel fileModel, int userId, System.IO.Stream stream)
        {
            fileModel.FileFullPath  = this.fileSystem.GetFolderPath(fileModel);
            fileModel.FileName      = this.fileSystem.GetGeneratedFileName(fileModel, userId);
            fileModel.ContentStream = stream;

            fileSystem.Write(fileModel);

            return(fileModel);
        }
        public HttpResponseMessage GetSecureFileDetails(RequestCarrier requestCarrier) //currently return void need to change afterwards
        {
            if (requestCarrier != null && requestCarrier.TanentId != 0 && requestCarrier.From != string.Empty)
            {
                if (requestCarrier.PayLoad != null)
                {
                    var secureModel = this._secureMapper.Map(WebCommon.Instance.GetObject <SecureFileViewModel>(requestCarrier.PayLoad));
                    secureModel.CreatedBy       = (int)requestCarrier.UserId.Value;
                    secureModel.CreatedByEntity = Convert.ToInt32(requestCarrier.From);
                    secureModel.TenantID        = requestCarrier.TanentId;
                    string hasAccess = this._dataServices.SecureFileService.CheckSecureFileAccess(secureModel.Id, secureModel.CreatedBy, secureModel.CreatedByEntity);
                    if (string.IsNullOrEmpty(hasAccess))
                    {
                        if (secureModel.Id > 0)
                        {
                            SecureFileModel fileModel = new SecureFileModel()
                            {
                                Id = secureModel.Id
                            };
                            fileModel = this._dataServices.SecureFileService.GetSecureFileDetails(fileModel);
                            byte[] filedata = new byte[1]; string contentType = "";
                            if (fileModel != null)
                            {
                                filedata    = this._dataServices.SecureFileService.DownloadFile(fileModel);
                                contentType = MimeMapping.GetMimeMapping(fileModel.FileFullPath + fileModel.FileName);

                                HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
                                var stream = new MemoryStream(filedata);
                                result.Content = new StreamContent(stream);
                                result.Content.Headers.ContentType        = new MediaTypeHeaderValue(contentType);
                                result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                                {
                                    FileName = fileModel.FileName,
                                };
                                return(result);
                            }
                        }
                    }
                    else
                    {
                        return(new HttpResponseMessage(HttpStatusCode.Unauthorized));
                    }
                }
                else
                {
                    return(new HttpResponseMessage(HttpStatusCode.BadRequest));
                }
            }
            else
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }
            return(new HttpResponseMessage(HttpStatusCode.Unauthorized));
        }
Exemple #6
0
        public SecureFileModel DeleteFile(SecureFileModel model)
        {
            var fileParam = new Parameter("@FileID", model.Id);
            var p_OpnFlag = new Parameter("@OpnFlag", 3);

            Parameter p_IsError  = new Parameter("@IsError", DBNull.Value, ParameterDirection.Output, DbType.Int16, 1);
            Parameter p_ErrorMsg = new Parameter("@ErrorMsg", DBNull.Value, ParameterDirection.Output, DbType.String, 16);

            var r = dataBaseService.ExecuteScalar(StoredProcedures.InsertUpdateDeleteSecureFile, DBCommandType.Procedure, fileParam);

            return(PrepareReturnModel(Convert.ToInt32(r), Convert.ToString(p_ErrorMsg), model));
        }
Exemple #7
0
        private SecureFileModel PrepareReturnModel(int fileId, string p_ErrorMsg, SecureFileModel model)
        {
            int retValue = fileId;

            if (retValue < (int)StoreProcStatusEnum.Success)
            {
                model.Success      = false;
                model.ErrorMessage = p_ErrorMsg;
            }
            else
            {
                model.Success = true;
                model.Id      = retValue;
            }
            return(model);
        }
        public IHttpActionResult SecureUpload()
        {
            ResponseCarrier response;
            string          fileIds     = string.Empty;
            bool            finalsucc   = true;
            var             httpRequest = HttpContext.Current.Request;
            SecureFileModel fileModel;

            if (httpRequest.Files.Count > 0)
            {
                foreach (string f in httpRequest.Files)
                {
                    var postedFile = httpRequest.Files[f];
                    fileModel = new SecureFileModel();
                    fileModel.ActualFileName = System.IO.Path.GetFileNameWithoutExtension(postedFile.FileName);
                    fileModel.FileDocType    = "secure";
                    fileModel.FileExtension  = System.IO.Path.GetExtension(postedFile.FileName);

                    fileModel           = this._dataServices.SecureFileService.UploadToFileSystem(fileModel, -1, postedFile.InputStream);
                    fileModel.IsDeleted = false;


                    fileModel = this._dataServices.SecureFileService.UploadFileToDB(fileModel);
                    if (fileModel.Success)
                    {
                        fileIds += fileModel.Id + "|";
                    }
                    else
                    {
                        finalsucc = false;
                        fileIds   = fileModel.ErrorMessage;
                    }
                }
                if (finalsucc)
                {
                    response = new ResponseCarrier()
                    {
                        PayLoad      = fileIds.Remove(fileIds.Length - 1, 1),
                        Status       = true,
                        ErrorMessage = string.Empty
                    };
                }
                else
                {
                    response = new ResponseCarrier()
                    {
                        PayLoad      = null,
                        Status       = false,
                        ErrorMessage = string.Empty
                    };
                }
            }
            else
            {
                response = new ResponseCarrier()
                {
                    Status = false, PayLoad = null, ErrorMessage = "No files provided."
                };
            }

            return(Json(response));
        }
Exemple #9
0
 public byte[] DownloadFile(SecureFileModel fileModel)
 {
     return(this.fileSystem.Read(fileModel).Contents);
 }