Exemple #1
0
        public SendFileResponse SendFile(SendFileRequest request)
        {
            var userAuthentication = userAuthenticationRepository.GetById(request.AuthKey);

            if (userAuthentication is null || userAuthentication.ExpireAt < DateTime.Now)
            {
                return(new SendFileResponse
                {
                    Code = "-1",
                    Completed = false,
                    Message = "Not Authenticated"
                });
            }
            var user    = userRepository.GetById(userAuthentication.UserId);
            var company = companyAccountRepository.GetFirstOrDefault(x => x.Identifier == request.ReceiverIdentifier);

            if (company is null)
            {
                return(new SendFileResponse
                {
                    Code = "-1",
                    Completed = false,
                    Message = "Receiver Company Not Found!"
                });
            }

            var fileBytes = Convert.FromBase64String(request.FileBase64Content);
            var outFile   = new OutFileDocumentModel
            {
                FileName   = request.DocumentName,
                InsertTime = DateTime.Now,
                FileSize   = fileBytes.Length
            };

            outFileDocumentRepository.Create(outFile, fileBytes);
            outFileRepository.Create(new Library.MsSqlDataAccess.Entity.OutFile
            {
                CompanyId          = user.CompanyId,
                DocumentName       = request.DocumentName,
                InsertAt           = DateTime.Now,
                OutFileId          = outFile.Id.ToString(),
                ReceiverIdentifier = request.ReceiverIdentifier,
                State = (int)FileState.Received
            });
            bus.Publish <IFileReceived>(new
            {
                CompanyId = user.CompanyId,
                FileID    = outFile.Id.ToString()
            });


            return(new SendFileResponse
            {
                Completed = true,
                Code = "1",
                Message = "File Received"
            });
        }