public IHttpActionResult Delete(Guid id)
        {
            try
            {
                var userID = _genericHelper.GetUserID();

                if (userID != null)
                {
                    FileMetaData fileMeta = new FileMetaData();
                    fileMeta.UserID = userID;
                    fileMeta.ID     = id;

                    var socketID = _genericHelper.GetCurrentSocketID();
                    QueueFileMetaDataModel queueItem = new QueueFileMetaDataModel(fileMeta, socketID);

                    _messageQueueHelper.PushMessage <QueueFileMetaDataModel>(_applicationConfig, queueItem, _applicationConfig.FileMetaDeleteQueue);
                    return(Ok());
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"File/Delete/id {id.ToString()} failed", ex);
                return(InternalServerError());
            }

            return(NotFound());
        }
        public void FileOpened(QueueFileMetaDataModel queueMessage)
        {
            var fileDB = _fileDataModel.Get(queueMessage.FileMeta.ID);

            if (fileDB.UserID == queueMessage.FileMeta.UserID)
            {
                fileDB.ViewCount += 1;
                _fileDataModel.Update(fileDB);
                var fileMeta = queueMessage.FileMeta;
                _fileUploadHub.UpdateFileRow(queueMessage.SocketID, new FileViewModel(fileDB.ID, fileDB.UserID, fileDB.Filename, fileDB.FileExtension, fileDB.BlobUrl, fileDB.ViewCount, fileDB.FileSize));
            }
        }
        public void FileDelete(QueueFileMetaDataModel queueMessage)
        {
            var fileDB = _fileDataModel.Get(queueMessage.FileMeta.ID);

            if (fileDB.UserID == queueMessage.FileMeta.UserID)
            {
                var deltetedFromBlob = _fileUploadHelper.DeleteFile(_applicationConfig, Convert.ToString(queueMessage.FileMeta.ID));
                var fileExists       = _fileUploadHelper.Exists(_applicationConfig, Convert.ToString(queueMessage.FileMeta.ID));

                if (fileExists == false || deltetedFromBlob)
                {
                    _fileDataModel.Delete(queueMessage.FileMeta.ID);
                    _fileUploadHub.RemoveFileFromList(queueMessage.SocketID, Convert.ToString(queueMessage.FileMeta.ID));
                }
            }
        }
 public void FilePushed(QueueFileMetaDataModel queueMessage)
 {
     _fileUploadHub.VerifyUpload(queueMessage.SocketID, queueMessage.MappingID, queueMessage.FileMeta.Filename);
     _fileDataModel.Insert(queueMessage.FileMeta);
 }
        public IHttpActionResult Post()
        {
            try
            {
                List <FileViewModel> pushedfiles = new List <FileViewModel>();
                List <FileViewModel> failedfiles = new List <FileViewModel>();

                var userID = _genericHelper.GetUserID();

                if (userID != null)
                {
                    var files = _genericHelper.GetFilesFromHttpMessage();

                    if (files != null && files.Count > 0)
                    {
                        foreach (var fileContent in files)
                        {
                            var fileID = Guid.NewGuid();

                            if (fileContent != null && fileContent.ContentLength > 0)
                            {
                                var extension   = Path.GetExtension(fileContent.FileName);
                                var isFileValid = _genericHelper.IsFileAccepted(_applicationConfig, extension);

                                if (isFileValid == false)
                                {
                                    //do logic to report failed uploads //log for info purposes
                                    continue;
                                }

                                var stream = fileContent.InputStream;
                                var url    = _fileUploadHelper.UploadFile(_applicationConfig, stream, fileID.ToString() + extension);

                                if (url != null)
                                {
                                    FileMetaData fileMeta = new FileMetaData();
                                    fileMeta.UserID   = userID;
                                    fileMeta.ID       = fileID;
                                    fileMeta.BlobUrl  = url;
                                    fileMeta.FileSize = fileContent.ContentLength;
                                    fileMeta.Filename = fileContent.FileName;

                                    var socketID = _genericHelper.GetCurrentSocketID();

                                    QueueFileMetaDataModel queueItem = new QueueFileMetaDataModel(fileMeta, socketID);
                                    queueItem.MappingID = fileContent.FileKey;
                                    _messageQueueHelper.PushMessage <QueueFileMetaDataModel>(_applicationConfig, queueItem, _applicationConfig.FileDataCreateQueue);

                                    pushedfiles.Add(new FileViewModel(fileMeta.ID, fileMeta.UserID, fileMeta.Filename, fileMeta.FileExtension, fileMeta.BlobUrl, fileMeta.ViewCount, fileMeta.FileSize));
                                }
                            }
                        }
                    }

                    return(Ok(pushedfiles));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"File/Post failed", ex);
                return(InternalServerError());
            }

            return(BadRequest());
        }